github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+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/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 . "github.com/onsi/gomega/ghttp" 13 ) 14 15 var _ = Describe("v3-start-application command", func() { 16 var ( 17 orgName string 18 spaceName string 19 appName string 20 ) 21 22 BeforeEach(func() { 23 orgName = helpers.NewOrgName() 24 spaceName = helpers.NewSpaceName() 25 appName = helpers.PrefixedRandomName("app") 26 }) 27 28 Describe("help", func() { 29 When("--help flag is set", func() { 30 It("Displays command usage to output", func() { 31 session := helpers.CF("v3-start", "--help") 32 33 Eventually(session).Should(Say("NAME:")) 34 Eventually(session).Should(Say("v3-start - Start an app")) 35 Eventually(session).Should(Say("USAGE:")) 36 Eventually(session).Should(Say("cf v3-start APP_NAME")) 37 38 Eventually(session).Should(Exit(0)) 39 }) 40 }) 41 }) 42 43 When("the app name is not provided", func() { 44 It("tells the user that the app name is required, prints help text, and exits 1", func() { 45 session := helpers.CF("v3-start") 46 47 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 48 Eventually(session).Should(Say("NAME:")) 49 Eventually(session).Should(Exit(1)) 50 }) 51 }) 52 53 It("displays the experimental warning", func() { 54 session := helpers.CF("v3-start", appName) 55 Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 56 Eventually(session).Should(Exit()) 57 }) 58 59 When("the environment is not setup correctly", func() { 60 When("the v3 api version is lower than the minimum version", func() { 61 var server *Server 62 63 BeforeEach(func() { 64 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 65 }) 66 67 AfterEach(func() { 68 server.Close() 69 }) 70 71 It("fails with error message that the minimum version is not met", func() { 72 session := helpers.CF("v3-start", appName) 73 Eventually(session).Should(Say("FAILED")) 74 Eventually(session.Err).Should(Say(`This command requires CF API version 3\.27\.0 or higher\.`)) 75 Eventually(session).Should(Exit(1)) 76 }) 77 }) 78 79 It("fails with the appropriate errors", func() { 80 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-start", appName) 81 }) 82 }) 83 84 When("the environment is set up correctly", func() { 85 BeforeEach(func() { 86 helpers.SetupCF(orgName, spaceName) 87 }) 88 89 AfterEach(func() { 90 helpers.QuickDeleteOrg(orgName) 91 }) 92 93 When("the app exists", func() { 94 BeforeEach(func() { 95 var packageGUID string 96 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 97 98 helpers.WithHelloWorldApp(func(dir string) { 99 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-create-package", appName) 100 Eventually(pkgSession).Should(Exit(0)) 101 regex, err := regexp.Compile(`package guid: (.+)`) 102 Expect(err).ToNot(HaveOccurred()) 103 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 104 Expect(matches).To(HaveLen(2)) 105 106 packageGUID = matches[1] 107 }) 108 109 stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID) 110 Eventually(stageSession).Should(Exit(0)) 111 112 regex, err := regexp.Compile(`droplet guid:\s+(.+)`) 113 Expect(err).ToNot(HaveOccurred()) 114 matches := regex.FindStringSubmatch(string(stageSession.Out.Contents())) 115 Expect(matches).To(HaveLen(2)) 116 117 dropletGUID := matches[1] 118 setDropletSession := helpers.CF("v3-set-droplet", appName, "--droplet-guid", dropletGUID) 119 Eventually(setDropletSession).Should(Exit(0)) 120 }) 121 122 It("starts the app", func() { 123 userName, _ := helpers.GetCredentials() 124 125 session := helpers.CF("v3-start", appName) 126 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 127 Eventually(session).Should(Say("OK")) 128 129 Eventually(session).Should(Exit(0)) 130 }) 131 132 When("the app is already started", func() { 133 BeforeEach(func() { 134 Eventually(helpers.CF("v3-start", appName)).Should(Exit(0)) 135 }) 136 137 It("displays app already started and exits 0", func() { 138 session := helpers.CF("v3-start", appName) 139 140 Eventually(session.Err).Should(Say("App %s is already started", appName)) 141 Eventually(session).Should(Say("OK")) 142 143 Eventually(session).Should(Exit(0)) 144 }) 145 }) 146 }) 147 148 When("the app does not exist", func() { 149 It("displays app not found and exits 1", func() { 150 invalidAppName := "invalid-app-name" 151 session := helpers.CF("v3-start", invalidAppName) 152 153 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 154 Eventually(session).Should(Say("FAILED")) 155 156 Eventually(session).Should(Exit(1)) 157 }) 158 }) 159 }) 160 })