github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/integration/shared/experimental/v3_droplets_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-droplets 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.NewAppName() 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-droplets", "--help") 30 31 Eventually(session).Should(Say("NAME:")) 32 Eventually(session).Should(Say("v3-droplets - List droplets of an app")) 33 Eventually(session).Should(Say("USAGE:")) 34 Eventually(session).Should(Say("cf v3-droplets 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-droplets") 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-droplets", 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 When("no API endpoint is set", func() { 59 BeforeEach(func() { 60 helpers.UnsetAPI() 61 }) 62 63 It("fails with no API endpoint set message", func() { 64 session := helpers.CF("v3-droplets", appName) 65 Eventually(session).Should(Say("FAILED")) 66 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 67 Eventually(session).Should(Exit(1)) 68 }) 69 }) 70 71 When("the v3 api version is lower than the minimum version", func() { 72 var server *Server 73 74 BeforeEach(func() { 75 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 76 }) 77 78 AfterEach(func() { 79 server.Close() 80 }) 81 82 It("fails with error message that the minimum version is not met", func() { 83 session := helpers.CF("v3-droplets", appName) 84 Eventually(session).Should(Say("FAILED")) 85 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 86 Eventually(session).Should(Exit(1)) 87 }) 88 }) 89 90 When("not logged in", func() { 91 BeforeEach(func() { 92 helpers.LogoutCF() 93 }) 94 95 It("fails with not logged in message", func() { 96 session := helpers.CF("v3-droplets", appName) 97 Eventually(session).Should(Say("FAILED")) 98 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 99 Eventually(session).Should(Exit(1)) 100 }) 101 }) 102 103 When("there is no org set", func() { 104 BeforeEach(func() { 105 helpers.LogoutCF() 106 helpers.LoginCF() 107 }) 108 109 It("fails with no org targeted error message", func() { 110 session := helpers.CF("v3-droplets", appName) 111 Eventually(session).Should(Say("FAILED")) 112 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 113 Eventually(session).Should(Exit(1)) 114 }) 115 }) 116 117 When("there is no space set", func() { 118 BeforeEach(func() { 119 helpers.LogoutCF() 120 helpers.LoginCF() 121 helpers.TargetOrg(ReadOnlyOrg) 122 }) 123 124 It("fails with no space targeted error message", func() { 125 session := helpers.CF("v3-droplets", appName) 126 Eventually(session).Should(Say("FAILED")) 127 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 128 Eventually(session).Should(Exit(1)) 129 }) 130 }) 131 }) 132 133 When("the environment is set up correctly", func() { 134 var userName string 135 136 BeforeEach(func() { 137 helpers.SetupCF(orgName, spaceName) 138 userName, _ = helpers.GetCredentials() 139 }) 140 141 AfterEach(func() { 142 helpers.QuickDeleteOrg(orgName) 143 }) 144 145 When("the app does not exist", func() { 146 It("displays app not found and exits 1", func() { 147 session := helpers.CF("v3-droplets", appName) 148 149 Eventually(session).Should(Say("Listing droplets of app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 150 Eventually(session.Err).Should(Say("App %s not found", appName)) 151 Eventually(session).Should(Say("FAILED")) 152 153 Eventually(session).Should(Exit(1)) 154 }) 155 }) 156 157 When("the app exists", func() { 158 Context("with no droplets", func() { 159 BeforeEach(func() { 160 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 161 }) 162 163 It("displays empty list", func() { 164 session := helpers.CF("v3-droplets", appName) 165 Eventually(session).Should(Say("Listing droplets of app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 166 Eventually(session).Should(Say("No droplets found")) 167 Eventually(session).Should(Exit(0)) 168 }) 169 }) 170 171 Context("with existing droplets", func() { 172 BeforeEach(func() { 173 helpers.WithHelloWorldApp(func(dir string) { 174 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-push", appName)).Should(Exit(0)) 175 }) 176 }) 177 178 It("displays droplets in the list", func() { 179 session := helpers.CF("v3-droplets", appName) 180 Eventually(session).Should(Say("Listing droplets of app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 181 Eventually(session).Should(Say("guid\\s+state\\s+created")) 182 Eventually(session).Should(Say("\\s+.*\\s+staged\\s+%s", helpers.UserFriendlyDateRegex)) 183 184 Eventually(session).Should(Exit(0)) 185 }) 186 }) 187 }) 188 }) 189 })