TestValidateImageFallback tests the fallback validation functionality
(t *testing.T)
| 1257 | |
| 1258 | // TestValidateImageFallback tests the fallback validation functionality |
| 1259 | func TestValidateImageFallback(t *testing.T) { |
| 1260 | ctx := context.Background() |
| 1261 | |
| 1262 | data := &validateVSAData{ |
| 1263 | policyConfig: "test-policy.yaml", |
| 1264 | fallbackToImageValidation: true, |
| 1265 | } |
| 1266 | |
| 1267 | tests := []struct { |
| 1268 | name string |
| 1269 | imageRef string |
| 1270 | componentName string |
| 1271 | expectError bool |
| 1272 | }{ |
| 1273 | { |
| 1274 | name: "valid image reference", |
| 1275 | imageRef: "nginx:latest", |
| 1276 | componentName: "test-component", |
| 1277 | expectError: true, // Expected to fail due to missing policy files |
| 1278 | }, |
| 1279 | { |
| 1280 | name: "valid image reference with digest", |
| 1281 | imageRef: "nginx@sha256:abc123def456", |
| 1282 | componentName: "test-component", |
| 1283 | expectError: true, // Expected to fail due to missing policy files |
| 1284 | }, |
| 1285 | { |
| 1286 | name: "empty image reference", |
| 1287 | imageRef: "", |
| 1288 | componentName: "test-component", |
| 1289 | expectError: true, // Expected to fail due to missing policy files |
| 1290 | }, |
| 1291 | { |
| 1292 | name: "invalid image reference", |
| 1293 | imageRef: "invalid:image:reference:with:too:many:colons", |
| 1294 | componentName: "test-component", |
| 1295 | expectError: true, |
| 1296 | }, |
| 1297 | { |
| 1298 | name: "default component name", |
| 1299 | imageRef: "nginx:latest", |
| 1300 | componentName: "", |
| 1301 | expectError: true, // Expected to fail due to missing policy files |
| 1302 | }, |
| 1303 | } |
| 1304 | |
| 1305 | for _, tt := range tests { |
| 1306 | t.Run(tt.name, func(t *testing.T) { |
| 1307 | // Create component from test data |
| 1308 | componentName := tt.componentName |
| 1309 | if componentName == "" { |
| 1310 | componentName = "fallback-component" |
| 1311 | } |
| 1312 | comp := app.SnapshotComponent{ |
| 1313 | ContainerImage: tt.imageRef, |
| 1314 | Name: componentName, |
| 1315 | } |
| 1316 |
nothing calls this directly
no test coverage detected