(t *testing.T)
| 212 | } |
| 213 | |
| 214 | func Test_ValidateInputCmd_NonStrictMode(t *testing.T) { |
| 215 | fs := afero.NewMemMapFs() |
| 216 | require.NoError(t, afero.WriteFile(fs, "/file.yaml", []byte("some: data"), 0o644)) |
| 217 | |
| 218 | // Mock validator: returns no error but a violation (should not cause non-zero exit in non-strict mode). |
| 219 | outMock := &output.Output{ |
| 220 | PolicyCheck: []evaluator.Outcome{ |
| 221 | { |
| 222 | Failures: []evaluator.Result{ |
| 223 | {Message: "Some violation"}, |
| 224 | }, |
| 225 | }, |
| 226 | }, |
| 227 | } |
| 228 | |
| 229 | cmd, _ := setUpValidateInputCmd(mockValidate(outMock, nil), fs) |
| 230 | cmd.SetArgs([]string{ |
| 231 | "input", |
| 232 | "--file", "/file.yaml", |
| 233 | "--policy", `{"publicKey": "testkey"}`, |
| 234 | "--strict", "false", |
| 235 | }) |
| 236 | |
| 237 | utils.SetTestRekorPublicKey(t) |
| 238 | |
| 239 | // Capture output for assertions |
| 240 | outputBuffer := &bytes.Buffer{} |
| 241 | cmd.SetOut(outputBuffer) |
| 242 | cmd.SetErr(outputBuffer) |
| 243 | |
| 244 | // Execute the command |
| 245 | err := cmd.Execute() |
| 246 | |
| 247 | // Ensure no error is returned in non-strict mode |
| 248 | assert.Error(t, err) |
| 249 | |
| 250 | // Check that the output mentions violations, but the command succeeds |
| 251 | output := outputBuffer.String() |
| 252 | assert.Contains(t, output, "Some violation") |
| 253 | assert.Contains(t, output, "success criteria not met") |
| 254 | } |
| 255 | |
| 256 | func Test_ValidateInputCmd_NoPolicyProvided(t *testing.T) { |
| 257 | fs := afero.NewMemMapFs() |
nothing calls this directly
no test coverage detected