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