MCPcopy Create free account
hub / github.com/cli/cli / TestNewCmdToken

Function TestNewCmdToken

pkg/cmd/auth/token/token_test.go:20–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestNewCmdToken(t *testing.T) {
21 tests := []struct {
22 name string
23 input string
24 output TokenOptions
25 wantErr bool
26 wantErrMsg string
27 }{
28 {
29 name: "no flags",
30 input: "",
31 output: TokenOptions{},
32 },
33 {
34 name: "with hostname",
35 input: "--hostname github.mycompany.com",
36 output: TokenOptions{Hostname: "github.mycompany.com"},
37 },
38 {
39 name: "with user",
40 input: "--user test-user",
41 output: TokenOptions{Username: "test-user"},
42 },
43 {
44 name: "with shorthand user",
45 input: "-u test-user",
46 output: TokenOptions{Username: "test-user"},
47 },
48 {
49 name: "with shorthand hostname",
50 input: "-h github.mycompany.com",
51 output: TokenOptions{Hostname: "github.mycompany.com"},
52 },
53 {
54 name: "with secure-storage",
55 input: "--secure-storage",
56 output: TokenOptions{SecureStorage: true},
57 },
58 {
59 name: "with no-refresh",
60 input: "--no-refresh",
61 output: TokenOptions{NoRefresh: true},
62 },
63 }
64
65 for _, tt := range tests {
66 t.Run(tt.name, func(t *testing.T) {
67 ios, _, _, _ := iostreams.Test()
68 f := &cmdutil.Factory{
69 IOStreams: ios,
70 Config: func() (gh.Config, error) {
71 cfg := config.NewMockConfig()
72 return cfg, nil
73 },
74 }
75 argv, err := shlex.Split(tt.input)
76 require.NoError(t, err)
77

Callers

nothing calls this directly

Calls 6

TestFunction · 0.92
NewMockConfigFunction · 0.92
NewCmdTokenFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected