Skip to content

Commit

Permalink
Differentiate DisplayName test
Browse files Browse the repository at this point in the history
  • Loading branch information
yohfee committed Mar 11, 2024
1 parent 986de35 commit 655edf8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 655edf8

Please sign in to comment.