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