github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/v7/push/path_flag_test.go (about)

     1  package push
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"regexp"
     7  
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = When("the -p flag is provided", func() {
    16  	var (
    17  		appName string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		appName = helpers.PrefixedRandomName("app")
    22  	})
    23  
    24  	When("the path is a directory", func() {
    25  		When("the directory contains files", func() {
    26  			It("pushes the app from the directory", func() {
    27  				helpers.WithHelloWorldApp(func(appDir string) {
    28  					session := helpers.CF(PushCommandName, appName, "-p", appDir)
    29  					Eventually(session).Should(Say(`name:\s+%s`, appName))
    30  					Eventually(session).Should(Say(`requested state:\s+started`))
    31  					Eventually(session).Should(Exit(0))
    32  				})
    33  			})
    34  		})
    35  
    36  		When("the directory is empty", func() {
    37  			var emptyDir string
    38  
    39  			BeforeEach(func() {
    40  				var err error
    41  				emptyDir, err = ioutil.TempDir("", "integration-push-path-empty")
    42  				Expect(err).ToNot(HaveOccurred())
    43  			})
    44  
    45  			AfterEach(func() {
    46  				Expect(os.RemoveAll(emptyDir)).ToNot(HaveOccurred())
    47  			})
    48  
    49  			It("returns an error", func() {
    50  				session := helpers.CF(PushCommandName, appName, "-p", emptyDir)
    51  				Eventually(session.Err).Should(Say("No app files found in '(/private)?%s'", regexp.QuoteMeta(emptyDir)))
    52  				Eventually(session).Should(Exit(1))
    53  			})
    54  		})
    55  	})
    56  
    57  	When("the path is a zip file", func() {
    58  		Context("pushing a zip file", func() {
    59  			var archive string
    60  
    61  			BeforeEach(func() {
    62  				helpers.WithHelloWorldApp(func(appDir string) {
    63  					tmpfile, err := ioutil.TempFile("", "push-archive-integration")
    64  					Expect(err).ToNot(HaveOccurred())
    65  					archive = tmpfile.Name()
    66  					Expect(tmpfile.Close())
    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("pushes the app from the zip file", func() {
    78  				session := helpers.CF(PushCommandName, appName, "-p", archive)
    79  
    80  				Eventually(session).Should(Say(`name:\s+%s`, appName))
    81  				Eventually(session).Should(Say(`requested state:\s+started`))
    82  				Eventually(session).Should(Exit(0))
    83  			})
    84  		})
    85  	})
    86  })