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

Function TestNewCmdView

pkg/cmd/repo/license/view/view_test.go:19–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestNewCmdView(t *testing.T) {
20 tests := []struct {
21 name string
22 args []string
23 wantErr bool
24 wantOpts *ViewOptions
25 tty bool
26 }{
27 {
28 name: "No license key or SPDX ID provided",
29 args: []string{},
30 wantErr: true,
31 wantOpts: &ViewOptions{
32 License: "",
33 },
34 },
35 {
36 name: "Happy path single license key",
37 args: []string{"mit"},
38 wantErr: false,
39 wantOpts: &ViewOptions{
40 License: "mit",
41 },
42 },
43 {
44 name: "Happy path too many license keys",
45 args: []string{"mit", "apache-2.0"},
46 wantErr: true,
47 wantOpts: &ViewOptions{
48 License: "",
49 },
50 },
51 }
52 for _, tt := range tests {
53 t.Run(tt.name, func(t *testing.T) {
54 ios, _, _, _ := iostreams.Test()
55 ios.SetStdinTTY(tt.tty)
56 ios.SetStdoutTTY(tt.tty)
57 ios.SetStderrTTY(tt.tty)
58
59 f := &cmdutil.Factory{
60 IOStreams: ios,
61 }
62 cmd := NewCmdView(f, func(*ViewOptions) error {
63 return nil
64 })
65 cmd.SetArgs(tt.args)
66 cmd.SetIn(&bytes.Buffer{})
67 cmd.SetOut(&bytes.Buffer{})
68 cmd.SetErr(&bytes.Buffer{})
69
70 _, err := cmd.ExecuteC()
71 if tt.wantErr {
72 assert.Error(t, err)
73 } else {
74 require.NoError(t, err)
75 }
76

Callers

nothing calls this directly

Calls 8

TestFunction · 0.92
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
NewCmdViewFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected