(t *testing.T)
| 27 | } |
| 28 | |
| 29 | func TestRevokeToken(t *testing.T) { |
| 30 | tests := []struct { |
| 31 | name string |
| 32 | host string |
| 33 | apiHost string |
| 34 | wantURL string |
| 35 | status int |
| 36 | transportErr error |
| 37 | wantErr string |
| 38 | }{ |
| 39 | { |
| 40 | name: "GitHub.com", host: "github.com", status: 204, |
| 41 | wantURL: "https://api.github.com/applications/" + oauthClientID + "/token", |
| 42 | }, |
| 43 | { |
| 44 | name: "GHES", host: "enterprise.example.com", status: 204, |
| 45 | wantURL: "https://enterprise.example.com/api/v3/applications/" + oauthClientID + "/token", |
| 46 | }, |
| 47 | { |
| 48 | name: "configured API gateway", host: "github.com", apiHost: "gateway.example.com", status: 204, |
| 49 | wantURL: "https://gateway.example.com/applications/" + oauthClientID + "/token", |
| 50 | }, |
| 51 | { |
| 52 | name: "not found is not success", host: "github.com", status: 404, |
| 53 | wantErr: "HTTP 404 (Not Found)", |
| 54 | }, |
| 55 | { |
| 56 | name: "server error omits response message", host: "github.com", status: 500, |
| 57 | wantErr: "HTTP 500 (Internal Server Error)", |
| 58 | }, |
| 59 | { |
| 60 | name: "unexpected successful status", host: "github.com", status: 200, |
| 61 | wantErr: "unexpected HTTP 200 for DELETE https://api.github.com/applications/" + oauthClientID + "/token", |
| 62 | }, |
| 63 | { |
| 64 | name: "does not follow redirects", host: "github.com", status: 302, |
| 65 | wantErr: "HTTP 302 (Found)", |
| 66 | }, |
| 67 | { |
| 68 | name: "request timeout", host: "github.com", transportErr: context.DeadlineExceeded, |
| 69 | wantErr: "request timed out", |
| 70 | }, |
| 71 | { |
| 72 | name: "request cancellation", host: "github.com", transportErr: context.Canceled, |
| 73 | wantErr: "context canceled", |
| 74 | }, |
| 75 | { |
| 76 | name: "transport error redacts credentials", host: "github.com", |
| 77 | transportErr: errors.New("connection failed with gho_test_secret and " + oauthClientSecret), |
| 78 | wantErr: "Delete \"https://api.github.com/applications/" + oauthClientID + "/token\": connection failed with [REDACTED] and [REDACTED]", |
| 79 | }, |
| 80 | } |
| 81 | for _, tt := range tests { |
| 82 | t.Run(tt.name, func(t *testing.T) { |
| 83 | cfg, _ := config.NewIsolatedTestConfig(t, "") |
| 84 | if tt.apiHost != "" { |
| 85 | cfg.Set(tt.host, "api_host", tt.apiHost) |
| 86 | } |
nothing calls this directly
no test coverage detected