github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+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("no API endpoint is set", func() {
    56  			BeforeEach(func() {
    57  				helpers.UnsetAPI()
    58  			})
    59  
    60  			It("fails with no API endpoint set message", func() {
    61  				session := helpers.CF("v3-apps")
    62  				Eventually(session).Should(Say("FAILED"))
    63  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    64  				Eventually(session).Should(Exit(1))
    65  			})
    66  		})
    67  
    68  		When("the v3 api version is lower than the minimum version", func() {
    69  			var server *Server
    70  
    71  			BeforeEach(func() {
    72  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    73  			})
    74  
    75  			AfterEach(func() {
    76  				server.Close()
    77  			})
    78  
    79  			It("fails with error message that the minimum version is not met", func() {
    80  				session := helpers.CF("v3-apps")
    81  				Eventually(session).Should(Say("FAILED"))
    82  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    83  				Eventually(session).Should(Exit(1))
    84  			})
    85  		})
    86  
    87  		When("not logged in", func() {
    88  			BeforeEach(func() {
    89  				helpers.LogoutCF()
    90  			})
    91  
    92  			It("fails with not logged in message", func() {
    93  				session := helpers.CF("v3-apps")
    94  				Eventually(session).Should(Say("FAILED"))
    95  				Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
    96  				Eventually(session).Should(Exit(1))
    97  			})
    98  		})
    99  
   100  		When("there is no org set", func() {
   101  			BeforeEach(func() {
   102  				helpers.LogoutCF()
   103  				helpers.LoginCF()
   104  			})
   105  
   106  			It("fails with no org targeted error message", func() {
   107  				session := helpers.CF("v3-apps")
   108  				Eventually(session).Should(Say("FAILED"))
   109  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\."))
   110  				Eventually(session).Should(Exit(1))
   111  			})
   112  		})
   113  
   114  		When("there is no space set", func() {
   115  			BeforeEach(func() {
   116  				helpers.LogoutCF()
   117  				helpers.LoginCF()
   118  				helpers.TargetOrg(ReadOnlyOrg)
   119  			})
   120  
   121  			It("fails with no space targeted error message", func() {
   122  				session := helpers.CF("v3-apps")
   123  				Eventually(session).Should(Say("FAILED"))
   124  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
   125  				Eventually(session).Should(Exit(1))
   126  			})
   127  		})
   128  	})
   129  
   130  	When("the environment is set up correctly", func() {
   131  		var userName string
   132  
   133  		BeforeEach(func() {
   134  			helpers.SetupCF(orgName, spaceName)
   135  			userName, _ = helpers.GetCredentials()
   136  		})
   137  
   138  		AfterEach(func() {
   139  			helpers.QuickDeleteOrg(orgName)
   140  		})
   141  
   142  		Context("with no apps", func() {
   143  			It("displays empty list", func() {
   144  				session := helpers.CF("v3-apps")
   145  				Eventually(session).Should(Say("Getting apps in org %s / space %s as %s\\.\\.\\.", orgName, spaceName, userName))
   146  				Eventually(session).Should(Say("No apps found"))
   147  				Eventually(session).Should(Exit(0))
   148  			})
   149  		})
   150  
   151  		Context("with existing apps", func() {
   152  			var domainName string
   153  
   154  			BeforeEach(func() {
   155  				helpers.WithProcfileApp(func(appDir string) {
   156  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName2)).Should(Exit(0))
   157  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName1)).Should(Exit(0))
   158  				})
   159  
   160  				domainName = helpers.DefaultSharedDomain()
   161  			})
   162  
   163  			It("displays apps in the list", func() {
   164  				session := helpers.CF("v3-apps")
   165  				Eventually(session).Should(Say("Getting apps in org %s / space %s as %s\\.\\.\\.", orgName, spaceName, userName))
   166  				Eventually(session).Should(Say("name\\s+requested state\\s+processes\\s+routes"))
   167  				Eventually(session).Should(Say("%s\\s+started\\s+web:1/1, console:0/0, rake:0/0\\s+%s\\.%s", appName1, appName1, domainName))
   168  				Eventually(session).Should(Say("%s\\s+started\\s+web:1/1, console:0/0, rake:0/0\\s+%s\\.%s", appName2, appName2, domainName))
   169  
   170  				Eventually(session).Should(Exit(0))
   171  			})
   172  
   173  			When("one app is stopped", func() {
   174  				BeforeEach(func() {
   175  					Eventually(helpers.CF("stop", appName1)).Should(Exit(0))
   176  				})
   177  
   178  				It("displays app as stopped", func() {
   179  					session := helpers.CF("v3-apps")
   180  					Eventually(session).Should(Say("Getting apps in org %s / space %s as %s\\.\\.\\.", orgName, spaceName, userName))
   181  					Eventually(session).Should(Say("name\\s+requested state\\s+processes\\s+routes"))
   182  					Eventually(session).Should(Say("%s\\s+stopped\\s+web:0/1, console:0/0, rake:0/0\\s+%s\\.%s", appName1, appName1, domainName))
   183  					Eventually(session).Should(Say("%s\\s+started\\s+web:1/1, console:0/0, rake:0/0\\s+%s\\.%s", appName2, appName2, domainName))
   184  
   185  					Eventually(session).Should(Exit(0))
   186  				})
   187  			})
   188  		})
   189  	})
   190  })