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

Function TestCodespacesService_ListIter

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

Source from the content-addressed store, hash-verified

4408}
4409
4410func TestCodespacesService_ListIter(t *testing.T) {
4411 t.Parallel()
4412 client, mux, _ := setup(t)
4413 var callNum int
4414 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
4415 callNum++
4416 switch callNum {
4417 case 1:
4418 w.Header().Set("Link", `<https://api.github.com/?page=1>; rel="next"`)
4419 fmt.Fprint(w, `{"codespaces": [{},{},{}]}`)
4420 case 2:
4421 fmt.Fprint(w, `{"codespaces": [{},{},{},{}]}`)
4422 case 3:
4423 fmt.Fprint(w, `{"codespaces": [{},{}]}`)
4424 case 4:
4425 w.WriteHeader(http.StatusNotFound)
4426 case 5:
4427 fmt.Fprint(w, `{"codespaces": [{},{}]}`)
4428 }
4429 })
4430
4431 iter := client.Codespaces.ListIter(t.Context(), nil)
4432 var gotItems int
4433 for _, err := range iter {
4434 gotItems++
4435 if err != nil {
4436 t.Errorf("Unexpected error: %v", err)
4437 }
4438 }
4439 if want := 7; gotItems != want {
4440 t.Errorf("client.Codespaces.ListIter call 1 got %v items; want %v", gotItems, want)
4441 }
4442
4443 opts := &ListCodespacesOptions{}
4444 iter = client.Codespaces.ListIter(t.Context(), opts)
4445 gotItems = 0
4446 for _, err := range iter {
4447 gotItems++
4448 if err != nil {
4449 t.Errorf("Unexpected error: %v", err)
4450 }
4451 }
4452 if want := 2; gotItems != want {
4453 t.Errorf("client.Codespaces.ListIter call 2 got %v items; want %v", gotItems, want)
4454 }
4455
4456 iter = client.Codespaces.ListIter(t.Context(), nil)
4457 gotItems = 0
4458 for _, err := range iter {
4459 gotItems++
4460 if err == nil {
4461 t.Error("expected error; got nil")
4462 }
4463 }
4464 if gotItems != 1 {
4465 t.Errorf("client.Codespaces.ListIter call 3 got %v items; want 1 (an error)", gotItems)
4466 }
4467

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…