github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/packages_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("packages command", func() {
    13  	var (
    14  		orgName   string
    15  		spaceName string
    16  		appName   string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  		appName = helpers.NewAppName()
    23  	})
    24  
    25  	Describe("help", func() {
    26  		When("--help flag is set", func() {
    27  			It("appears in cf help -a", func() {
    28  				session := helpers.CF("help", "-a")
    29  				Eventually(session).Should(Exit(0))
    30  				Expect(session).To(HaveCommandInCategoryWithDescription("packages", "APPS", "List packages of an app"))
    31  			})
    32  
    33  			It("Displays command usage to output", func() {
    34  				session := helpers.CF("packages", "--help")
    35  
    36  				Eventually(session).Should(Say("NAME:"))
    37  				Eventually(session).Should(Say("packages - List packages of an app"))
    38  				Eventually(session).Should(Say("USAGE:"))
    39  				Eventually(session).Should(Say("cf packages APP_NAME"))
    40  				Eventually(session).Should(Say("SEE ALSO:"))
    41  				Eventually(session).Should(Say("app, create-package, droplets, push"))
    42  
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  	})
    47  
    48  	When("the app name is not provided", func() {
    49  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    50  			session := helpers.CF("packages")
    51  
    52  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    53  			Eventually(session).Should(Say("NAME:"))
    54  			Eventually(session).Should(Exit(1))
    55  		})
    56  	})
    57  
    58  	When("the environment is not setup correctly", func() {
    59  		It("fails with the appropriate errors", func() {
    60  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "packages", appName)
    61  		})
    62  	})
    63  
    64  	When("the environment is set up correctly", func() {
    65  		var userName string
    66  
    67  		BeforeEach(func() {
    68  			helpers.SetupCF(orgName, spaceName)
    69  			userName, _ = helpers.GetCredentials()
    70  		})
    71  
    72  		AfterEach(func() {
    73  			helpers.QuickDeleteOrg(orgName)
    74  		})
    75  
    76  		When("the app does not exist", func() {
    77  			It("displays app not found and exits 1", func() {
    78  				session := helpers.CF("packages", appName)
    79  				userName, _ = helpers.GetCredentials()
    80  
    81  				Eventually(session).Should(Say(`Getting packages of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    82  				Eventually(session.Err).Should(Say(`App '%s' not found\.`, appName))
    83  				Eventually(session).Should(Say("FAILED"))
    84  
    85  				Eventually(session).Should(Exit(1))
    86  			})
    87  		})
    88  
    89  		When("the app exists", func() {
    90  			Context("with no packages", func() {
    91  				BeforeEach(func() {
    92  					Eventually(helpers.CF("create-app", appName)).Should(Exit(0))
    93  				})
    94  
    95  				It("displays empty list", func() {
    96  					session := helpers.CF("packages", appName)
    97  					Eventually(session).Should(Say(`Getting packages of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    98  					Eventually(session).Should(Say(`No packages found\.`))
    99  					Eventually(session).Should(Exit(0))
   100  				})
   101  			})
   102  
   103  			Context("with existing packages", func() {
   104  				BeforeEach(func() {
   105  					helpers.WithHelloWorldApp(func(dir string) {
   106  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-push", appName, "--no-start")).Should(Exit(0))
   107  					})
   108  				})
   109  
   110  				It("displays packages in the list", func() {
   111  					session := helpers.CF("packages", appName)
   112  					Eventually(session).Should(Say(`Getting packages of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   113  					Eventually(session).Should(Say(`guid\s+state\s+created`))
   114  					Eventually(session).Should(Say(`.*\s+ready\s+.*`))
   115  
   116  					Eventually(session).Should(Exit(0))
   117  				})
   118  			})
   119  		})
   120  	})
   121  })