diff --git a/org.go b/org.go index 0f58fe6..b31b399 100644 --- a/org.go +++ b/org.go @@ -2,7 +2,8 @@ package mackerel // Org information type Org struct { - Name string `json:"name"` + Name string `json:"name"` + DisplayName string `json:"displayName,omitempty"` } // GetOrg gets the org. diff --git a/org_test.go b/org_test.go index a136be8..10f6ccd 100644 --- a/org_test.go +++ b/org_test.go @@ -33,4 +33,39 @@ func TestGetOrg(t *testing.T) { 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) + } }