-
Notifications
You must be signed in to change notification settings - Fork 33
/
org_test.go
71 lines (58 loc) · 1.78 KB
/
org_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package mackerel
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetOrg(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/api/v0/org" {
t.Error("request URL should be /api/v0/org but: ", req.URL.Path)
}
if req.Method != "GET" {
t.Error("request method should be GET but: ", req.Method)
}
respJSON, _ := json.Marshal(&Org{Name: "hoge"})
res.Header()["Content-Type"] = []string{"application/json"}
fmt.Fprint(res, string(respJSON))
}))
defer ts.Close()
client, _ := NewClientWithOptions("dummy-key", ts.URL, false)
org, err := client.GetOrg()
if err != nil {
t.Error("err should be nil but: ", err)
}
if org.Name != "hoge" {
t.Error("request sends json including Name but: ", org)
}
if org.DisplayName != "" {
t.Error("request sends json not including DisplayName but: ", org)
}
}
func TestGetOrgWithDisplayName(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/api/v0/org" {
t.Error("request URL should be /api/v0/org but: ", req.URL.Path)
}
if req.Method != "GET" {
t.Error("request method should be GET but: ", req.Method)
}
respJSON, _ := json.Marshal(&Org{Name: "hoge", DisplayName: "fuga"})
res.Header()["Content-Type"] = []string{"application/json"}
fmt.Fprint(res, string(respJSON))
}))
defer ts.Close()
client, _ := NewClientWithOptions("dummy-key", ts.URL, false)
org, err := client.GetOrg()
if err != nil {
t.Error("err should be nil but: ", err)
}
if org.Name != "hoge" {
t.Error("request sends json including Name but: ", org)
}
if org.DisplayName != "fuga" {
t.Error("request sends json including DisplayName but: ", org)
}
}