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

Function TestValidateImageCommand_RunE

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

Source from the content-addressed store, hash-verified

1265}
1266
1267func TestValidateImageCommand_RunE(t *testing.T) {
1268 validateImageCmd := validateImageCmd(happyValidator())
1269 cmd := setUpCobra(validateImageCmd)
1270
1271 ctx := utils.WithFS(context.Background(), afero.NewMemMapFs())
1272 client := fake.FakeClient{}
1273 commonMockClient(&client)
1274 ctx = oci.WithClient(ctx, &client)
1275 cmd.SetContext(ctx)
1276
1277 effectiveTimeTest := time.Now().UTC().Format(time.RFC3339Nano)
1278
1279 cmd.SetArgs(append(rootArgs, []string{
1280 "--image",
1281 "registry/image:tag",
1282 "--policy",
1283 fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON),
1284 "--effective-time",
1285 effectiveTimeTest,
1286 }...))
1287
1288 var out bytes.Buffer
1289 cmd.SetOut(&out)
1290
1291 utils.SetTestRekorPublicKey(t)
1292
1293 err := cmd.Execute()
1294 assert.NoError(t, err)
1295 assert.JSONEq(t, fmt.Sprintf(`{
1296 "success": true,
1297 "ec-version": "development",
1298 "effective-time": %q,
1299 "key": %s,
1300 "components": [
1301 {
1302 "name": "Unnamed",
1303 "containerImage": "registry/image:tag",
1304 "source": {},
1305 "success": true
1306 }
1307 ],
1308 "policy": {
1309 "publicKey": %s
1310 }
1311 }`, effectiveTimeTest, utils.TestPublicKeyJSON, utils.TestPublicKeyJSON), out.String())
1312}
1313
1314func TestValidateImageDefaultOutput(t *testing.T) {
1315 commonArgs := []string{

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