github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/e2e/relocation_test.go (about) 1 package e2e 2 3 import ( 4 "os" 5 "path/filepath" 6 "strings" 7 "testing" 8 9 "github.com/docker/app/internal/image" 10 "gotest.tools/assert/cmp" 11 12 "gotest.tools/assert" 13 "gotest.tools/icmd" 14 ) 15 16 func TestRelocationMapRun(t *testing.T) { 17 runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) { 18 cmd := info.configuredCmd 19 cfg := getDockerConfigDir(t, cmd) 20 21 path := filepath.Join("testdata", "local") 22 ref := info.registryAddress + "/test/local:a-tag" 23 bundlePath := filepath.Join(cfg, "app", "bundles", strings.Replace(info.registryAddress, ":", "_", 1), "test", "local", "_tags", "a-tag") 24 25 // Given a pushed application 26 build(t, cmd, dockerCli, ref, path) 27 cmd.Command = dockerCli.Command("app", "push", ref) 28 icmd.RunCmd(cmd).Assert(t, icmd.Success) 29 // And given application files are remove 30 assert.NilError(t, os.RemoveAll(bundlePath)) 31 _, err := os.Stat(filepath.Join(bundlePath, image.BundleFilename)) 32 assert.Assert(t, os.IsNotExist(err)) 33 // And given local images are removed 34 cmd.Command = dockerCli.Command("rmi", "web", "local:1.1.0-beta1-invoc", "worker") 35 icmd.RunCmd(cmd).Assert(t, icmd.Success) 36 // And given application is pulled from the registry 37 cmd.Command = dockerCli.Command("app", "pull", ref) 38 icmd.RunCmd(cmd).Assert(t, icmd.Success) 39 40 t.Run("with-relocation-map", func(t *testing.T) { 41 name := "test-relocation-map-run-with-relocation-map" 42 // When application is run 43 cmd.Command = dockerCli.Command("app", "run", "--name", name, ref) 44 icmd.RunCmd(cmd).Assert(t, icmd.Success) 45 46 // Then the application is running 47 cmd.Command = dockerCli.Command("app", "ls") 48 assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), name)) 49 50 cmd.Command = dockerCli.Command("app", "rm", name) 51 icmd.RunCmd(cmd).Assert(t, icmd.Success) 52 }) 53 54 t.Run("without-relocation-map", func(t *testing.T) { 55 name := "test-relocation-map-run-without-relocation-map" 56 // And given the relocation map is removed after the pull 57 assert.NilError(t, filepath.Walk(filepath.Join(cfg, "app", "bundles", "contents"), func(path string, info os.FileInfo, err error) error { 58 if info.Name() == image.RelocationMapFilename { 59 os.Remove(path) 60 } 61 return nil 62 })) 63 64 // Then the application cannot be run 65 cmd.Command = dockerCli.Command("app", "run", "--name", name, ref) 66 icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 1}) 67 }) 68 }) 69 } 70 71 func TestPushPulledApplication(t *testing.T) { 72 runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) { 73 cmd := info.configuredCmd 74 cfg := getDockerConfigDir(t, cmd) 75 76 path := filepath.Join("testdata", "local") 77 ref := info.registryAddress + "/test/local:a-tag" 78 79 // Given an application pushed on a registry 80 build(t, cmd, dockerCli, ref, path) 81 cmd.Command = dockerCli.Command("app", "push", ref) 82 icmd.RunCmd(cmd).Assert(t, icmd.Success) 83 // And given local images are removed 84 assert.NilError(t, os.RemoveAll(filepath.Join(cfg, "app", "bundles"))) 85 86 // And given application is pulled from the registry 87 cmd.Command = dockerCli.Command("app", "pull", ref) 88 icmd.RunCmd(cmd).Assert(t, icmd.Success) 89 90 // Then the application can still be pushed 91 cmd.Command = dockerCli.Command("app", "push", ref) 92 icmd.RunCmd(cmd).Assert(t, icmd.Success) 93 }) 94 } 95 96 func TestRelocationMapOnInspect(t *testing.T) { 97 runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) { 98 cmd := info.configuredCmd 99 cfg := getDockerConfigDir(t, cmd) 100 101 path := filepath.Join("testdata", "local") 102 ref := info.registryAddress + "/test/local:a-tag" 103 bundlePath := filepath.Join(cfg, "app", "bundles", strings.Replace(info.registryAddress, ":", "_", 1), "test", "local", "_tags", "a-tag") 104 105 // Given a pushed application 106 build(t, cmd, dockerCli, ref, path) 107 cmd.Command = dockerCli.Command("app", "push", ref) 108 icmd.RunCmd(cmd).Assert(t, icmd.Success) 109 // And given application files are remove 110 assert.NilError(t, os.RemoveAll(bundlePath)) 111 _, err := os.Stat(filepath.Join(bundlePath, image.BundleFilename)) 112 assert.Assert(t, os.IsNotExist(err)) 113 // And given local images are removed 114 cmd.Command = dockerCli.Command("rmi", "web", "local:1.1.0-beta1-invoc", "worker") 115 icmd.RunCmd(cmd).Assert(t, icmd.Success) 116 // And given application is pulled from the registry 117 cmd.Command = dockerCli.Command("app", "pull", ref) 118 icmd.RunCmd(cmd).Assert(t, icmd.Success) 119 120 // When inspect the image 121 cmd.Command = dockerCli.Command("app", "image", "inspect", ref) 122 icmd.RunCmd(cmd).Assert(t, icmd.Success) 123 }) 124 }