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

Function TestAuthFeatures

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

Source from the content-addressed store, hash-verified

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

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