github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/experimental/v3_apps_command_test.go (about)

     1  package experimental
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     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  	. "github.com/onsi/gomega/ghttp"
    11  )
    12  
    13  var _ = Describe("v3-apps command", func() {
    14  	var (
    15  		orgName   string
    16  		spaceName string
    17  		appName1  string
    18  		appName2  string
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		orgName = helpers.NewOrgName()
    23  		spaceName = helpers.NewSpaceName()
    24  		appName1 = helpers.PrefixedRandomName("app1")
    25  		appName2 = helpers.PrefixedRandomName("app2")
    26  		helpers.TurnOffExperimental()
    27  	})
    28  
    29  	AfterEach(func() {
    30  		helpers.TurnOnExperimental()
    31  	})
    32  
    33  	Describe("help", func() {
    34  		When("--help flag is set", func() {
    35  			It("Displays command usage to output", func() {
    36  				session := helpers.CF("v3-apps", "--help")
    37  
    38  				Eventually(session).Should(Say("NAME:"))
    39  				Eventually(session).Should(Say("v3-apps - List all apps in the target space"))
    40  				Eventually(session).Should(Say("USAGE:"))
    41  				Eventually(session).Should(Say("cf v3-apps"))
    42  
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  	})
    47  
    48  	It("displays the experimental warning", func() {
    49  		session := helpers.CF("v3-apps")
    50  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    51  		Eventually(session).Should(Exit())
    52  	})
    53  
    54  	When("the environment is not setup correctly", func() {
    55  		When("the v3 api version is lower than the minimum version", func() {
    56  			var server *Server
    57  
    58  			BeforeEach(func() {
    59  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    60  			})
    61  
    62  			AfterEach(func() {
    63  				server.Close()
    64  			})
    65  
    66  			It("fails with error message that the minimum version is not met", func() {
    67  				session := helpers.CF("v3-apps")
    68  				Eventually(session).Should(Say("FAILED"))
    69  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.27\.0 or higher\.`))
    70  				Eventually(session).Should(Exit(1))
    71  			})
    72  		})
    73  
    74  		It("fails with the appropriate errors", func() {
    75  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-apps")
    76  		})
    77  	})
    78  
    79  	When("the environment is set up correctly", func() {
    80  		var userName string
    81  
    82  		BeforeEach(func() {
    83  			helpers.SetupCF(orgName, spaceName)
    84  			userName, _ = helpers.GetCredentials()
    85  		})
    86  
    87  		AfterEach(func() {
    88  			helpers.QuickDeleteOrg(orgName)
    89  		})
    90  
    91  		Context("with no apps", func() {
    92  			It("displays empty list", func() {
    93  				session := helpers.CF("v3-apps")
    94  				Eventually(session).Should(Say(`Getting apps in org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
    95  				Eventually(session).Should(Say("No apps found"))
    96  				Eventually(session).Should(Exit(0))
    97  			})
    98  		})
    99  
   100  		Context("with existing apps", func() {
   101  			var domainName string
   102  
   103  			BeforeEach(func() {
   104  				helpers.WithProcfileApp(func(appDir string) {
   105  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName2)).Should(Exit(0))
   106  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName1)).Should(Exit(0))
   107  				})
   108  
   109  				domainName = helpers.DefaultSharedDomain()
   110  			})
   111  
   112  			It("displays apps in the list", func() {
   113  				session := helpers.CF("v3-apps")
   114  				Eventually(session).Should(Say(`Getting apps in org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   115  				Eventually(session).Should(Say(`name\s+requested state\s+processes\s+routes`))
   116  				Eventually(session).Should(Say(`%s\s+started\s+web:1/1, console:0/0\s+%s\.%s`, appName1, appName1, domainName))
   117  				Eventually(session).Should(Say(`%s\s+started\s+web:1/1, console:0/0\s+%s\.%s`, appName2, appName2, domainName))
   118  
   119  				Eventually(session).Should(Exit(0))
   120  			})
   121  
   122  			When("one app is stopped", func() {
   123  				BeforeEach(func() {
   124  					Eventually(helpers.CF("stop", appName1)).Should(Exit(0))
   125  				})
   126  
   127  				It("displays app as stopped", func() {
   128  					session := helpers.CF("v3-apps")
   129  					Eventually(session).Should(Say(`Getting apps in org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   130  					Eventually(session).Should(Say(`name\s+requested state\s+processes\s+routes`))
   131  					Eventually(session).Should(Say(`%s\s+stopped\s+web:0/1, console:0/0\s+%s\.%s`, appName1, appName1, domainName))
   132  					Eventually(session).Should(Say(`%s\s+started\s+web:1/1, console:0/0\s+%s\.%s`, appName2, appName2, domainName))
   133  
   134  					Eventually(session).Should(Exit(0))
   135  				})
   136  			})
   137  		})
   138  	})
   139  })