github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v6/experimental/v3_packages_command_test.go (about)

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