summaryrefslogtreecommitdiff
path: root/pkg/autoupdate/autoupdate_test.go
blob: 7a5da5bb049c4de603ed9a1a63b5670c18604d5f (plain)
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
package autoupdate

import (
	"testing"
)

func TestValidateImageReference(t *testing.T) {
	tests := []struct {
		input string
		valid bool
	}{
		{ // Fully-qualified reference
			input: "quay.io/foo/bar:tag",
			valid: true,
		},
		{ // Fully-qualified reference in transport notation
			input: "docker://quay.io/foo/bar:tag",
			valid: true,
		},
		{ // Fully-qualified reference but with digest
			input: "quay.io/foo/bar@sha256:c9b1b535fdd91a9855fb7f82348177e5f019329a58c53c47272962dd60f71fc9",
			valid: false,
		},
		{ // Reference with missing tag
			input: "quay.io/foo/bar",
			valid: false,
		},
		{ // Short name
			input: "alpine",
			valid: false,
		},
		{ // Short name with repo
			input: "library/alpine",
			valid: false,
		},
		{ // Wrong transport
			input: "docker-archive:/some/path.tar",
			valid: false,
		},
	}

	for _, test := range tests {
		err := ValidateImageReference(test.input)
		if test.valid && err != nil {
			t.Fatalf("parsing %q should have succeeded: %v", test.input, err)
		} else if !test.valid && err == nil {
			t.Fatalf("parsing %q should have failed", test.input)
		}
	}
}