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

Function TestRepositoriesService_ListIter

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

Source from the content-addressed store, hash-verified

12184}
12185
12186func TestRepositoriesService_ListIter(t *testing.T) {
12187 t.Parallel()
12188 client, mux, _ := setup(t)
12189 var callNum int
12190 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
12191 callNum++
12192 switch callNum {
12193 case 1:
12194 w.Header().Set("Link", `<https://api.github.com/?page=1>; rel="next"`)
12195 fmt.Fprint(w, `[{},{},{}]`)
12196 case 2:
12197 fmt.Fprint(w, `[{},{},{},{}]`)
12198 case 3:
12199 fmt.Fprint(w, `[{},{}]`)
12200 case 4:
12201 w.WriteHeader(http.StatusNotFound)
12202 case 5:
12203 fmt.Fprint(w, `[{},{}]`)
12204 }
12205 })
12206
12207 iter := client.Repositories.ListIter(t.Context(), "", nil)
12208 var gotItems int
12209 for _, err := range iter {
12210 gotItems++
12211 if err != nil {
12212 t.Errorf("Unexpected error: %v", err)
12213 }
12214 }
12215 if want := 7; gotItems != want {
12216 t.Errorf("client.Repositories.ListIter call 1 got %v items; want %v", gotItems, want)
12217 }
12218
12219 opts := &RepositoryListOptions{}
12220 iter = client.Repositories.ListIter(t.Context(), "", opts)
12221 gotItems = 0
12222 for _, err := range iter {
12223 gotItems++
12224 if err != nil {
12225 t.Errorf("Unexpected error: %v", err)
12226 }
12227 }
12228 if want := 2; gotItems != want {
12229 t.Errorf("client.Repositories.ListIter call 2 got %v items; want %v", gotItems, want)
12230 }
12231
12232 iter = client.Repositories.ListIter(t.Context(), "", nil)
12233 gotItems = 0
12234 for _, err := range iter {
12235 gotItems++
12236 if err == nil {
12237 t.Error("expected error; got nil")
12238 }
12239 }
12240 if gotItems != 1 {
12241 t.Errorf("client.Repositories.ListIter call 3 got %v items; want 1 (an error)", gotItems)
12242 }
12243

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…