@@ -132,64 +132,93 @@ func TestListPipelineBridges(t *testing.T) {
132132}
133133
134134func TestListRefMostRecentJobs (t * testing.T ) {
135- ctx , mux , server , c := getMockedClient ()
136- defer server .Close ()
137-
138- ref := schemas.Ref {
139- Project : schemas .NewProject ("foo" ),
140- Name : "yay" ,
135+ tests := []struct {
136+ name string
137+ keysetPagination bool
138+ expectedQueryParams url.Values
139+ }{
140+ {
141+ name : "offset pagination" ,
142+ keysetPagination : false ,
143+ expectedQueryParams : url.Values {
144+ "page" : []string {"1" },
145+ "per_page" : []string {"100" },
146+ },
147+ },
148+ {
149+ name : "keyset pagination" ,
150+ keysetPagination : true ,
151+ expectedQueryParams : url.Values {
152+ "pagination" : []string {"keyset" },
153+ "per_page" : []string {"100" },
154+ },
155+ },
141156 }
142157
143- jobs , err := c .ListRefMostRecentJobs (ctx , ref )
144- assert .NoError (t , err )
145- assert .Len (t , jobs , 0 )
158+ for _ , tc := range tests {
159+ t .Run (tc .name , func (t * testing.T ) {
160+ ctx , mux , server , c := getMockedClient ()
161+ defer server .Close ()
146162
147- mux .HandleFunc ("/api/v4/projects/foo/jobs" ,
148- func (w http.ResponseWriter , r * http.Request ) {
149- assert .Equal (t , "GET" , r .Method )
150- expectedQueryParams := url.Values {
151- "pagination" : []string {"keyset" },
152- "per_page" : []string {"100" },
163+ if tc .keysetPagination {
164+ c .UpdateVersion (NewGitLabVersion ("16.0.0" ))
165+ } else {
166+ c .UpdateVersion (NewGitLabVersion ("15.0.0" ))
153167 }
154- assert .Equal (t , expectedQueryParams , r .URL .Query ())
155- fmt .Fprint (w , `[{"id":3,"name":"foo","ref":"yay"},{"id":4,"name":"bar","ref":"yay"}]` )
156- })
157168
158- mux . HandleFunc ( fmt . Sprintf ( "/api/v4/projects/bar/jobs" ),
159- func ( w http. ResponseWriter , r * http. Request ) {
160- w . WriteHeader ( http . StatusNotFound )
161- })
169+ ref := schemas. Ref {
170+ Project : schemas . NewProject ( "foo" ),
171+ Name : "yay" ,
172+ }
162173
163- ref .LatestJobs = schemas.Jobs {
164- "foo" : {
165- ID : 1 ,
166- Name : "foo" ,
167- },
168- "bar" : {
169- ID : 2 ,
170- Name : "bar" ,
171- },
172- }
174+ jobs , err := c .ListRefMostRecentJobs (ctx , ref )
175+ assert .NoError (t , err )
176+ assert .Len (t , jobs , 0 )
177+
178+ mux .HandleFunc ("/api/v4/projects/foo/jobs" ,
179+ func (w http.ResponseWriter , r * http.Request ) {
180+ assert .Equal (t , "GET" , r .Method )
181+ assert .Equal (t , tc .expectedQueryParams , r .URL .Query ())
182+ fmt .Fprint (w , `[{"id":3,"name":"foo","ref":"yay"},{"id":4,"name":"bar","ref":"yay"}]` )
183+ })
184+
185+ mux .HandleFunc (fmt .Sprintf ("/api/v4/projects/bar/jobs" ),
186+ func (w http.ResponseWriter , r * http.Request ) {
187+ w .WriteHeader (http .StatusNotFound )
188+ })
189+
190+ ref .LatestJobs = schemas.Jobs {
191+ "foo" : {
192+ ID : 1 ,
193+ Name : "foo" ,
194+ },
195+ "bar" : {
196+ ID : 2 ,
197+ Name : "bar" ,
198+ },
199+ }
173200
174- jobs , err = c .ListRefMostRecentJobs (ctx , ref )
175- assert .NoError (t , err )
176- assert .Len (t , jobs , 2 )
177- assert .Equal (t , 3 , jobs [0 ].ID )
178- assert .Equal (t , 4 , jobs [1 ].ID )
201+ jobs , err = c .ListRefMostRecentJobs (ctx , ref )
202+ assert .NoError (t , err )
203+ assert .Len (t , jobs , 2 )
204+ assert .Equal (t , 3 , jobs [0 ].ID )
205+ assert .Equal (t , 4 , jobs [1 ].ID )
179206
180- ref .LatestJobs ["baz" ] = schemas.Job {
181- ID : 5 ,
182- Name : "baz" ,
183- }
207+ ref .LatestJobs ["baz" ] = schemas.Job {
208+ ID : 5 ,
209+ Name : "baz" ,
210+ }
184211
185- jobs , err = c .ListRefMostRecentJobs (ctx , ref )
186- assert .NoError (t , err )
187- assert .Len (t , jobs , 2 )
188- assert .Equal (t , 3 , jobs [0 ].ID )
189- assert .Equal (t , 4 , jobs [1 ].ID )
212+ jobs , err = c .ListRefMostRecentJobs (ctx , ref )
213+ assert .NoError (t , err )
214+ assert .Len (t , jobs , 2 )
215+ assert .Equal (t , 3 , jobs [0 ].ID )
216+ assert .Equal (t , 4 , jobs [1 ].ID )
190217
191- // Test invalid project id
192- ref .Project .Name = "bar"
193- _ , err = c .ListRefMostRecentJobs (ctx , ref )
194- assert .Error (t , err )
218+ // Test invalid project id
219+ ref .Project .Name = "bar"
220+ _ , err = c .ListRefMostRecentJobs (ctx , ref )
221+ assert .Error (t , err )
222+ })
223+ }
195224}
0 commit comments