github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/push/symlink_resources_test.go (about) 1 package push 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 9 "code.cloudfoundry.org/cli/integration/helpers" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("push with symlinked resources", func() { 17 var ( 18 appName string 19 ) 20 21 BeforeEach(func() { 22 helpers.SkipIfVersionLessThan(ccversion.MinVersionSymlinkedFilesV2) 23 appName = helpers.NewAppName() 24 }) 25 26 When("pushing a directory", func() { 27 When("the directory contains a symlink to a file in the directory", func() { 28 When("the file exists", func() { 29 It("should push the symlink", func() { 30 helpers.WithHelloWorldApp(func(dir string) { 31 targetFile := filepath.Join(dir, "targetFile") 32 Expect(ioutil.WriteFile(targetFile, []byte("foo bar baz"), 0777)).ToNot(HaveOccurred()) 33 relativePath, err := filepath.Rel(dir, targetFile) 34 Expect(err).ToNot(HaveOccurred()) 35 36 err = os.Symlink(relativePath, filepath.Join(dir, "symlinkFile")) 37 Expect(err).ToNot(HaveOccurred()) 38 39 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 40 41 Eventually(session).Should(Exit(0)) 42 }) 43 44 helpers.VerifyAppPackageContentsV2(appName, "symlinkFile", "targetFile", "Staticfile", "index.html") 45 }) 46 }) 47 48 When("the file doesn't exists", func() { 49 It("should push the symlink", func() { 50 helpers.WithHelloWorldApp(func(dir string) { 51 tempFile, err := ioutil.TempFile(dir, "tempFile") 52 Expect(err).ToNot(HaveOccurred()) 53 tempFile.Close() 54 relativePath, err := filepath.Rel(dir, tempFile.Name()) 55 Expect(err).ToNot(HaveOccurred()) 56 57 err = os.Symlink(relativePath, filepath.Join(dir, "symlinkFile")) 58 Expect(err).ToNot(HaveOccurred()) 59 Expect(os.Remove(tempFile.Name())) 60 61 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 62 63 Eventually(session).Should(Exit(0)) 64 }) 65 66 helpers.VerifyAppPackageContentsV2(appName, "symlinkFile", "Staticfile", "index.html") 67 }) 68 }) 69 }) 70 71 When("the directory contains a symlink to subdirectory in the directory", func() { 72 It("should push the symlink", func() { 73 helpers.WithHelloWorldApp(func(dir string) { 74 targetDir, err := ioutil.TempDir(dir, "target-dir") 75 Expect(err).ToNot(HaveOccurred()) 76 relativePath, err := filepath.Rel(dir, targetDir) 77 Expect(err).ToNot(HaveOccurred()) 78 79 err = os.Symlink(relativePath, filepath.Join(dir, "symlinkFile")) 80 Expect(err).ToNot(HaveOccurred()) 81 Expect(os.RemoveAll(targetDir)).ToNot(HaveOccurred()) 82 83 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 84 85 Eventually(session).Should(Exit(0)) 86 }) 87 88 helpers.VerifyAppPackageContentsV2(appName, "symlinkFile", "Staticfile", "index.html") 89 }) 90 }) 91 }) 92 93 When("pushing an archive", func() { 94 var archive string 95 96 AfterEach(func() { 97 Expect(os.RemoveAll(archive)).ToNot(HaveOccurred()) 98 }) 99 100 When("the archive contains a symlink to a file in the directory", func() { 101 BeforeEach(func() { 102 helpers.WithHelloWorldApp(func(appDir string) { 103 helpers.WithHelloWorldApp(func(appDir string) { 104 tmpfile, err := ioutil.TempFile("", "push-archive-integration") 105 Expect(err).ToNot(HaveOccurred()) 106 archive = tmpfile.Name() 107 Expect(tmpfile.Close()).ToNot(HaveOccurred()) 108 109 targetFile := filepath.Join(appDir, "targetFile") 110 Expect(ioutil.WriteFile(targetFile, []byte("some random data"), 0777)).ToNot(HaveOccurred()) 111 relativePath, err := filepath.Rel(appDir, targetFile) 112 Expect(err).ToNot(HaveOccurred()) 113 114 err = os.Symlink(relativePath, filepath.Join(appDir, "symlinkFile")) 115 Expect(err).ToNot(HaveOccurred()) 116 117 err = helpers.Zipit(appDir, archive, "") 118 Expect(err).ToNot(HaveOccurred()) 119 }) 120 }) 121 }) 122 123 It("should push the symlink", func() { 124 session := helpers.CF(PushCommandName, appName, "--no-start", "-p", archive) 125 126 Eventually(session).Should(Exit(0)) 127 helpers.VerifyAppPackageContentsV2(appName, "symlinkFile", "targetFile", "Staticfile", "index.html") 128 }) 129 }) 130 }) 131 })