(t *testing.T)
| 123 | } |
| 124 | |
| 125 | func TestNewCmdView(t *testing.T) { |
| 126 | tests := []struct { |
| 127 | name string |
| 128 | args []string |
| 129 | wantErr bool |
| 130 | wantOpts *ViewOptions |
| 131 | tty bool |
| 132 | }{ |
| 133 | { |
| 134 | name: "No template", |
| 135 | args: []string{}, |
| 136 | wantErr: true, |
| 137 | wantOpts: &ViewOptions{ |
| 138 | Template: "", |
| 139 | }, |
| 140 | }, |
| 141 | { |
| 142 | name: "Happy path single template", |
| 143 | args: []string{"Go"}, |
| 144 | wantErr: false, |
| 145 | wantOpts: &ViewOptions{ |
| 146 | Template: "Go", |
| 147 | }, |
| 148 | }, |
| 149 | { |
| 150 | name: "Happy path too many templates", |
| 151 | args: []string{"Go", "Ruby"}, |
| 152 | wantErr: true, |
| 153 | wantOpts: &ViewOptions{ |
| 154 | Template: "", |
| 155 | }, |
| 156 | }, |
| 157 | } |
| 158 | for _, tt := range tests { |
| 159 | t.Run(tt.name, func(t *testing.T) { |
| 160 | ios, _, _, _ := iostreams.Test() |
| 161 | ios.SetStdinTTY(tt.tty) |
| 162 | ios.SetStdoutTTY(tt.tty) |
| 163 | ios.SetStderrTTY(tt.tty) |
| 164 | |
| 165 | f := &cmdutil.Factory{ |
| 166 | IOStreams: ios, |
| 167 | } |
| 168 | cmd := NewCmdView(f, func(*ViewOptions) error { |
| 169 | return nil |
| 170 | }) |
| 171 | cmd.SetArgs(tt.args) |
| 172 | cmd.SetIn(&bytes.Buffer{}) |
| 173 | cmd.SetOut(&bytes.Buffer{}) |
| 174 | cmd.SetErr(&bytes.Buffer{}) |
| 175 | |
| 176 | _, err := cmd.ExecuteC() |
| 177 | if tt.wantErr { |
| 178 | assert.Error(t, err) |
| 179 | } else { |
| 180 | require.NoError(t, err) |
| 181 | } |
| 182 |
nothing calls this directly
no test coverage detected