Skip to content

Commit

Permalink
Merge pull request #153 from mackerelio/orgs-display_name
Browse files Browse the repository at this point in the history
Add `DisplayName` to `Org`
  • Loading branch information
yohfee authored Mar 11, 2024
2 parents d090012 + 655edf8 commit 3d928b0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 35 additions & 0 deletions org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 3d928b0

Please sign in to comment.