Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DisplayName to Org #153

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading