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

     1  package isolated
     2  
     3  import (
     4  	"regexp"
     5  
     6  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("apps command", func() {
    15  	var (
    16  		orgName   string
    17  		spaceName string
    18  		appName1  string
    19  		appName2  string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		orgName = helpers.NewOrgName()
    24  		spaceName = helpers.NewSpaceName()
    25  		appName1 = helpers.PrefixedRandomName("app1")
    26  		appName2 = helpers.PrefixedRandomName("app2")
    27  		helpers.TurnOffExperimental()
    28  	})
    29  
    30  	AfterEach(func() {
    31  		helpers.TurnOnExperimental()
    32  	})
    33  
    34  	Describe("help", func() {
    35  		When("--help flag is set", func() {
    36  			It("appears in cf help -a", func() {
    37  				session := helpers.CF("help", "-a")
    38  				Eventually(session).Should(Exit(0))
    39  				Expect(session).To(HaveCommandInCategoryWithDescription("apps", "APPS", "List all apps in the target space"))
    40  			})
    41  
    42  			It("Displays command usage to output", func() {
    43  				session := helpers.CF("apps", "--help")
    44  
    45  				Eventually(session).Should(Say("NAME:"))
    46  				Eventually(session).Should(Say("apps - List all apps in the target space"))
    47  				Eventually(session).Should(Say("USAGE:"))
    48  				Eventually(session).Should(Say(regexp.QuoteMeta("cf apps [--labels SELECTOR]")))
    49  				Eventually(session).Should(Say("EXAMPLES:"))
    50  				Eventually(session).Should(Say("cf apps"))
    51  				Eventually(session).Should(Say(regexp.QuoteMeta("cf apps --labels 'environment in (production,staging),tier in (backend)'")))
    52  				Eventually(session).Should(Say(regexp.QuoteMeta("cf apps --labels 'env=dev,!chargeback-code,tier in (backend,worker)'")))
    53  				Eventually(session).Should(Say("ALIAS:"))
    54  				Eventually(session).Should(Say("a"))
    55  				Eventually(session).Should(Say("OPTIONS:"))
    56  				Eventually(session).Should(Say(`--labels\s+Selector to filter apps by labels`))
    57  				Eventually(session).Should(Say("SEE ALSO:"))
    58  				Eventually(session).Should(Say("events, logs, map-route, push, restart, scale, start, stop"))
    59  
    60  				Eventually(session).Should(Exit(0))
    61  			})
    62  		})
    63  	})
    64  
    65  	When("the environment is not setup correctly", func() {
    66  		It("fails with the appropriate errors", func() {
    67  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "apps")
    68  		})
    69  	})
    70  
    71  	When("the environment is set up correctly", func() {
    72  		var userName string
    73  
    74  		BeforeEach(func() {
    75  			helpers.SetupCF(orgName, spaceName)
    76  			userName, _ = helpers.GetCredentials()
    77  		})
    78  
    79  		AfterEach(func() {
    80  			helpers.QuickDeleteOrg(orgName)
    81  		})
    82  
    83  		Context("with no apps", func() {
    84  			It("displays empty list", func() {
    85  				session := helpers.CF("apps")
    86  				Eventually(session).Should(Say(`Getting apps in org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
    87  				Eventually(session).Should(Say("No apps found"))
    88  				Eventually(session).Should(Exit(0))
    89  			})
    90  		})
    91  
    92  		Context("with existing apps", func() {
    93  			var domainName string
    94  
    95  			BeforeEach(func() {
    96  				domainName = helpers.DefaultSharedDomain()
    97  				helpers.WithProcfileApp(func(appDir string) {
    98  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName2)).Should(Exit(0))
    99  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName1)).Should(Exit(0))
   100  				})
   101  
   102  			})
   103  
   104  			It("displays apps in the list", func() {
   105  				session := helpers.CF("apps")
   106  				Eventually(session).Should(Say(`Getting apps in org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   107  				Eventually(session).Should(Say(`name\s+requested state\s+processes\s+routes`))
   108  				Eventually(session).Should(Say(`%s\s+started\s+web:1/1, console:0/0\s+%s\.%s`, appName1, appName1, domainName))
   109  				Eventually(session).Should(Say(`%s\s+started\s+web:1/1, console:0/0\s+%s\.%s`, appName2, appName2, domainName))
   110  
   111  				Eventually(session).Should(Exit(0))
   112  			})
   113  
   114  			When("one app is stopped", func() {
   115  				BeforeEach(func() {
   116  					Eventually(helpers.CF("stop", appName1)).Should(Exit(0))
   117  				})
   118  
   119  				It("displays app as stopped", func() {
   120  					session := helpers.CF("apps")
   121  					Eventually(session).Should(Say(`Getting apps in org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   122  					Eventually(session).Should(Say(`name\s+requested state\s+processes\s+routes`))
   123  					Eventually(session).Should(Say(`%s\s+stopped\s+web:0/1, console:0/0\s+%s\.%s`, appName1, appName1, domainName))
   124  					Eventually(session).Should(Say(`%s\s+started\s+web:1/1, console:0/0\s+%s\.%s`, appName2, appName2, domainName))
   125  
   126  					Eventually(session).Should(Exit(0))
   127  				})
   128  			})
   129  
   130  			When("the --labels flag is given", func() {
   131  
   132  				BeforeEach(func() {
   133  					Eventually(helpers.CF("set-label", "app", appName1, "environment=production", "tier=backend")).Should(Exit(0))
   134  					Eventually(helpers.CF("set-label", "app", appName2, "environment=staging", "tier=frontend")).Should(Exit(0))
   135  				})
   136  
   137  				It("displays apps with provided labels", func() {
   138  					session := helpers.CF("apps", "--labels", "environment in (production,staging),tier in (backend)")
   139  					Eventually(session).Should(Exit(0))
   140  					Expect(session).Should(Say(appName1))
   141  					Expect(session).ShouldNot(Say(appName2))
   142  				})
   143  			})
   144  		})
   145  
   146  	})
   147  })