github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/shared/experimental/v3_start_application_command_test.go (about) 1 package experimental 2 3 import ( 4 "regexp" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("v3-start-application 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-start", "--help") 30 31 Eventually(session).Should(Say("NAME:")) 32 Eventually(session).Should(Say("v3-start - Start an app")) 33 Eventually(session).Should(Say("USAGE:")) 34 Eventually(session).Should(Say("cf v3-start APP_NAME")) 35 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-start") 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-start", 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("the environment is not setup correctly", func() { 58 It("fails with the appropriate errors", func() { 59 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-start", appName) 60 }) 61 }) 62 63 When("the environment is set up correctly", func() { 64 BeforeEach(func() { 65 helpers.SetupCF(orgName, spaceName) 66 }) 67 68 AfterEach(func() { 69 helpers.QuickDeleteOrg(orgName) 70 }) 71 72 When("the app exists", func() { 73 BeforeEach(func() { 74 var packageGUID string 75 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 76 77 helpers.WithHelloWorldApp(func(dir string) { 78 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-create-package", appName) 79 Eventually(pkgSession).Should(Exit(0)) 80 regex, err := regexp.Compile(`package guid: (.+)`) 81 Expect(err).ToNot(HaveOccurred()) 82 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 83 Expect(matches).To(HaveLen(2)) 84 85 packageGUID = matches[1] 86 }) 87 88 stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID) 89 Eventually(stageSession).Should(Exit(0)) 90 91 regex, err := regexp.Compile(`droplet guid:\s+(.+)`) 92 Expect(err).ToNot(HaveOccurred()) 93 matches := regex.FindStringSubmatch(string(stageSession.Out.Contents())) 94 Expect(matches).To(HaveLen(2)) 95 96 dropletGUID := matches[1] 97 setDropletSession := helpers.CF("v3-set-droplet", appName, "--droplet-guid", dropletGUID) 98 Eventually(setDropletSession).Should(Exit(0)) 99 }) 100 101 It("starts the app", func() { 102 userName, _ := helpers.GetCredentials() 103 104 session := helpers.CF("v3-start", appName) 105 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 106 Eventually(session).Should(Say("OK")) 107 108 Eventually(session).Should(Exit(0)) 109 }) 110 111 When("the app is already started", func() { 112 BeforeEach(func() { 113 Eventually(helpers.CF("v3-start", appName)).Should(Exit(0)) 114 }) 115 116 It("displays app already started and exits 0", func() { 117 session := helpers.CF("v3-start", appName) 118 119 Eventually(session.Err).Should(Say("App %s is already started", appName)) 120 Eventually(session).Should(Say("OK")) 121 122 Eventually(session).Should(Exit(0)) 123 }) 124 }) 125 }) 126 127 When("the app does not exist", func() { 128 It("displays app not found and exits 1", func() { 129 invalidAppName := "invalid-app-name" 130 session := helpers.CF("v3-start", invalidAppName) 131 132 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 133 Eventually(session).Should(Say("FAILED")) 134 135 Eventually(session).Should(Exit(1)) 136 }) 137 }) 138 }) 139 })