diff --git a/org.go b/org.go index 0d2aa78..b31b399 100644 --- a/org.go +++ b/org.go @@ -3,7 +3,7 @@ package mackerel // Org information type Org struct { Name string `json:"name"` - DisplayName string `json:"displayName"` + DisplayName string `json:"displayName,omitempty"` } // GetOrg gets the org. diff --git a/org_test.go b/org_test.go index ab32cba..10f6ccd 100644 --- a/org_test.go +++ b/org_test.go @@ -9,6 +9,37 @@ import ( ) 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)