-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapi_test.go
47 lines (44 loc) · 1.25 KB
/
api_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package p2pubapi
import (
"encoding/json"
"io/ioutil"
"net/url"
"os"
"path"
"testing"
)
func testCall(t *testing.T) {
t.Log("call test")
api := NewAPI(os.Getenv("IIJAPI_ACCESS_KEY"), os.Getenv("IIJAPI_SECRET_KEY"))
u, err := url.Parse(EndpointJSON)
u.Path = path.Join(u.Path, "/r/"+APIVersion20151130+"/gises/"+os.Getenv("GISSERVICECODE")+".json")
t.Log("u", u, u.RawPath, "err", err)
resp, err := api.Get(*u)
t.Log("resp", resp, "err", err)
t.Log("resp header", resp.Header)
b, err := ioutil.ReadAll(resp.Body)
t.Log("read err", err)
t.Log("resp body", string(b))
var maps map[string]interface{}
json.Unmarshal(b, &maps)
t.Log("decoded", maps)
}
func testCall2(t *testing.T) {
t.Log("call test")
api := NewAPI(os.Getenv("IIJAPI_ACCESS_KEY"), os.Getenv("IIJAPI_SECRET_KEY"))
u, err := url.Parse(EndpointJSON)
u.Path = path.Join(u.Path, "/r/"+APIVersion20151130+"/gises.json")
q := u.Query()
q.Set("Item", "ServiceCode")
u.RawQuery = q.Encode()
t.Log("u", u, u.RawPath, "err", err)
resp, err := api.Get(*u)
t.Log("resp", resp, "err", err)
t.Log("resp header", resp.Header)
b, err := ioutil.ReadAll(resp.Body)
t.Log("read err", err)
t.Log("resp body", string(b))
var maps map[string]interface{}
json.Unmarshal(b, &maps)
t.Log("decoded", maps)
}