MCPcopy Create free account
hub / github.com/cli/cli / TestDetectorClient

Function TestDetectorClient

internal/featuredetection/feature_detection_test.go:840–888  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

838}
839
840func TestDetectorClient(t *testing.T) {
841 tests := []struct {
842 name string
843 cacheTTL time.Duration
844 extraStatuses []int
845 wantTTL []string
846 wantStatuses []string
847 }{
848 {
849 name: "uncached detector",
850 },
851 {
852 name: "uncached detector ignores extra statuses",
853 extraStatuses: []int{http.StatusForbidden, http.StatusNotFound},
854 },
855 {
856 name: "cached detector",
857 cacheTTL: 24 * time.Hour,
858 wantTTL: []string{"24h0m0s"},
859 },
860 {
861 name: "cached detector with extra statuses",
862 cacheTTL: 24 * time.Hour,
863 extraStatuses: []int{http.StatusForbidden, http.StatusNotFound},
864 wantTTL: []string{"24h0m0s"},
865 wantStatuses: []string{"403,404"},
866 },
867 }
868
869 for _, tt := range tests {
870 t.Run(tt.name, func(t *testing.T) {
871 reg := &httpmock.Registry{}
872 defer reg.Verify(t)
873 var gotHeader http.Header
874 reg.Register(httpmock.REST("GET", "probe"), func(req *http.Request) (*http.Response, error) {
875 gotHeader = req.Header
876 return httpmock.StringResponse("{}")(req)
877 })
878
879 d := &detector{host: "github.com", httpClient: &http.Client{Transport: reg}, cacheTTL: tt.cacheTTL}
880 res, err := d.client(tt.extraStatuses...).Get("https://api.github.com/probe")
881 require.NoError(t, err)
882 res.Body.Close()
883
884 assert.Equal(t, tt.wantTTL, gotHeader.Values("X-GH-CACHE-TTL"))
885 assert.Equal(t, tt.wantStatuses, gotHeader.Values("X-GH-CACHE-STATUSES"))
886 })
887 }
888}
889
890func TestActionsFeatures(t *testing.T) {
891 tests := []struct {

Callers

nothing calls this directly

Calls 9

VerifyMethod · 0.95
RegisterMethod · 0.95
clientMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected