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

Function TestActivityService_ListStargazersIter

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

Source from the content-addressed store, hash-verified

2824}
2825
2826func TestActivityService_ListStargazersIter(t *testing.T) {
2827 t.Parallel()
2828 client, mux, _ := setup(t)
2829 var callNum int
2830 mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
2831 callNum++
2832 switch callNum {
2833 case 1:
2834 w.Header().Set("Link", `<https://api.github.com/?page=1>; rel="next"`)
2835 fmt.Fprint(w, `[{},{},{}]`)
2836 case 2:
2837 fmt.Fprint(w, `[{},{},{},{}]`)
2838 case 3:
2839 fmt.Fprint(w, `[{},{}]`)
2840 case 4:
2841 w.WriteHeader(http.StatusNotFound)
2842 case 5:
2843 fmt.Fprint(w, `[{},{}]`)
2844 }
2845 })
2846
2847 iter := client.Activity.ListStargazersIter(t.Context(), "", "", nil)
2848 var gotItems int
2849 for _, err := range iter {
2850 gotItems++
2851 if err != nil {
2852 t.Errorf("Unexpected error: %v", err)
2853 }
2854 }
2855 if want := 7; gotItems != want {
2856 t.Errorf("client.Activity.ListStargazersIter call 1 got %v items; want %v", gotItems, want)
2857 }
2858
2859 opts := &ListOptions{}
2860 iter = client.Activity.ListStargazersIter(t.Context(), "", "", opts)
2861 gotItems = 0
2862 for _, err := range iter {
2863 gotItems++
2864 if err != nil {
2865 t.Errorf("Unexpected error: %v", err)
2866 }
2867 }
2868 if want := 2; gotItems != want {
2869 t.Errorf("client.Activity.ListStargazersIter call 2 got %v items; want %v", gotItems, want)
2870 }
2871
2872 iter = client.Activity.ListStargazersIter(t.Context(), "", "", nil)
2873 gotItems = 0
2874 for _, err := range iter {
2875 gotItems++
2876 if err == nil {
2877 t.Error("expected error; got nil")
2878 }
2879 }
2880 if gotItems != 1 {
2881 t.Errorf("client.Activity.ListStargazersIter call 3 got %v items; want 1 (an error)", gotItems)
2882 }
2883

Callers

nothing calls this directly

Calls 3

ListStargazersIterMethod · 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…