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

Function TestExtractDigestFromImageRef

internal/validate/vsa/vsa_test.go:1372–1422  ·  view source on GitHub ↗

TestExtractDigestFromImageRef tests the ExtractDigestFromImageRef function

(t *testing.T)

Source from the content-addressed store, hash-verified

1370
1371// TestExtractDigestFromImageRef tests the ExtractDigestFromImageRef function
1372func 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}

Callers

nothing calls this directly

Calls 3

RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected