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

Function TestOrganizationsService_ListIter

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

Source from the content-addressed store, hash-verified

8728}
8729
8730func TestOrganizationsService_ListIter(t *testing.T) {
8731 t.Parallel()
8732 client, mux, _ := setup(t)
8733 var callNum int
8734 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
8735 callNum++
8736 switch callNum {
8737 case 1:
8738 w.Header().Set("Link", `<https://api.github.com/?page=1>; rel="next"`)
8739 fmt.Fprint(w, `[{},{},{}]`)
8740 case 2:
8741 fmt.Fprint(w, `[{},{},{},{}]`)
8742 case 3:
8743 fmt.Fprint(w, `[{},{}]`)
8744 case 4:
8745 w.WriteHeader(http.StatusNotFound)
8746 case 5:
8747 fmt.Fprint(w, `[{},{}]`)
8748 }
8749 })
8750
8751 iter := client.Organizations.ListIter(t.Context(), "", nil)
8752 var gotItems int
8753 for _, err := range iter {
8754 gotItems++
8755 if err != nil {
8756 t.Errorf("Unexpected error: %v", err)
8757 }
8758 }
8759 if want := 7; gotItems != want {
8760 t.Errorf("client.Organizations.ListIter call 1 got %v items; want %v", gotItems, want)
8761 }
8762
8763 opts := &ListOptions{}
8764 iter = client.Organizations.ListIter(t.Context(), "", opts)
8765 gotItems = 0
8766 for _, err := range iter {
8767 gotItems++
8768 if err != nil {
8769 t.Errorf("Unexpected error: %v", err)
8770 }
8771 }
8772 if want := 2; gotItems != want {
8773 t.Errorf("client.Organizations.ListIter call 2 got %v items; want %v", gotItems, want)
8774 }
8775
8776 iter = client.Organizations.ListIter(t.Context(), "", nil)
8777 gotItems = 0
8778 for _, err := range iter {
8779 gotItems++
8780 if err == nil {
8781 t.Error("expected error; got nil")
8782 }
8783 }
8784 if gotItems != 1 {
8785 t.Errorf("client.Organizations.ListIter call 3 got %v items; want 1 (an error)", gotItems)
8786 }
8787

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…