@@ -4,9 +4,10 @@ import (
44 "bytes"
55 "encoding/json"
66 "io/ioutil"
7- "reflect"
87 "testing"
98
9+ "github.com/stretchr/testify/assert"
10+
1011 "github.com/cli/cli/internal/ghrepo"
1112 "github.com/cli/cli/pkg/httpmock"
1213)
@@ -73,6 +74,7 @@ func TestIssueList(t *testing.T) {
7374func TestIssueList_pagination (t * testing.T ) {
7475 http := & httpmock.Registry {}
7576 client := NewClient (ReplaceTripper (http ))
77+
7678 http .StubResponse (200 , bytes .NewBufferString (`
7779 { "data": { "repository": {
7880 "hasIssuesEnabled": true,
@@ -111,42 +113,33 @@ func TestIssueList_pagination(t *testing.T) {
111113 }
112114 } } }
113115 ` ))
114- repo := ghrepo .New ("OWNER" , "REPO" )
115116
116- want := & IssuesAndTotalCount {
117- Issues : []Issue {
118- {
119- Title : "issue1" ,
120- Assignees : struct {
121- Nodes []struct { Login string }
122- TotalCount int
123- }{[]struct { Login string }{{"user1" }}, 1 },
124- Labels : struct {
125- Nodes []struct { Name string }
126- TotalCount int
127- }{[]struct { Name string }{{"bug" }}, 1 },
128- },
129- {
130- Title : "issue2" ,
131- Assignees : struct {
132- Nodes []struct { Login string }
133- TotalCount int
134- }{[]struct { Login string }{{"user2" }}, 1 },
135- Labels : struct {
136- Nodes []struct { Name string }
137- TotalCount int
138- }{[]struct { Name string }{{"enhancement" }}, 1 },
139- },
140- },
141- TotalCount : 2 ,
117+ repo := ghrepo .New ("OWNER" , "REPO" )
118+ res , err := IssueList (client , repo , "" , nil , "" , 0 , "" , "" , "" )
119+ if err != nil {
120+ t .Fatalf ("IssueList() error = %v" , err )
142121 }
143122
144- got , err := IssueList (client , repo , "" , nil , "" , 0 , "" , "" , "" )
145- if err != nil {
146- t .Errorf ("IssueList() error = %v" , err )
147- return
123+ assert .Equal (t , 2 , res .TotalCount )
124+ assert .Equal (t , 2 , len (res .Issues ))
125+
126+ getLabels := func (i Issue ) []string {
127+ var labels []string
128+ for _ , l := range i .Labels .Nodes {
129+ labels = append (labels , l .Name )
130+ }
131+ return labels
148132 }
149- if ! reflect .DeepEqual (got , want ) {
150- t .Errorf ("IssueList() = %v, want %v" , got , want )
133+ getAssignees := func (i Issue ) []string {
134+ var logins []string
135+ for _ , u := range i .Assignees .Nodes {
136+ logins = append (logins , u .Login )
137+ }
138+ return logins
151139 }
140+
141+ assert .Equal (t , []string {"bug" }, getLabels (res .Issues [0 ]))
142+ assert .Equal (t , []string {"user1" }, getAssignees (res .Issues [0 ]))
143+ assert .Equal (t , []string {"enhancement" }, getLabels (res .Issues [1 ]))
144+ assert .Equal (t , []string {"user2" }, getAssignees (res .Issues [1 ]))
152145}
0 commit comments