@@ -59,3 +59,57 @@ func TestStripTags(t *testing.T) {
59
59
})
60
60
}
61
61
}
62
+
63
+ func TestSetImageTag (t * testing.T ) {
64
+ tests := []struct {
65
+ description string
66
+ image string
67
+ tag string
68
+ expectedImage string
69
+ shouldErr bool
70
+ }{
71
+ {
72
+ description : "image with tag" ,
73
+ image : "gcr.io/foo/bar:latest" ,
74
+ tag : "test-1" ,
75
+ expectedImage : "gcr.io/foo/bar:test-1" ,
76
+ },
77
+ {
78
+ description : "image with tag and digest" ,
79
+ image : "gcr.io/foo/bar:latest@sha256:79e160161fd8190acae2d04d8f296a27a562c8a59732c64ac71c99009a6e89bc" ,
80
+ tag : "test-2" ,
81
+ expectedImage : "gcr.io/foo/bar:test-2@sha256:79e160161fd8190acae2d04d8f296a27a562c8a59732c64ac71c99009a6e89bc" ,
82
+ },
83
+ {
84
+ description : "image without tag and digest" ,
85
+ image : "gcr.io/foo/bar" ,
86
+ tag : "test-3" ,
87
+ expectedImage : "gcr.io/foo/bar:test-3" ,
88
+ },
89
+ {
90
+ description : "empty tag" ,
91
+ image : "gcr.io/foo/bar:test-4" ,
92
+ expectedImage : "gcr.io/foo/bar" ,
93
+ },
94
+ {
95
+ description : "image with digest" ,
96
+ image : "gcr.io/foo/bar@sha256:79e160161fd8190acae2d04d8f296a27a562c8a59732c64ac71c99009a6e89bc" ,
97
+ tag : "test-5" ,
98
+ expectedImage : "gcr.io/foo/bar:test-5@sha256:79e160161fd8190acae2d04d8f296a27a562c8a59732c64ac71c99009a6e89bc" ,
99
+ },
100
+ {
101
+ description : "invalid reference" ,
102
+ image : "!!invalid!!" ,
103
+ shouldErr : true ,
104
+ },
105
+ }
106
+
107
+ for _ , test := range tests {
108
+ testutil .Run (t , test .description , func (t * testutil.T ) {
109
+ t .Parallel ()
110
+
111
+ image , err := SetImageTag (test .image , test .tag )
112
+ t .CheckErrorAndDeepEqual (test .shouldErr , err , test .expectedImage , image )
113
+ })
114
+ }
115
+ }
0 commit comments