github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/droplets_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("droplets 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("droplets", "APPS", "List droplets of an app"))
    31  			})
    32  
    33  			It("Displays command usage to output", func() {
    34  				session := helpers.CF("droplets", "--help")
    35  
    36  				Eventually(session).Should(Say("NAME:"))
    37  				Eventually(session).Should(Say("droplets - List droplets of an app"))
    38  				Eventually(session).Should(Say("USAGE:"))
    39  				Eventually(session).Should(Say("cf droplets APP_NAME"))
    40  				Eventually(session).Should(Say("SEE ALSO:"))
    41  				Eventually(session).Should(Say("app, create-package, packages, push, set-droplet"))
    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("droplets")
    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, "droplets", 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("droplets", appName)
    79  
    80  				Eventually(session).Should(Say(`Getting droplets of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    81  				Eventually(session.Err).Should(Say("App '%s' not found", appName))
    82  				Eventually(session).Should(Say("FAILED"))
    83  
    84  				Eventually(session).Should(Exit(1))
    85  			})
    86  		})
    87  
    88  		When("the app exists", func() {
    89  			Context("with no droplets", func() {
    90  				BeforeEach(func() {
    91  					Eventually(helpers.CF("create-app", appName)).Should(Exit(0))
    92  				})
    93  
    94  				It("displays empty list", func() {
    95  					session := helpers.CF("droplets", appName)
    96  					Eventually(session).Should(Say(`Getting droplets of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    97  					Eventually(session).Should(Say("No droplets found"))
    98  					Eventually(session).Should(Exit(0))
    99  				})
   100  			})
   101  
   102  			Context("with existing droplets", func() {
   103  				BeforeEach(func() {
   104  					helpers.WithHelloWorldApp(func(dir string) {
   105  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "push", appName)).Should(Exit(0))
   106  					})
   107  				})
   108  
   109  				It("displays droplets in the list", func() {
   110  					session := helpers.CF("droplets", appName)
   111  					Eventually(session).Should(Say(`Getting droplets of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   112  					Eventually(session).Should(Say(`guid\s+state\s+created`))
   113  					Eventually(session).Should(Say(`\s+.* \(current\)\s+staged\s+%s`, helpers.UserFriendlyDateRegex))
   114  
   115  					Eventually(session).Should(Exit(0))
   116  				})
   117  			})
   118  		})
   119  	})
   120  })