github.com/loafoe/cli@v7.1.0+incompatible/integration/v6/push/symlink_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  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("push with symlink path", func() {
    15  	var (
    16  		appName       string
    17  		runningDir    string
    18  		symlinkedPath string
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		appName = helpers.NewAppName()
    23  
    24  		var err error
    25  		runningDir, err = ioutil.TempDir("", "push-with-symlink")
    26  		Expect(err).ToNot(HaveOccurred())
    27  		symlinkedPath = filepath.Join(runningDir, "symlink-dir")
    28  	})
    29  
    30  	AfterEach(func() {
    31  		Expect(os.RemoveAll(runningDir)).To(Succeed())
    32  	})
    33  
    34  	Context("push with flag options", func() {
    35  		When("pushing from a symlinked current directory", func() {
    36  			It("should push with the absolute path of the app", func() {
    37  				helpers.WithHelloWorldApp(func(dir string) {
    38  					Expect(os.Symlink(dir, symlinkedPath)).ToNot(HaveOccurred())
    39  
    40  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: symlinkedPath}, PushCommandName, appName)
    41  					Eventually(session).Should(helpers.SayPath(`path:\s+%s`, dir))
    42  					Eventually(session).Should(Exit(0))
    43  				})
    44  			})
    45  		})
    46  
    47  		When("pushing a symlinked path with the '-p' flag", func() {
    48  			It("should push with the absolute path of the app", func() {
    49  				helpers.WithHelloWorldApp(func(dir string) {
    50  					Expect(os.Symlink(dir, symlinkedPath)).ToNot(HaveOccurred())
    51  
    52  					session := helpers.CF(PushCommandName, appName, "-p", symlinkedPath)
    53  					Eventually(session).Should(helpers.SayPath(`path:\s+%s`, dir))
    54  					Eventually(session).Should(Exit(0))
    55  				})
    56  			})
    57  		})
    58  
    59  		When("pushing an symlinked archive with the '-p' flag", func() {
    60  			var archive string
    61  
    62  			BeforeEach(func() {
    63  				helpers.WithHelloWorldApp(func(appDir string) {
    64  					tmpfile := helpers.TempFileAbsolutePath("", "push-archive-integration")
    65  					archive = tmpfile.Name()
    66  					Expect(tmpfile.Close()).ToNot(HaveOccurred())
    67  
    68  					err := helpers.Zipit(appDir, archive, "")
    69  					Expect(err).ToNot(HaveOccurred())
    70  				})
    71  			})
    72  
    73  			AfterEach(func() {
    74  				Expect(os.RemoveAll(archive)).ToNot(HaveOccurred())
    75  			})
    76  
    77  			It("should push with the absolute path of the archive", func() {
    78  				Expect(os.Symlink(archive, symlinkedPath)).ToNot(HaveOccurred())
    79  
    80  				session := helpers.CF(PushCommandName, appName, "-p", symlinkedPath)
    81  				Eventually(session).Should(helpers.SayPath(`path:\s+%s`, archive))
    82  				Eventually(session).Should(Exit(0))
    83  			})
    84  		})
    85  
    86  		Context("push with a single app manifest", func() {
    87  			When("the path property is a symlinked path", func() {
    88  				It("should push with the absolute path of the app", func() {
    89  					helpers.WithHelloWorldApp(func(dir string) {
    90  						Expect(os.Symlink(dir, symlinkedPath)).ToNot(HaveOccurred())
    91  
    92  						helpers.WriteManifest(filepath.Join(runningDir, "manifest.yml"), map[string]interface{}{
    93  							"applications": []map[string]string{
    94  								{
    95  									"name": appName,
    96  									"path": symlinkedPath,
    97  								},
    98  							},
    99  						})
   100  
   101  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: runningDir}, PushCommandName)
   102  						Eventually(session).Should(helpers.SayPath(`path:\s+%s`, dir))
   103  						Eventually(session).Should(Exit(0))
   104  					})
   105  				})
   106  			})
   107  		})
   108  	})
   109  })