(t *testing.T)
| 1312 | } |
| 1313 | |
| 1314 | func TestValidateImageDefaultOutput(t *testing.T) { |
| 1315 | commonArgs := []string{ |
| 1316 | "validate", |
| 1317 | "image", |
| 1318 | "--image", |
| 1319 | "registry/image:tag", |
| 1320 | "--policy", |
| 1321 | fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON), |
| 1322 | } |
| 1323 | |
| 1324 | commonOutput := hd.Doc(` |
| 1325 | Success: true |
| 1326 | Result: SUCCESS |
| 1327 | Violations: 0, Warnings: 0, Successes: 1 |
| 1328 | Component: Unnamed |
| 1329 | ImageRef: registry/image:tag |
| 1330 | |
| 1331 | `) |
| 1332 | |
| 1333 | cases := []struct { |
| 1334 | args []string |
| 1335 | expected string |
| 1336 | }{ |
| 1337 | { |
| 1338 | args: commonArgs, |
| 1339 | expected: commonOutput, |
| 1340 | }, |
| 1341 | { |
| 1342 | args: append(commonArgs, "--show-successes"), |
| 1343 | expected: fmt.Sprintf("%s%s", commonOutput, hd.Doc(` |
| 1344 | Results: |
| 1345 | ✓ [Success] policy.nice |
| 1346 | ImageRef: registry/image:tag |
| 1347 | Title: Very nice |
| 1348 | |
| 1349 | `)), |
| 1350 | }, |
| 1351 | { |
| 1352 | args: append(commonArgs, "--show-warnings"), |
| 1353 | expected: commonOutput, // No warnings in happyValidator, so no change |
| 1354 | }, |
| 1355 | { |
| 1356 | args: append(commonArgs, "--show-warnings=false"), |
| 1357 | expected: commonOutput, // No warnings in happyValidator, so no change |
| 1358 | }, |
| 1359 | } |
| 1360 | |
| 1361 | for _, c := range cases { |
| 1362 | validateImageCmd := validateImageCmd(happyValidator()) |
| 1363 | cmd := setUpCobra(validateImageCmd) |
| 1364 | |
| 1365 | ctx := utils.WithFS(context.Background(), afero.NewMemMapFs()) |
| 1366 | client := fake.FakeClient{} |
| 1367 | commonMockClient(&client) |
| 1368 | ctx = oci.WithClient(ctx, &client) |
| 1369 | cmd.SetContext(ctx) |
| 1370 | |
| 1371 | // Notice there is no --output flag here |
nothing calls this directly
no test coverage detected