(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestResolveCapiURL(t *testing.T) { |
| 17 | tests := []struct { |
| 18 | name string |
| 19 | resp string |
| 20 | wantURL string |
| 21 | wantErr bool |
| 22 | }{ |
| 23 | { |
| 24 | name: "returns resolved URL", |
| 25 | resp: `{"data":{"viewer":{"copilotEndpoints":{"api":"https://test-copilot-api.example.com"}}}}`, |
| 26 | wantURL: "https://test-copilot-api.example.com", |
| 27 | }, |
| 28 | { |
| 29 | name: "ghe.com tenant URL", |
| 30 | resp: `{"data":{"viewer":{"copilotEndpoints":{"api":"https://test-copilot-api.tenant.example.com"}}}}`, |
| 31 | wantURL: "https://test-copilot-api.tenant.example.com", |
| 32 | }, |
| 33 | { |
| 34 | name: "empty URL returns error", |
| 35 | resp: `{"data":{"viewer":{"copilotEndpoints":{"api":""}}}}`, |
| 36 | wantErr: true, |
| 37 | }, |
| 38 | } |
| 39 | |
| 40 | for _, tt := range tests { |
| 41 | t.Run(tt.name, func(t *testing.T) { |
| 42 | reg := &httpmock.Registry{} |
| 43 | defer reg.Verify(t) |
| 44 | |
| 45 | reg.Register( |
| 46 | httpmock.GraphQL(`query CopilotEndpoints\b`), |
| 47 | httpmock.StringResponse(tt.resp), |
| 48 | ) |
| 49 | |
| 50 | httpClient := &http.Client{Transport: reg} |
| 51 | url, err := resolveCapiURL(httpClient, "github.com") |
| 52 | |
| 53 | if tt.wantErr { |
| 54 | require.Error(t, err) |
| 55 | return |
| 56 | } |
| 57 | |
| 58 | require.NoError(t, err) |
| 59 | assert.Equal(t, tt.wantURL, url) |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestCapiClientFuncResolvesURL(t *testing.T) { |
| 65 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected