Skip to content

Commit

Permalink
Merge pull request heimweh#117 from drastawi/allow_for_paged_resources
Browse files Browse the repository at this point in the history
Test and restore paged resources support
  • Loading branch information
imjaroiswebdev authored Jan 17, 2023
2 parents 65eb8c4 + 05ecc15 commit 310c225
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pagerduty/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ type offsetQueryOptionsGen interface {
}

type simpleOffsetQueryOptionsGen struct {
offset int `url:"offset,omitempty"`
Offset int `url:"offset,omitempty"`
}

func (o *simpleOffsetQueryOptionsGen) currentOffset() int {
return o.offset
return o.Offset
}

func (o *simpleOffsetQueryOptionsGen) changeOffset(i int) {
o.offset = i
o.Offset = i
}

func (o *simpleOffsetQueryOptionsGen) buildStruct() interface{} {
Expand Down
40 changes: 40 additions & 0 deletions pagerduty/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,46 @@ func TestTeamsGetMembers(t *testing.T) {
}
}

func TestPagedTeamsGetMembers(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/teams/1/members", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
if r.URL.Query().Get("offset") == "1" {
w.Write([]byte(`{"members": [{"user": {"id": "2"}, "role": "observer"}], "limit": 1, "offset": 1, "more": false}`))
} else {
w.Write([]byte(`{"members": [{"user": {"id": "1"}, "role": "manager"}], "limit": 1, "offset": 0, "more": true}`))
}
})

resp, _, err := client.Teams.GetMembers("1", &GetMembersOptions{})
if err != nil {
t.Fatal(err)
}

want := &GetMembersResponse{
Members: []*Member{
{
User: &UserReference{
ID: "1",
},
Role: "manager",
},
{
User: &UserReference{
ID: "2",
},
Role: "observer",
},
},
}

if !reflect.DeepEqual(resp, want) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want)
}
}

func TestTeamsAddEscalationPolicy(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 310c225

Please sign in to comment.