(t *testing.T)
| 956 | } |
| 957 | |
| 958 | func TestEventsFeatures(t *testing.T) { |
| 959 | tests := []struct { |
| 960 | name string |
| 961 | hostname string |
| 962 | status int |
| 963 | wantFeatures EventsFeatures |
| 964 | wantErr bool |
| 965 | }{ |
| 966 | { |
| 967 | name: "subscriptions enabled", |
| 968 | hostname: "github.com", |
| 969 | status: http.StatusOK, |
| 970 | wantFeatures: EventsFeatures{Subscriptions: true}, |
| 971 | }, |
| 972 | { |
| 973 | name: "subscriptions not enabled", |
| 974 | hostname: "github.com", |
| 975 | status: http.StatusForbidden, |
| 976 | wantFeatures: EventsFeatures{Subscriptions: false}, |
| 977 | }, |
| 978 | { |
| 979 | name: "endpoint does not exist", |
| 980 | hostname: "github.com", |
| 981 | status: http.StatusNotFound, |
| 982 | wantFeatures: EventsFeatures{Subscriptions: false}, |
| 983 | }, |
| 984 | { |
| 985 | name: "server error", |
| 986 | hostname: "github.com", |
| 987 | status: http.StatusInternalServerError, |
| 988 | wantErr: true, |
| 989 | }, |
| 990 | { |
| 991 | name: "GHES host", |
| 992 | hostname: "ghe.example.com", |
| 993 | wantFeatures: EventsFeatures{Subscriptions: false}, |
| 994 | }, |
| 995 | { |
| 996 | name: "GHE.com host", |
| 997 | hostname: "example.ghe.com", |
| 998 | wantFeatures: EventsFeatures{Subscriptions: false}, |
| 999 | }, |
| 1000 | } |
| 1001 | |
| 1002 | for _, tt := range tests { |
| 1003 | t.Run(tt.name, func(t *testing.T) { |
| 1004 | reg := &httpmock.Registry{} |
| 1005 | defer reg.Verify(t) |
| 1006 | if tt.status != 0 { |
| 1007 | reg.Register( |
| 1008 | httpmock.QueryMatcher("GET", "event-subscriptions", url.Values{"per_page": {"1"}}), |
| 1009 | func(req *http.Request) (*http.Response, error) { |
| 1010 | assert.Equal(t, "true", req.Header.Get("gh-feature-detection")) |
| 1011 | return httpmock.StatusStringResponse(tt.status, `{}`)(req) |
| 1012 | }) |
| 1013 | } |
| 1014 | |
| 1015 | features, err := NewDetector(&http.Client{Transport: reg}, tt.hostname).EventsFeatures() |
nothing calls this directly
no test coverage detected