github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/image_convert_linux_test.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "testing" 22 23 "github.com/containerd/nerdctl/pkg/rootlessutil" 24 "github.com/containerd/nerdctl/pkg/testutil" 25 "github.com/containerd/nerdctl/pkg/testutil/testregistry" 26 "gotest.tools/v3/icmd" 27 ) 28 29 func TestImageConvertNydus(t *testing.T) { 30 testutil.RequireExecutable(t, "nydus-image") 31 testutil.DockerIncompatible(t) 32 base := testutil.NewBase(t) 33 convertedImage := testutil.Identifier(t) + ":nydus" 34 base.Cmd("rmi", convertedImage).Run() 35 base.Cmd("pull", testutil.CommonImage).AssertOK() 36 base.Cmd("image", "convert", "--nydus", "--oci", 37 testutil.CommonImage, convertedImage).AssertOK() 38 defer base.Cmd("rmi", convertedImage).Run() 39 40 // use `nydusify` check whether the convertd nydus image is valid 41 42 // skip if rootless 43 if rootlessutil.IsRootless() { 44 t.Skip("Nydusify check is not supported rootless mode.") 45 } 46 47 // skip if nydusify is not installed 48 testutil.RequireExecutable(t, "nydusify") 49 50 // setup local docker registry 51 registryPort := 15000 52 registry := testregistry.NewPlainHTTP(base, registryPort) 53 defer registry.Cleanup() 54 55 remoteImage := fmt.Sprintf("%s:%d/nydusd-image:test", registry.IP.String(), registryPort) 56 base.Cmd("tag", convertedImage, remoteImage).AssertOK() 57 defer base.Cmd("rmi", remoteImage).Run() 58 base.Cmd("push", "--insecure-registry", remoteImage).AssertOK() 59 nydusifyCmd := testutil.Cmd{ 60 Cmd: icmd.Command( 61 "nydusify", 62 "check", 63 "--source", 64 testutil.CommonImage, 65 "--target", 66 remoteImage, 67 "--source-insecure", 68 "--target-insecure", 69 ), 70 Base: base, 71 } 72 nydusifyCmd.AssertOK() 73 }