MCPcopy Create free account
hub / github.com/google/go-github / TestActivityService_ListWatchersIter

Function TestActivityService_ListWatchersIter

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

Source from the content-addressed store, hash-verified

3112}
3113
3114func TestActivityService_ListWatchersIter(t *testing.T) {
3115 t.Parallel()
3116 client, mux, _ := setup(t)
3117 var callNum int
3118 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
3119 callNum++
3120 switch callNum {
3121 case 1:
3122 w.Header().Set("Link", `<https://api.github.com/?page=1>; rel="next"`)
3123 fmt.Fprint(w, `[{},{},{}]`)
3124 case 2:
3125 fmt.Fprint(w, `[{},{},{},{}]`)
3126 case 3:
3127 fmt.Fprint(w, `[{},{}]`)
3128 case 4:
3129 w.WriteHeader(http.StatusNotFound)
3130 case 5:
3131 fmt.Fprint(w, `[{},{}]`)
3132 }
3133 })
3134
3135 iter := client.Activity.ListWatchersIter(t.Context(), "", "", nil)
3136 var gotItems int
3137 for _, err := range iter {
3138 gotItems++
3139 if err != nil {
3140 t.Errorf("Unexpected error: %v", err)
3141 }
3142 }
3143 if want := 7; gotItems != want {
3144 t.Errorf("client.Activity.ListWatchersIter call 1 got %v items; want %v", gotItems, want)
3145 }
3146
3147 opts := &ListOptions{}
3148 iter = client.Activity.ListWatchersIter(t.Context(), "", "", opts)
3149 gotItems = 0
3150 for _, err := range iter {
3151 gotItems++
3152 if err != nil {
3153 t.Errorf("Unexpected error: %v", err)
3154 }
3155 }
3156 if want := 2; gotItems != want {
3157 t.Errorf("client.Activity.ListWatchersIter call 2 got %v items; want %v", gotItems, want)
3158 }
3159
3160 iter = client.Activity.ListWatchersIter(t.Context(), "", "", nil)
3161 gotItems = 0
3162 for _, err := range iter {
3163 gotItems++
3164 if err == nil {
3165 t.Error("expected error; got nil")
3166 }
3167 }
3168 if gotItems != 1 {
3169 t.Errorf("client.Activity.ListWatchersIter call 3 got %v items; want 1 (an error)", gotItems)
3170 }
3171

Callers

nothing calls this directly

Calls 3

ListWatchersIterMethod · 0.80
setupFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…