(t *testing.T)
| 1265 | } |
| 1266 | |
| 1267 | func 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 | |
| 1314 | func TestValidateImageDefaultOutput(t *testing.T) { |
| 1315 | commonArgs := []string{ |
nothing calls this directly
no test coverage detected