github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/experimental/v3_apps_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  	. "github.com/onsi/gomega/ghttp"
    10  )
    11  
    12  var _ = Describe("v3-apps command", func() {
    13  	var (
    14  		orgName   string
    15  		spaceName string
    16  		appName1  string
    17  		appName2  string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		orgName = helpers.NewOrgName()
    22  		spaceName = helpers.NewSpaceName()
    23  		appName1 = helpers.PrefixedRandomName("app1")
    24  		appName2 = helpers.PrefixedRandomName("app2")
    25  	})
    26  
    27  	Describe("help", func() {
    28  		Context("when --help flag is set", func() {
    29  			It("Displays command usage to output", func() {
    30  				session := helpers.CF("v3-apps", "--help")
    31  
    32  				Eventually(session).Should(Say("NAME:"))
    33  				Eventually(session).Should(Say("v3-apps - List all apps in the target space"))
    34  				Eventually(session).Should(Say("USAGE:"))
    35  				Eventually(session).Should(Say("cf v3-apps"))
    36  
    37  				Eventually(session).Should(Exit(0))
    38  			})
    39  		})
    40  	})
    41  
    42  	It("displays the experimental warning", func() {
    43  		session := helpers.CF("v3-apps")
    44  		Eventually(session).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    45  		Eventually(session).Should(Exit())
    46  	})
    47  
    48  	Context("when the environment is not setup correctly", func() {
    49  		Context("when no API endpoint is set", func() {
    50  			BeforeEach(func() {
    51  				helpers.UnsetAPI()
    52  			})
    53  
    54  			It("fails with no API endpoint set message", func() {
    55  				session := helpers.CF("v3-apps")
    56  				Eventually(session).Should(Say("FAILED"))
    57  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    58  				Eventually(session).Should(Exit(1))
    59  			})
    60  		})
    61  
    62  		Context("when the v3 api does not exist", func() {
    63  			var server *Server
    64  
    65  			BeforeEach(func() {
    66  				server = helpers.StartAndTargetServerWithoutV3API()
    67  			})
    68  
    69  			AfterEach(func() {
    70  				server.Close()
    71  			})
    72  
    73  			It("fails with error message that the minimum version is not met", func() {
    74  				session := helpers.CF("v3-apps")
    75  				Eventually(session).Should(Say("FAILED"))
    76  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    77  				Eventually(session).Should(Exit(1))
    78  			})
    79  		})
    80  
    81  		Context("when the v3 api version is lower than the minimum version", func() {
    82  			var server *Server
    83  
    84  			BeforeEach(func() {
    85  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
    86  			})
    87  
    88  			AfterEach(func() {
    89  				server.Close()
    90  			})
    91  
    92  			It("fails with error message that the minimum version is not met", func() {
    93  				session := helpers.CF("v3-apps")
    94  				Eventually(session).Should(Say("FAILED"))
    95  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    96  				Eventually(session).Should(Exit(1))
    97  			})
    98  		})
    99  
   100  		Context("when not logged in", func() {
   101  			BeforeEach(func() {
   102  				helpers.LogoutCF()
   103  			})
   104  
   105  			It("fails with not logged in message", func() {
   106  				session := helpers.CF("v3-apps")
   107  				Eventually(session).Should(Say("FAILED"))
   108  				Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
   109  				Eventually(session).Should(Exit(1))
   110  			})
   111  		})
   112  
   113  		Context("when there is no org set", func() {
   114  			BeforeEach(func() {
   115  				helpers.LogoutCF()
   116  				helpers.LoginCF()
   117  			})
   118  
   119  			It("fails with no org targeted error message", func() {
   120  				session := helpers.CF("v3-apps")
   121  				Eventually(session).Should(Say("FAILED"))
   122  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\."))
   123  				Eventually(session).Should(Exit(1))
   124  			})
   125  		})
   126  
   127  		Context("when there is no space set", func() {
   128  			BeforeEach(func() {
   129  				helpers.LogoutCF()
   130  				helpers.LoginCF()
   131  				helpers.TargetOrg(ReadOnlyOrg)
   132  			})
   133  
   134  			It("fails with no space targeted error message", func() {
   135  				session := helpers.CF("v3-apps")
   136  				Eventually(session).Should(Say("FAILED"))
   137  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
   138  				Eventually(session).Should(Exit(1))
   139  			})
   140  		})
   141  	})
   142  
   143  	Context("when the environment is set up correctly", func() {
   144  		var userName string
   145  
   146  		BeforeEach(func() {
   147  			setupCF(orgName, spaceName)
   148  			userName, _ = helpers.GetCredentials()
   149  		})
   150  
   151  		AfterEach(func() {
   152  			helpers.QuickDeleteOrg(orgName)
   153  		})
   154  
   155  		Context("with no apps", func() {
   156  			It("displays empty list", func() {
   157  				session := helpers.CF("v3-apps")
   158  				Eventually(session).Should(Say("Getting apps in org %s / space %s as %s\\.\\.\\.", orgName, spaceName, userName))
   159  				Eventually(session).Should(Say("No apps found"))
   160  				Eventually(session).Should(Exit(0))
   161  			})
   162  		})
   163  
   164  		Context("with existing apps", func() {
   165  			var domainName string
   166  
   167  			BeforeEach(func() {
   168  				helpers.WithProcfileApp(func(appDir string) {
   169  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName2)).Should(Exit(0))
   170  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName1)).Should(Exit(0))
   171  				})
   172  
   173  				domainName = defaultSharedDomain()
   174  			})
   175  
   176  			It("displays apps in the list", func() {
   177  				session := helpers.CF("v3-apps")
   178  				Eventually(session).Should(Say("Getting apps in org %s / space %s as %s\\.\\.\\.", orgName, spaceName, userName))
   179  				Eventually(session).Should(Say("name\\s+requested state\\s+processes\\s+routes"))
   180  				Eventually(session).Should(Say("%s\\s+started\\s+web:1/1, console:0/0, rake:0/0\\s+%s\\.%s", appName1, appName1, domainName))
   181  				Eventually(session).Should(Say("%s\\s+started\\s+web:1/1, console:0/0, rake:0/0\\s+%s\\.%s", appName2, appName2, domainName))
   182  
   183  				Eventually(session).Should(Exit(0))
   184  			})
   185  
   186  			Context("when one app is stopped", func() {
   187  				BeforeEach(func() {
   188  					Eventually(helpers.CF("stop", appName1)).Should(Exit(0))
   189  				})
   190  
   191  				It("displays app as stopped", func() {
   192  					session := helpers.CF("v3-apps")
   193  					Eventually(session).Should(Say("Getting apps in org %s / space %s as %s\\.\\.\\.", orgName, spaceName, userName))
   194  					Eventually(session).Should(Say("name\\s+requested state\\s+processes\\s+routes"))
   195  					Eventually(session).Should(Say("%s\\s+stopped\\s+web:0/1, console:0/0, rake:0/0\\s+%s\\.%s", appName1, appName1, domainName))
   196  					Eventually(session).Should(Say("%s\\s+started\\s+web:1/1, console:0/0, rake:0/0\\s+%s\\.%s", appName2, appName2, domainName))
   197  
   198  					Eventually(session).Should(Exit(0))
   199  				})
   200  			})
   201  		})
   202  	})
   203  })