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

Function Test_NewCmdView

pkg/cmd/codespace/view_test.go:12–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func Test_NewCmdView(t *testing.T) {
13 tests := []struct {
14 tName string
15 codespaceName string
16 opts *viewOptions
17 cliArgs []string
18 wantErr bool
19 wantStdout string
20 errMsg string
21 }{
22 {
23 tName: "selector throws because no terminal found",
24 opts: &viewOptions{},
25 wantErr: true,
26 errMsg: "choosing codespace: error getting answers: no terminal",
27 },
28 {
29 tName: "command fails because provided codespace doesn't exist",
30 codespaceName: "i-dont-exist",
31 opts: &viewOptions{},
32 wantErr: true,
33 errMsg: "getting full codespace details: codespace not found",
34 },
35 {
36 tName: "command succeeds because codespace exists (no details)",
37 codespaceName: "monalisa-cli-cli-abcdef",
38 opts: &viewOptions{},
39 wantErr: false,
40 wantStdout: "Name\tmonalisa-cli-cli-abcdef\nState\t\nRepository\t\nGit Status\t - 0 commits ahead, 0 commits behind\nDevcontainer Path\t\nMachine Display Name\t\nIdle Timeout\t0 minutes\nCreated At\t\nRetention Period\t\n",
41 },
42 {
43 tName: "command succeeds because codespace exists (with details)",
44 codespaceName: "monalisa-cli-cli-hijklm",
45 opts: &viewOptions{},
46 wantErr: false,
47 wantStdout: "Name\tmonalisa-cli-cli-hijklm\nState\tAvailable\nRepository\tcli/cli\nGit Status\tmain* - 1 commit ahead, 2 commits behind\nDevcontainer Path\t.devcontainer/devcontainer.json\nMachine Display Name\tTest Display Name\nIdle Timeout\t30 minutes\nCreated At\t\nRetention Period\t1 day\n",
48 },
49 }
50
51 for _, tt := range tests {
52 t.Run(tt.tName, func(t *testing.T) {
53 ios, _, stdout, _ := iostreams.Test()
54 a := &App{
55 apiClient: testViewApiMock(),
56 io: ios,
57 }
58 selector := &CodespaceSelector{api: a.apiClient, codespaceName: tt.codespaceName}
59 tt.opts.selector = selector
60
61 var err error
62 if tt.cliArgs == nil {
63 if tt.opts.selector == nil {
64 t.Fatalf("selector must be set in opts if cliArgs are not provided")
65 }
66
67 err = a.ViewCodespace(context.Background(), tt.opts)
68 } else {
69 cmd := newViewCmd(a)

Callers

nothing calls this directly

Calls 8

ViewCodespaceMethod · 0.95
TestFunction · 0.92
testViewApiMockFunction · 0.85
newViewCmdFunction · 0.85
RunMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected