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