(t *testing.T)
| 775 | } |
| 776 | |
| 777 | func 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 | |
| 821 | func TestActionsFeatures(t *testing.T) { |
| 822 | tests := []struct { |
nothing calls this directly
no test coverage detected