(t *testing.T)
| 344 | } |
| 345 | |
| 346 | func Test_ValidateImageCommand(t *testing.T) { |
| 347 | validateImageCmd := validateImageCmd(happyValidator()) |
| 348 | cmd := setUpCobra(validateImageCmd) |
| 349 | |
| 350 | client := fake.FakeClient{} |
| 351 | commonMockClient(&client) |
| 352 | ctx := utils.WithFS(context.Background(), afero.NewMemMapFs()) |
| 353 | ctx = oci.WithClient(ctx, &client) |
| 354 | cmd.SetContext(ctx) |
| 355 | |
| 356 | effectiveTimeTest := time.Now().UTC().Format(time.RFC3339Nano) |
| 357 | |
| 358 | cmd.SetArgs(append(rootArgs, []string{ |
| 359 | "--image", |
| 360 | "registry/image:tag", |
| 361 | "--policy", |
| 362 | fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON), |
| 363 | "--effective-time", |
| 364 | effectiveTimeTest, |
| 365 | }...)) |
| 366 | |
| 367 | var out bytes.Buffer |
| 368 | cmd.SetOut(&out) |
| 369 | |
| 370 | utils.SetTestRekorPublicKey(t) |
| 371 | |
| 372 | err := cmd.Execute() |
| 373 | assert.NoError(t, err) |
| 374 | assert.JSONEq(t, fmt.Sprintf(`{ |
| 375 | "success": true, |
| 376 | "ec-version": "development", |
| 377 | "effective-time": %q, |
| 378 | "key": %s, |
| 379 | "components": [ |
| 380 | { |
| 381 | "name": "Unnamed", |
| 382 | "containerImage": "registry/image:tag", |
| 383 | "source": {}, |
| 384 | "success": true |
| 385 | } |
| 386 | ], |
| 387 | "policy": { |
| 388 | "publicKey": %s |
| 389 | } |
| 390 | }`, effectiveTimeTest, utils.TestPublicKeyJSON, utils.TestPublicKeyJSON), out.String()) |
| 391 | } |
| 392 | |
| 393 | func Test_ValidateImageCommandImages(t *testing.T) { |
| 394 | validateImageCmd := validateImageCmd(happyValidator()) |
nothing calls this directly
no test coverage detected