MCPcopy Index your code
hub / github.com/google/go-github / TestLicensesService_ListIter

Function TestLicensesService_ListIter

github/github-iterators_test.go:8298–8368  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8296}
8297
8298func TestLicensesService_ListIter(t *testing.T) {
8299 t.Parallel()
8300 client, mux, _ := setup(t)
8301 var callNum int
8302 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
8303 callNum++
8304 switch callNum {
8305 case 1:
8306 w.Header().Set("Link", `<https://api.github.com/?page=1>; rel="next"`)
8307 fmt.Fprint(w, `[{},{},{}]`)
8308 case 2:
8309 fmt.Fprint(w, `[{},{},{},{}]`)
8310 case 3:
8311 fmt.Fprint(w, `[{},{}]`)
8312 case 4:
8313 w.WriteHeader(http.StatusNotFound)
8314 case 5:
8315 fmt.Fprint(w, `[{},{}]`)
8316 }
8317 })
8318
8319 iter := client.Licenses.ListIter(t.Context(), nil)
8320 var gotItems int
8321 for _, err := range iter {
8322 gotItems++
8323 if err != nil {
8324 t.Errorf("Unexpected error: %v", err)
8325 }
8326 }
8327 if want := 7; gotItems != want {
8328 t.Errorf("client.Licenses.ListIter call 1 got %v items; want %v", gotItems, want)
8329 }
8330
8331 opts := &ListLicensesOptions{}
8332 iter = client.Licenses.ListIter(t.Context(), opts)
8333 gotItems = 0
8334 for _, err := range iter {
8335 gotItems++
8336 if err != nil {
8337 t.Errorf("Unexpected error: %v", err)
8338 }
8339 }
8340 if want := 2; gotItems != want {
8341 t.Errorf("client.Licenses.ListIter call 2 got %v items; want %v", gotItems, want)
8342 }
8343
8344 iter = client.Licenses.ListIter(t.Context(), nil)
8345 gotItems = 0
8346 for _, err := range iter {
8347 gotItems++
8348 if err == nil {
8349 t.Error("expected error; got nil")
8350 }
8351 }
8352 if gotItems != 1 {
8353 t.Errorf("client.Licenses.ListIter call 3 got %v items; want 1 (an error)", gotItems)
8354 }
8355

Callers

nothing calls this directly

Calls 3

setupFunction · 0.70
ListIterMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…