github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_create_app_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-create-app command", func() { 13 var ( 14 orgName string 15 spaceName string 16 appName string 17 ) 18 19 BeforeEach(func() { 20 orgName = helpers.NewOrgName() 21 spaceName = helpers.NewSpaceName() 22 appName = helpers.PrefixedRandomName("app") 23 }) 24 25 Describe("help", func() { 26 Context("when --help flag is set", func() { 27 It("Displays command usage to output", func() { 28 session := helpers.CF("v3-create-app", "--help") 29 Eventually(session).Should(Say("NAME:")) 30 Eventually(session).Should(Say("v3-create-app - Create a V3 App")) 31 Eventually(session).Should(Say("USAGE:")) 32 Eventually(session).Should(Say("cf v3-create-app APP_NAME \\[--app-type \\(buildpack | docker\\)\\]")) 33 Eventually(session).Should(Say("OPTIONS:")) 34 Eventually(session).Should(Say("--app-type\\s+App lifecycle type to stage and run the app \\(Default: buildpack\\)")) 35 Eventually(session).Should(Exit(0)) 36 }) 37 }) 38 }) 39 40 Context("when the app name is not provided", func() { 41 It("tells the user that the app name is required, prints help text, and exits 1", func() { 42 session := helpers.CF("v3-create-app") 43 44 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 45 Eventually(session.Out).Should(Say("NAME:")) 46 Eventually(session).Should(Exit(1)) 47 }) 48 }) 49 50 Context("when app type is not supported", func() { 51 It("tells the user that the app type is incorrect, prints help text, and exits 1", func() { 52 session := helpers.CF("v3-create-app", appName, "--app-type", "unknown-app-type") 53 54 Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `unknown-app-type' for option `--app-type'. Allowed values are: buildpack or docker")) 55 Eventually(session.Out).Should(Say("NAME:")) 56 Eventually(session).Should(Exit(1)) 57 }) 58 }) 59 60 Context("when the environment is not setup correctly", func() { 61 Context("when no API endpoint is set", func() { 62 BeforeEach(func() { 63 helpers.UnsetAPI() 64 }) 65 66 It("fails with no API endpoint set message", func() { 67 session := helpers.CF("v3-create-app", appName) 68 Eventually(session).Should(Say("FAILED")) 69 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 70 Eventually(session).Should(Exit(1)) 71 }) 72 }) 73 74 Context("when the v3 api does not exist", func() { 75 var server *Server 76 77 BeforeEach(func() { 78 server = helpers.StartAndTargetServerWithoutV3API() 79 }) 80 81 AfterEach(func() { 82 server.Close() 83 }) 84 85 It("fails with error message that the minimum version is not met", func() { 86 session := helpers.CF("v3-create-app", appName) 87 Eventually(session).Should(Say("FAILED")) 88 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 89 Eventually(session).Should(Exit(1)) 90 }) 91 }) 92 93 Context("when the v3 api version is lower than the minimum version", func() { 94 var server *Server 95 96 BeforeEach(func() { 97 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 98 }) 99 100 AfterEach(func() { 101 server.Close() 102 }) 103 104 It("fails with error message that the minimum version is not met", func() { 105 session := helpers.CF("v3-create-app", appName) 106 Eventually(session).Should(Say("FAILED")) 107 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 108 Eventually(session).Should(Exit(1)) 109 }) 110 }) 111 112 Context("when not logged in", func() { 113 BeforeEach(func() { 114 helpers.LogoutCF() 115 }) 116 117 It("fails with not logged in message", func() { 118 session := helpers.CF("v3-create-app", appName) 119 Eventually(session).Should(Say("FAILED")) 120 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 121 Eventually(session).Should(Exit(1)) 122 }) 123 }) 124 125 Context("when there is no org set", func() { 126 BeforeEach(func() { 127 helpers.LogoutCF() 128 helpers.LoginCF() 129 }) 130 131 It("fails with no targeted org error message", func() { 132 session := helpers.CF("v3-create-app", appName) 133 Eventually(session.Out).Should(Say("FAILED")) 134 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 135 Eventually(session).Should(Exit(1)) 136 }) 137 }) 138 139 Context("when there is no space set", func() { 140 BeforeEach(func() { 141 helpers.LogoutCF() 142 helpers.LoginCF() 143 helpers.TargetOrg(ReadOnlyOrg) 144 }) 145 146 It("fails with no targeted space error message", func() { 147 session := helpers.CF("v3-create-app", appName) 148 Eventually(session.Out).Should(Say("FAILED")) 149 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 150 Eventually(session).Should(Exit(1)) 151 }) 152 }) 153 }) 154 155 Context("when the environment is set up correctly", func() { 156 BeforeEach(func() { 157 setupCF(orgName, spaceName) 158 }) 159 160 AfterEach(func() { 161 helpers.QuickDeleteOrg(orgName) 162 }) 163 164 Context("when the app does not exist", func() { 165 It("creates the app with default app type buildpack", func() { 166 session := helpers.CF("v3-create-app", appName) 167 userName, _ := helpers.GetCredentials() 168 Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 169 Eventually(session).Should(Say("OK")) 170 Eventually(session).Should(Exit(0)) 171 172 session = helpers.CF("v3-app", appName) 173 Eventually(session).Should(Say("buildpacks:")) 174 Eventually(session).Should(Exit(0)) 175 }) 176 177 Context("when app type is specified", func() { 178 It("creates the app with the specified app type", func() { 179 session := helpers.CF("v3-create-app", appName, "--app-type", "docker") 180 userName, _ := helpers.GetCredentials() 181 Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 182 Eventually(session).Should(Say("OK")) 183 Eventually(session).Should(Exit(0)) 184 185 session = helpers.CF("v3-app", appName) 186 Eventually(session).Should(Say("docker image:")) 187 Eventually(session).Should(Exit(0)) 188 }) 189 }) 190 }) 191 192 Context("when the app already exists", func() { 193 BeforeEach(func() { 194 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 195 }) 196 197 It("fails to create the app", func() { 198 session := helpers.CF("v3-create-app", appName) 199 userName, _ := helpers.GetCredentials() 200 Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 201 Eventually(session.Err).Should(Say("App %s already exists", appName)) 202 Eventually(session).Should(Say("OK")) 203 Eventually(session).Should(Exit(0)) 204 }) 205 }) 206 }) 207 })