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

Function TestShortenImageDigest

cmd/validate/vsa_test.go:1587–1636  ·  view source on GitHub ↗

TestShortenImageDigest tests the shortenImageDigest helper function

(t *testing.T)

Source from the content-addressed store, hash-verified

1585
1586// TestShortenImageDigest tests the shortenImageDigest helper function
1587func TestShortenImageDigest(t *testing.T) {
1588 tests := []struct {
1589 name string
1590 imageRef string
1591 expected string
1592 }{
1593 {
1594 name: "image with sha256 digest",
1595 imageRef: "registry.com/repo@sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
1596 expected: "abcdef12",
1597 },
1598 {
1599 name: "image with short digest",
1600 imageRef: "registry.com/repo@sha256:abc123",
1601 expected: "abc123",
1602 },
1603 {
1604 name: "image with digest without sha256 prefix",
1605 imageRef: "registry.com/repo@abcdef1234567890",
1606 expected: "abcdef12",
1607 },
1608 {
1609 name: "image without digest, long ref",
1610 imageRef: "registry.com/very/long/repository/path/image:tag",
1611 expected: "…mage:tag", // Last 8 characters
1612 },
1613 {
1614 name: "image without digest, short ref",
1615 imageRef: "image:tag",
1616 expected: "…mage:tag", // 9 chars, so last 8 with ellipsis
1617 },
1618 {
1619 name: "image ref with exactly 8 chars",
1620 imageRef: "img:tag",
1621 expected: "img:tag",
1622 },
1623 {
1624 name: "empty string",
1625 imageRef: "",
1626 expected: "",
1627 },
1628 }
1629
1630 for _, tt := range tests {
1631 t.Run(tt.name, func(t *testing.T) {
1632 result := shortenImageDigest(tt.imageRef)
1633 assert.Equal(t, tt.expected, result)
1634 })
1635 }
1636}
1637
1638// TestExtractFallbackReason tests the extractFallbackReason helper function
1639func TestExtractFallbackReason(t *testing.T) {

Callers

nothing calls this directly

Calls 2

shortenImageDigestFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected