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

Function TestGistsService_ListIter

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

Source from the content-addressed store, hash-verified

6928}
6929
6930func TestGistsService_ListIter(t *testing.T) {
6931 t.Parallel()
6932 client, mux, _ := setup(t)
6933 var callNum int
6934 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
6935 callNum++
6936 switch callNum {
6937 case 1:
6938 w.Header().Set("Link", `<https://api.github.com/?page=1>; rel="next"`)
6939 fmt.Fprint(w, `[{},{},{}]`)
6940 case 2:
6941 fmt.Fprint(w, `[{},{},{},{}]`)
6942 case 3:
6943 fmt.Fprint(w, `[{},{}]`)
6944 case 4:
6945 w.WriteHeader(http.StatusNotFound)
6946 case 5:
6947 fmt.Fprint(w, `[{},{}]`)
6948 }
6949 })
6950
6951 iter := client.Gists.ListIter(t.Context(), "", nil)
6952 var gotItems int
6953 for _, err := range iter {
6954 gotItems++
6955 if err != nil {
6956 t.Errorf("Unexpected error: %v", err)
6957 }
6958 }
6959 if want := 7; gotItems != want {
6960 t.Errorf("client.Gists.ListIter call 1 got %v items; want %v", gotItems, want)
6961 }
6962
6963 opts := &GistListOptions{}
6964 iter = client.Gists.ListIter(t.Context(), "", opts)
6965 gotItems = 0
6966 for _, err := range iter {
6967 gotItems++
6968 if err != nil {
6969 t.Errorf("Unexpected error: %v", err)
6970 }
6971 }
6972 if want := 2; gotItems != want {
6973 t.Errorf("client.Gists.ListIter call 2 got %v items; want %v", gotItems, want)
6974 }
6975
6976 iter = client.Gists.ListIter(t.Context(), "", nil)
6977 gotItems = 0
6978 for _, err := range iter {
6979 gotItems++
6980 if err == nil {
6981 t.Error("expected error; got nil")
6982 }
6983 }
6984 if gotItems != 1 {
6985 t.Errorf("client.Gists.ListIter call 3 got %v items; want 1 (an error)", gotItems)
6986 }
6987

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…