TestExtractDigestFromImageRef tests the ExtractDigestFromImageRef function
(t *testing.T)
| 1370 | |
| 1371 | // TestExtractDigestFromImageRef tests the ExtractDigestFromImageRef function |
| 1372 | func TestExtractDigestFromImageRef(t *testing.T) { |
| 1373 | tests := []struct { |
| 1374 | name string |
| 1375 | imageRef string |
| 1376 | expected string |
| 1377 | expectError bool |
| 1378 | }{ |
| 1379 | { |
| 1380 | name: "tag reference", |
| 1381 | imageRef: "registry.io/image:latest", |
| 1382 | expected: "registry.io/image:latest", |
| 1383 | expectError: false, |
| 1384 | }, |
| 1385 | { |
| 1386 | name: "docker hub tag", |
| 1387 | imageRef: "nginx:1.21", |
| 1388 | expected: "nginx:1.21", |
| 1389 | expectError: false, |
| 1390 | }, |
| 1391 | { |
| 1392 | name: "quay reference", |
| 1393 | imageRef: "quay.io/namespace/repo:tag", |
| 1394 | expected: "quay.io/namespace/repo:tag", |
| 1395 | expectError: false, |
| 1396 | }, |
| 1397 | { |
| 1398 | name: "invalid reference", |
| 1399 | imageRef: "invalid:reference:with:colons", |
| 1400 | expected: "", |
| 1401 | expectError: true, |
| 1402 | }, |
| 1403 | { |
| 1404 | name: "empty reference", |
| 1405 | imageRef: "", |
| 1406 | expected: "", |
| 1407 | expectError: true, |
| 1408 | }, |
| 1409 | } |
| 1410 | |
| 1411 | for _, tt := range tests { |
| 1412 | t.Run(tt.name, func(t *testing.T) { |
| 1413 | result, err := ExtractDigestFromImageRef(tt.imageRef) |
| 1414 | if tt.expectError { |
| 1415 | require.Error(t, err) |
| 1416 | } else { |
| 1417 | require.NoError(t, err) |
| 1418 | assert.Equal(t, tt.expected, result) |
| 1419 | } |
| 1420 | }) |
| 1421 | } |
| 1422 | } |
nothing calls this directly
no test coverage detected