MCPcopy Index your code
hub / github.com/cli/cli / TestResolveCapiURL

Function TestResolveCapiURL

pkg/cmd/agent-task/shared/capi_test.go:16–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func 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
64func TestCapiClientFuncResolvesURL(t *testing.T) {
65 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 8

VerifyMethod · 0.95
RegisterMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
resolveCapiURLFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected