github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/create_app_command_test.go (about) 1 package isolated 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 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 ) 11 12 var _ = Describe("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 When("--help flag is set", func() { 27 It("appears in cf help -a", func() { 28 session := helpers.CF("help", "-a") 29 Eventually(session).Should(Exit(0)) 30 Expect(session).To(HaveCommandInCategoryWithDescription("create-app", "APPS", "Create an Application in the target space")) 31 }) 32 33 It("Displays command usage to output", func() { 34 session := helpers.CF("create-app", "--help") 35 Eventually(session).Should(Say("NAME:")) 36 Eventually(session).Should(Say("create-app - Create an Application in the target space")) 37 Eventually(session).Should(Say("USAGE:")) 38 Eventually(session).Should(Say(`cf create-app APP_NAME \[--app-type \(buildpack | docker\)\]`)) 39 Eventually(session).Should(Say("OPTIONS:")) 40 Eventually(session).Should(Say(`--app-type\s+App lifecycle type to stage and run the app \(Default: buildpack\)`)) 41 Eventually(session).Should(Say("SEE ALSO:")) 42 Eventually(session).Should(Say("app, apps, push")) 43 Eventually(session).Should(Exit(0)) 44 }) 45 }) 46 }) 47 48 When("the app name is not provided", func() { 49 It("tells the user that the app name is required, prints help text, and exits 1", func() { 50 session := helpers.CF("create-app") 51 52 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 53 Eventually(session).Should(Say("NAME:")) 54 Eventually(session).Should(Exit(1)) 55 }) 56 }) 57 58 When("app type is not supported", func() { 59 It("tells the user that the app type is incorrect, prints help text, and exits 1", func() { 60 session := helpers.CF("create-app", appName, "--app-type", "unknown-app-type") 61 62 Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `unknown-app-type' for option `--app-type'. Allowed values are: buildpack or docker")) 63 Eventually(session).Should(Say("NAME:")) 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 68 When("the environment is not setup correctly", func() { 69 It("fails with the appropriate errors", func() { 70 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "create-app", appName) 71 }) 72 }) 73 74 When("the environment is set up correctly", func() { 75 BeforeEach(func() { 76 helpers.SetupCF(orgName, spaceName) 77 }) 78 79 AfterEach(func() { 80 helpers.QuickDeleteOrg(orgName) 81 }) 82 83 When("the app does not exist", func() { 84 It("creates the app with default app type buildpack", func() { 85 session := helpers.CF("create-app", appName) 86 userName, _ := helpers.GetCredentials() 87 Eventually(session).Should(Say("Creating app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 88 Eventually(session).Should(Say("OK")) 89 Eventually(session).Should(Exit(0)) 90 91 session = helpers.CF("app", appName) 92 Eventually(session).Should(Say("buildpacks:")) 93 Eventually(session).Should(Exit(0)) 94 }) 95 96 When("app type is specified", func() { 97 It("creates the app with the specified app type", func() { 98 session := helpers.CF("create-app", appName, "--app-type", "docker") 99 userName, _ := helpers.GetCredentials() 100 Eventually(session).Should(Say("Creating app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 101 Eventually(session).Should(Say("OK")) 102 Eventually(session).Should(Exit(0)) 103 104 session = helpers.CF("app", appName) 105 Eventually(session).Should(Say("docker image:")) 106 Eventually(session).Should(Exit(0)) 107 }) 108 }) 109 }) 110 111 When("the app already exists", func() { 112 BeforeEach(func() { 113 Eventually(helpers.CF("create-app", appName)).Should(Exit(0)) 114 }) 115 116 It("fails to create the app", func() { 117 session := helpers.CF("create-app", appName) 118 userName, _ := helpers.GetCredentials() 119 Eventually(session).Should(Say("Creating app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 120 Eventually(session).Should(Say(`App with the name '%s' already exists\.`, appName)) 121 Eventually(session).Should(Say("OK")) 122 Eventually(session).Should(Exit(0)) 123 }) 124 }) 125 }) 126 })