github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/autoupdate/autoupdate_test.go (about) 1 package autoupdate 2 3 import ( 4 "testing" 5 ) 6 7 func TestValidateImageReference(t *testing.T) { 8 tests := []struct { 9 input string 10 valid bool 11 }{ 12 { // Fully-qualified reference 13 input: "quay.io/foo/bar:tag", 14 valid: true, 15 }, 16 { // Fully-qualified reference in transport notation 17 input: "docker://quay.io/foo/bar:tag", 18 valid: true, 19 }, 20 { // Fully-qualified reference but with digest 21 input: "quay.io/foo/bar@sha256:c9b1b535fdd91a9855fb7f82348177e5f019329a58c53c47272962dd60f71fc9", 22 valid: false, 23 }, 24 { // Reference with missing tag 25 input: "quay.io/foo/bar", 26 valid: false, 27 }, 28 { // Short name 29 input: "alpine", 30 valid: false, 31 }, 32 { // Short name with repo 33 input: "library/alpine", 34 valid: false, 35 }, 36 { // Wrong transport 37 input: "docker-archive:/some/path.tar", 38 valid: false, 39 }, 40 } 41 42 for _, test := range tests { 43 err := ValidateImageReference(test.input) 44 if test.valid && err != nil { 45 t.Fatalf("parsing %q should have succeeded: %v", test.input, err) 46 } else if !test.valid && err == nil { 47 t.Fatalf("parsing %q should have failed", test.input) 48 } 49 } 50 }