MCPcopy Create free account
hub / github.com/conforma/cli / Test_ValidateImageCommand

Function Test_ValidateImageCommand

cmd/validate/image_test.go:346–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

344}
345
346func 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
393func Test_ValidateImageCommandImages(t *testing.T) {
394 validateImageCmd := validateImageCmd(happyValidator())

Callers

nothing calls this directly

Calls 8

WithFSFunction · 0.92
WithClientFunction · 0.92
SetTestRekorPublicKeyFunction · 0.92
validateImageCmdFunction · 0.85
happyValidatorFunction · 0.85
commonMockClientFunction · 0.85
setUpCobraFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected