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

Function TestAuthFeatures

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

Source from the content-addressed store, hash-verified

777}
778
779func TestAuthFeatures(t *testing.T) {
780 tests := []struct {
781 hostname string
782 installedVersion string
783 metaStatus int
784 wantExpiring bool
785 wantErr bool
786 }{
787 {hostname: "github.com", wantExpiring: true},
788 {hostname: "tenant.ghe.com", wantExpiring: true},
789 {hostname: "github.example.com", installedVersion: "3.19.0"},
790 {hostname: "github.example.com", installedVersion: "3.22.999"},
791 {hostname: "github.example.com", installedVersion: "3.23.0", wantExpiring: true},
792 {hostname: "github.example.com", installedVersion: "3.24.0", wantExpiring: true},
793 {hostname: "github.example.com", installedVersion: "invalid", wantErr: true},
794 {hostname: "github.example.com", wantErr: true},
795 {hostname: "github.example.com", metaStatus: http.StatusServiceUnavailable, wantErr: true},
796 }
797 for _, tt := range tests {
798 t.Run(tt.hostname+"/"+tt.installedVersion, func(t *testing.T) {
799 reg := &httpmock.Registry{}
800 defer reg.Verify(t)
801 if tt.installedVersion != "" || tt.wantErr {
802 response := httpmock.JSONResponse(map[string]string{"installed_version": tt.installedVersion})
803 if tt.metaStatus != 0 {
804 response = httpmock.StatusStringResponse(tt.metaStatus, `{"message":"Service Unavailable"}`)
805 }
806 reg.Register(
807 httpmock.WithHost(httpmock.REST("GET", "api/v3/meta"), tt.hostname),
808 response,
809 )
810 }
811
812 features, err := NewDetector(&http.Client{Transport: reg}, tt.hostname).AuthFeatures()
813 if tt.wantErr {
814 require.Error(t, err)
815 return
816 }
817 require.NoError(t, err)
818 assert.Equal(t, tt.wantExpiring, features.ExpiringTokens)
819 })
820 }
821}
822
823func TestNewCachedDetector(t *testing.T) {
824 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 11

VerifyMethod · 0.95
RegisterMethod · 0.95
JSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
WithHostFunction · 0.92
RESTFunction · 0.92
NewDetectorFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
AuthFeaturesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected