-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdigest_test.go
More file actions
78 lines (75 loc) · 2.05 KB
/
digest_test.go
File metadata and controls
78 lines (75 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ociutil
import (
"testing"
)
func TestExtractDigest(t *testing.T) {
tests := []struct {
name string
imageID string
expected string
}{
{
name: "empty string",
imageID: "",
expected: "",
},
{
name: "docker-pullable format",
imageID: "docker-pullable://nginx@sha256:abc123def456",
expected: "sha256:abc123def456",
},
{
name: "docker format",
imageID: "docker://sha256:abc123def456789",
expected: "sha256:abc123def456789",
},
{
name: "just sha256 digest",
imageID: "sha256:0123456789abcdef",
expected: "sha256:0123456789abcdef",
},
{
name: "full gcr image with digest",
imageID: "docker-pullable://gcr.io/my-project/my-image@sha256:fedcba9876543210",
expected: "sha256:fedcba9876543210",
},
{
name: "registry with port and digest",
imageID: "docker-pullable://localhost:5000/myapp@sha256:1234567890abcdef",
expected: "sha256:1234567890abcdef",
},
{
name: "no sha256 prefix returns original",
imageID: "some-random-id-without-sha",
expected: "some-random-id-without-sha",
},
{
name: "digest with trailing space",
imageID: "docker://sha256:abc123 extra",
expected: "sha256:abc123",
},
{
name: "digest with trailing @",
imageID: "sha256:abc123@extra",
expected: "sha256:abc123",
},
{
name: "real world kubernetes imageID",
imageID: "docker-pullable://ghcr.io/github/deployment-tracker@sha256:a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
expected: "sha256:a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
},
{
name: "containerd format",
imageID: "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
expected: "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := ExtractDigest(tt.imageID)
if result != tt.expected {
t.Errorf("ExtractDigest(%q) = %q, want %q", tt.imageID, result, tt.expected)
}
})
}
}