github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/integration/shared/experimental/v3_create_app_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-create-app command", func() { 14 var ( 15 orgName string 16 spaceName string 17 appName string 18 ) 19 20 BeforeEach(func() { 21 orgName = helpers.NewOrgName() 22 spaceName = helpers.NewSpaceName() 23 appName = helpers.PrefixedRandomName("app") 24 }) 25 26 Describe("help", func() { 27 When("--help flag is set", func() { 28 It("Displays command usage to output", func() { 29 session := helpers.CF("v3-create-app", "--help") 30 Eventually(session).Should(Say("NAME:")) 31 Eventually(session).Should(Say("v3-create-app - Create a V3 App")) 32 Eventually(session).Should(Say("USAGE:")) 33 Eventually(session).Should(Say("cf v3-create-app APP_NAME \\[--app-type \\(buildpack | docker\\)\\]")) 34 Eventually(session).Should(Say("OPTIONS:")) 35 Eventually(session).Should(Say("--app-type\\s+App lifecycle type to stage and run the app \\(Default: buildpack\\)")) 36 Eventually(session).Should(Exit(0)) 37 }) 38 }) 39 }) 40 41 When("the app name is not provided", func() { 42 It("tells the user that the app name is required, prints help text, and exits 1", func() { 43 session := helpers.CF("v3-create-app") 44 45 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 46 Eventually(session).Should(Say("NAME:")) 47 Eventually(session).Should(Exit(1)) 48 }) 49 }) 50 51 It("displays the experimental warning", func() { 52 session := helpers.CF("v3-create-app", appName) 53 Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 54 Eventually(session).Should(Exit()) 55 }) 56 57 When("app type is not supported", func() { 58 It("tells the user that the app type is incorrect, prints help text, and exits 1", func() { 59 session := helpers.CF("v3-create-app", appName, "--app-type", "unknown-app-type") 60 61 Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `unknown-app-type' for option `--app-type'. Allowed values are: buildpack or docker")) 62 Eventually(session).Should(Say("NAME:")) 63 Eventually(session).Should(Exit(1)) 64 }) 65 }) 66 67 When("the environment is not setup correctly", func() { 68 When("no API endpoint is set", func() { 69 BeforeEach(func() { 70 helpers.UnsetAPI() 71 }) 72 73 It("fails with no API endpoint set message", func() { 74 session := helpers.CF("v3-create-app", appName) 75 Eventually(session).Should(Say("FAILED")) 76 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 77 Eventually(session).Should(Exit(1)) 78 }) 79 }) 80 81 When("the v3 api version is lower than the minimum version", func() { 82 var server *Server 83 84 BeforeEach(func() { 85 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 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-create-app", appName) 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 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-create-app", appName) 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 When("there is no org set", func() { 114 BeforeEach(func() { 115 helpers.LogoutCF() 116 helpers.LoginCF() 117 }) 118 119 It("fails with no targeted org error message", func() { 120 session := helpers.CF("v3-create-app", appName) 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 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 targeted space error message", func() { 135 session := helpers.CF("v3-create-app", appName) 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 When("the environment is set up correctly", func() { 144 BeforeEach(func() { 145 helpers.SetupCF(orgName, spaceName) 146 }) 147 148 AfterEach(func() { 149 helpers.QuickDeleteOrg(orgName) 150 }) 151 152 When("the app does not exist", func() { 153 It("creates the app with default app type buildpack", func() { 154 session := helpers.CF("v3-create-app", appName) 155 userName, _ := helpers.GetCredentials() 156 Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 157 Eventually(session).Should(Say("OK")) 158 Eventually(session).Should(Exit(0)) 159 160 session = helpers.CF("app", appName) 161 Eventually(session).Should(Say("buildpacks:")) 162 Eventually(session).Should(Exit(0)) 163 }) 164 165 When("app type is specified", func() { 166 It("creates the app with the specified app type", func() { 167 session := helpers.CF("v3-create-app", appName, "--app-type", "docker") 168 userName, _ := helpers.GetCredentials() 169 Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 170 Eventually(session).Should(Say("OK")) 171 Eventually(session).Should(Exit(0)) 172 173 session = helpers.CF("app", appName) 174 Eventually(session).Should(Say("docker image:")) 175 Eventually(session).Should(Exit(0)) 176 }) 177 }) 178 }) 179 180 When("the app already exists", func() { 181 BeforeEach(func() { 182 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 183 }) 184 185 It("fails to create the app", func() { 186 session := helpers.CF("v3-create-app", appName) 187 userName, _ := helpers.GetCredentials() 188 Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 189 Eventually(session.Err).Should(Say("App %s already exists", appName)) 190 Eventually(session).Should(Say("OK")) 191 Eventually(session).Should(Exit(0)) 192 }) 193 }) 194 }) 195 })