@@ -146,6 +146,24 @@ func TestConvert(t *testing.T) {
146146 convertedRef := imgRef + "-soci"
147147
148148 sh .X ("nerdctl" , "pull" , "--all-platforms" , imgRef )
149+ sh .X ("soci" , "convert" , "--all-platforms" , "--min-layer-size" , "0" , imgRef , convertedRef )
150+
151+ imgDigest := getImageDigest (sh , imgRef )
152+ convertedDigest := getImageDigest (sh , convertedRef )
153+
154+ validateConversion (t , sh , imgDigest , convertedDigest )
155+ })
156+ }
157+ })
158+
159+ t .Run ("single platform conversion" , func (t * testing.T ) {
160+ for _ , imageName := range convertImages {
161+ t .Run (imageName , func (t * testing.T ) {
162+ rebootContainerd (t , sh , "" , "" )
163+ imgRef := dockerhub (imageName ).ref
164+ convertedRef := imgRef + "-soci"
165+
166+ sh .X ("nerdctl" , "pull" , imgRef )
149167 sh .X ("soci" , "convert" , "--min-layer-size" , "0" , imgRef , convertedRef )
150168
151169 imgDigest := getImageDigest (sh , imgRef )
@@ -165,8 +183,8 @@ func TestConvert(t *testing.T) {
165183 convertedRef2 := imgRef + "-soci-2"
166184
167185 sh .X ("nerdctl" , "pull" , "--all-platforms" , imgRef )
168- sh .X ("soci" , "convert" , imgRef , convertedRef1 )
169- sh .X ("soci" , "convert" , convertedRef1 , convertedRef2 )
186+ sh .X ("soci" , "convert" , "--all-platforms" , imgRef , convertedRef1 )
187+ sh .X ("soci" , "convert" , "--all-platforms" , convertedRef1 , convertedRef2 )
170188
171189 convertedDigest1 := getImageDigest (sh , convertedRef1 )
172190 convertedDigest2 := getImageDigest (sh , convertedRef2 )
@@ -177,7 +195,7 @@ func TestConvert(t *testing.T) {
177195 }
178196 })
179197
180- t .Run ("single platform conversion" , func (t * testing.T ) {
198+ t .Run ("single image manifest conversion" , func (t * testing.T ) {
181199 images := []string {cloudwatchAgentx86ImageRef }
182200 for _ , imgRef := range images {
183201 t .Run (imgRef , func (t * testing.T ) {
@@ -215,21 +233,89 @@ func TestConvert(t *testing.T) {
215233
216234}
217235
236+ type convertAndPushTestConfig struct {
237+ PullPlatforms string
238+ ConvertPlatforms string
239+ PushPlatforms string
240+ }
241+
242+ func (c convertAndPushTestConfig ) String () string {
243+ return strings .Join ([]string {c .PullPlatforms , c .ConvertPlatforms , c .PushPlatforms }, "," )
244+ }
245+
218246func TestConvertAndPush (t * testing.T ) {
219247 registryConfig := newRegistryConfig ()
220248 sh , done := newShellWithRegistry (t , registryConfig )
221249 defer done ()
222- for _ , imageName := range convertImages {
223- t .Run (imageName , func (t * testing.T ) {
224- rebootContainerd (t , sh , "" , "" )
225- img := dockerhub (imageName )
226- convertedImg := registryConfig .mirror (imageName )
227250
228- sh .X ("nerdctl" , "pull" , "--all-platforms" , img .ref )
229- sh .X ("soci" , "convert" , img .ref , convertedImg .ref )
230- sh .X ("nerdctl" , "login" , "--username" , registryConfig .user , "--password" , registryConfig .pass , convertedImg .ref )
231- sh .X ("nerdctl" , "push" , "--all-platforms" , convertedImg .ref )
232- })
251+ imageName := nginxImage
252+
253+ platformOptions := map [string ][]string {
254+ "one" : {"--platform" , "linux/x86_64" },
255+ "all" : {"--all-platforms" },
256+ }
257+
258+ convertFailureMessages := map [convertAndPushTestConfig ]string {
259+ // Any config not in this list should succeed on convert (no error message)
260+ {PullPlatforms : "one" , ConvertPlatforms : "all" , PushPlatforms : "one" }: "not found" ,
261+ {PullPlatforms : "one" , ConvertPlatforms : "all" , PushPlatforms : "all" }: "not found" ,
262+ }
263+
264+ pushFailureMessages := map [convertAndPushTestConfig ]string {
265+ // Any config not in this list should succeed on push (no error message)
266+ {PullPlatforms : "one" , ConvertPlatforms : "one" , PushPlatforms : "all" }: "not found" ,
267+ }
268+
269+ for pullPlatform := range platformOptions {
270+ for convertPlatform := range platformOptions {
271+ for pushPlatform := range platformOptions {
272+ test := convertAndPushTestConfig {
273+ PullPlatforms : pullPlatform ,
274+ ConvertPlatforms : convertPlatform ,
275+ PushPlatforms : pushPlatform ,
276+ }
277+
278+ t .Run (test .String (), func (t * testing.T ) {
279+ rebootContainerd (t , sh , "" , "" )
280+ img := dockerhub (imageName )
281+ convertedImg := registryConfig .mirror (imageName )
282+
283+ pull := []string {"nerdctl" , "pull" }
284+ convert := []string {"soci" , "convert" }
285+ push := []string {"nerdctl" , "push" }
286+
287+ pull = append (pull , platformOptions [pullPlatform ]... )
288+ convert = append (convert , platformOptions [convertPlatform ]... )
289+ push = append (push , platformOptions [pushPlatform ]... )
290+
291+ convertFailureMessage , expectedConvertFailure := convertFailureMessages [test ]
292+ pushFailureMessage := pushFailureMessages [test ]
293+
294+ sh .X (append (pull , img .ref )... )
295+ o , err := sh .CombinedOLog (append (convert , img .ref , convertedImg .ref )... )
296+ validateErrorOutput (t , "convert" , string (o ), err , convertFailureMessage )
297+ if expectedConvertFailure {
298+ // If we expected a convert error and we got the correct one, then the test is done.
299+ // We should push because we know it will fail.
300+ return
301+ }
302+ sh .X ("nerdctl" , "login" , "--username" , registryConfig .user , "--password" , registryConfig .pass , convertedImg .ref )
303+ o , err = sh .CombinedOLog (append (push , convertedImg .ref )... )
304+ validateErrorOutput (t , "push" , string (o ), err , pushFailureMessage )
305+ })
306+
307+ }
308+ }
309+ }
310+ }
311+
312+ func validateErrorOutput (t * testing.T , name string , o string , err error , expectedError string ) {
313+ if expectedError != "" {
314+ if ! strings .Contains (o , expectedError ) {
315+ t .Fatalf ("%s: expected error %q, got %q" , name , expectedError , o )
316+ }
317+ } else if err != nil {
318+ t .Fatalf ("%s: unexpected error: %v" , name , err )
233319 }
234320}
235321
0 commit comments