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

Function Test_getCurrentUsername

pkg/cmd/pr/status/http_test.go:12–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func Test_getCurrentUsername(t *testing.T) {
13 tests := []struct {
14 name string
15 username string
16 hostname string
17 serverUsername string
18 currentUsername string
19 }{
20 {
21 name: "dotcom",
22 username: "@me",
23 hostname: "github.com",
24 currentUsername: "@me",
25 },
26 {
27 name: "ghec data residency (ghe.com)",
28 username: "@me",
29 hostname: "stampname.ghe.com",
30 currentUsername: "@me",
31 },
32 {
33 name: "ghes",
34 username: "@me",
35 hostname: "my.server.com",
36 serverUsername: "@serverUserName",
37 currentUsername: "@serverUserName",
38 },
39 }
40 for _, tt := range tests {
41 t.Run(tt.name, func(t *testing.T) {
42 clientStub := &http.Client{}
43 if tt.serverUsername != "" {
44 reg := &httpmock.Registry{}
45 defer reg.Verify(t)
46
47 reg.Register(
48 httpmock.GraphQL(`query UserCurrent\b`),
49 httpmock.StringResponse(`{"data":{"viewer":{"login":"`+tt.serverUsername+`"}}}`),
50 )
51
52 clientStub.Transport = reg
53 }
54
55 apiClientStub := api.NewClientFromHTTP(clientStub)
56
57 currentUsername, err := getCurrentUsername(tt.username, tt.hostname, apiClientStub)
58 assert.NoError(t, err)
59 assert.Equal(t, tt.currentUsername, currentUsername)
60 })
61 }
62}

Callers

nothing calls this directly

Calls 8

VerifyMethod · 0.95
RegisterMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
NewClientFromHTTPFunction · 0.92
getCurrentUsernameFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected