MCPcopy
hub / github.com/cli/cli / TestApp_Select

Function TestApp_Select

pkg/cmd/codespace/select_test.go:16–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14const CODESPACE_NAME = "monalisa-cli-cli-abcdef"
15
16func TestApp_Select(t *testing.T) {
17 tests := []struct {
18 name string
19 arg string
20 wantErr bool
21 outputToFile bool
22 wantStdout string
23 wantStderr string
24 wantFileContents string
25 }{
26 {
27 name: "Select a codespace",
28 arg: CODESPACE_NAME,
29 wantErr: false,
30 wantStdout: fmt.Sprintf("%s\n", CODESPACE_NAME),
31 },
32 {
33 name: "Select a codespace error",
34 arg: "non-existent-codespace-name",
35 wantErr: true,
36 },
37 {
38 name: "Select a codespace",
39 arg: CODESPACE_NAME,
40 wantErr: false,
41 wantFileContents: CODESPACE_NAME,
42 outputToFile: true,
43 },
44 }
45 for _, tt := range tests {
46 t.Run(tt.name, func(t *testing.T) {
47 ios, _, stdout, stderr := iostreams.Test()
48 ios.SetStdinTTY(true)
49 ios.SetStdoutTTY(true)
50 a := NewApp(ios, nil, testSelectApiMock(), nil, nil)
51
52 opts := selectOptions{}
53
54 if tt.outputToFile {
55 file, err := os.CreateTemp("", "codespace-selection-test")
56 if err != nil {
57 t.Fatal(err)
58 }
59
60 defer os.Remove(file.Name())
61
62 opts = selectOptions{filePath: file.Name()}
63 }
64
65 opts.selector = &CodespaceSelector{api: a.apiClient, codespaceName: tt.arg}
66
67 if err := a.Select(context.Background(), opts); (err != nil) != tt.wantErr {
68 t.Errorf("App.Select() error = %v, wantErr %v", err, tt.wantErr)
69 }
70
71 if out := stdout.String(); out != tt.wantStdout {
72 t.Errorf("stdout = %q, want %q", out, tt.wantStdout)
73 }

Callers

nothing calls this directly

Calls 12

SelectMethod · 0.95
TestFunction · 0.92
NewAppFunction · 0.85
testSelectApiMockFunction · 0.85
sortLinesFunction · 0.85
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
RunMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected