github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/create_space_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-space command", func() { 13 var ( 14 orgName string 15 otherOrgName string 16 spaceName string 17 spaceNameNew string 18 ) 19 20 BeforeEach(func() { 21 orgName = helpers.NewOrgName() 22 otherOrgName = helpers.NewOrgName() 23 spaceName = helpers.NewSpaceName() 24 spaceNameNew = helpers.PrefixedRandomName("space") 25 }) 26 27 Describe("help", func() { 28 When("--help flag is set", func() { 29 It("appears in cf help -a", func() { 30 session := helpers.CF("help", "-a") 31 Eventually(session).Should(Exit(0)) 32 Expect(session).To(HaveCommandInCategoryWithDescription("create-space", "SPACES", "Create a space")) 33 }) 34 35 It("Displays command usage to output", func() { 36 session := helpers.CF("create-space", "--help") 37 Eventually(session).Should(Say("NAME:")) 38 Eventually(session).Should(Say("create-space - Create a space")) 39 Eventually(session).Should(Say("USAGE:")) 40 Eventually(session).Should(Say(`cf create-space SPACE \[-o ORG\]`)) 41 Eventually(session).Should(Say("ALIAS:")) 42 Eventually(session).Should(Say(`csp`)) 43 Eventually(session).Should(Say("OPTIONS:")) 44 Eventually(session).Should(Say(`-o\s+Organization`)) 45 Eventually(session).Should(Say(`--quota, -q\s+Quota to assign to the newly created space`)) 46 Eventually(session).Should(Say("SEE ALSO:")) 47 Eventually(session).Should(Say("set-space-isolation-segment, space-quotas, spaces, target")) 48 Eventually(session).Should(Exit(0)) 49 }) 50 }) 51 }) 52 53 When("the space name is not provided", func() { 54 It("tells the user that the space name is required, prints help text, and exits 1", func() { 55 session := helpers.CF("create-space") 56 57 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE` was not provided")) 58 Eventually(session).Should(Say("NAME:")) 59 Eventually(session).Should(Exit(1)) 60 }) 61 }) 62 63 When("the environment is not setup correctly", func() { 64 It("fails with the appropriate errors", func() { 65 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-space", spaceNameNew) 66 }) 67 }) 68 69 When("the environment is set up correctly", func() { 70 BeforeEach(func() { 71 helpers.SetupCF(orgName, spaceName) 72 }) 73 74 AfterEach(func() { 75 helpers.QuickDeleteOrg(orgName) 76 }) 77 78 When("org does not exist", func() { 79 It("tells the user that the org does not exist, prints help text, and exits 1", func() { 80 session := helpers.CF("create-space", spaceNameNew, "-o", "not-an-org") 81 82 Eventually(session.Err).Should(Say("Organization 'not-an-org' not found.")) 83 Eventually(session).Should(Exit(1)) 84 }) 85 }) 86 87 When("the space does not exist", func() { 88 89 When("the actor is a user", func() { 90 91 It("creates the space in the targeted org", func() { 92 session := helpers.CF("create-space", spaceNameNew) 93 userName, _ := helpers.GetCredentials() 94 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, userName)) 95 Eventually(session).Should(Say("OK")) 96 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s" -s "%s"' to target new space`, orgName, spaceNameNew)) 97 Eventually(session).Should(Exit(0)) 98 99 session = helpers.CF("space", spaceNameNew) 100 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 101 Eventually(session).Should(Exit(0)) 102 }) 103 }) 104 105 When("the actor is a client", func() { 106 var clientID string 107 108 BeforeEach(func() { 109 clientID = helpers.LoginCFWithClientCredentials() 110 helpers.TargetOrg(orgName) 111 }) 112 113 It("creates the space in the targeted org", func() { 114 session := helpers.CF("create-space", spaceNameNew) 115 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, clientID)) 116 Eventually(session).Should(Say("OK")) 117 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s" -s "%s"' to target new space`, orgName, spaceNameNew)) 118 Eventually(session).Should(Exit(0)) 119 120 session = helpers.CF("space", spaceNameNew) 121 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 122 Eventually(session).Should(Exit(0)) 123 124 session = helpers.CF("space-users", orgName, spaceNameNew) 125 Eventually(session).Should(Say("SPACE MANAGER")) 126 Eventually(session).Should(Say(`\s+%s \(client\)`, clientID)) 127 Eventually(session).Should(Say("SPACE DEVELOPER")) 128 Eventually(session).Should(Say(`\s+%s \(client\)`, clientID)) 129 }) 130 }) 131 132 When("org is specified", func() { 133 BeforeEach(func() { 134 helpers.CreateOrg(otherOrgName) 135 }) 136 137 AfterEach(func() { 138 helpers.QuickDeleteOrg(otherOrgName) 139 }) 140 141 It("creates the space in the specified org and assigns roles to the user", func() { 142 session := helpers.CF("create-space", spaceNameNew, "-o", otherOrgName) 143 144 userName, _ := helpers.GetCredentials() 145 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, otherOrgName, userName)) 146 Eventually(session).Should(Say("OK")) 147 Eventually(session).Should(Say(`Assigning role SpaceManager to user %s in org %s / space %s as %s\.\.\.`, userName, otherOrgName, spaceNameNew, userName)) 148 Eventually(session).Should(Say(`OK\n`)) 149 Eventually(session).Should(Say(`Assigning role SpaceDeveloper to user %s in org %s / space %s as %s\.\.\.`, userName, otherOrgName, spaceNameNew, userName)) 150 Eventually(session).Should(Say(`OK\n\n`)) 151 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s" -s "%s"' to target new space`, otherOrgName, spaceNameNew)) 152 Eventually(session).Should(Exit(0)) 153 154 helpers.TargetOrg(otherOrgName) 155 session = helpers.CF("space", spaceNameNew) 156 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 157 Eventually(session).Should(Exit(0)) 158 159 session = helpers.CF("space-users", otherOrgName, spaceNameNew) 160 Eventually(session).Should(Say("SPACE MANAGER")) 161 Eventually(session).Should(Say(`\s+%s`, userName)) 162 Eventually(session).Should(Say("SPACE DEVELOPER")) 163 Eventually(session).Should(Say(`\s+%s`, userName)) 164 }) 165 }) 166 167 When("the --quota flag is passed", func() { 168 When("the quota does not exist", func() { 169 var ( 170 quotaName = "garb-quota" 171 ) 172 173 It("makes a space and informs the user setting the quota has failed", func() { 174 session := helpers.CF("create-space", spaceNameNew, "-q", quotaName) 175 userName, _ := helpers.GetCredentials() 176 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, userName)) 177 Eventually(session).Should(Say("OK")) 178 179 Eventually(session).Should(Say("Setting space quota %s to space %s as %s...", quotaName, spaceNameNew, userName)) 180 Eventually(session.Err).Should(Say("Space quota with name '%s' not found.", quotaName)) 181 Eventually(session).Should(Say("FAILED")) 182 183 session = helpers.CF("space", spaceNameNew) 184 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 185 Eventually(session).Should(Exit(0)) 186 }) 187 }) 188 189 When("the quota exists", func() { 190 var ( 191 quotaName = helpers.QuotaName() 192 ) 193 194 BeforeEach(func() { 195 Eventually(helpers.CF("create-space-quota", quotaName)).Should(Exit(0)) 196 }) 197 198 It("makes an org with the given quota", func() { 199 session := helpers.CF("create-space", spaceNameNew, "-q", quotaName) 200 userName, _ := helpers.GetCredentials() 201 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, userName)) 202 Eventually(session).Should(Say("OK")) 203 204 Eventually(session).Should(Say("Setting space quota %s to space %s as %s...", quotaName, spaceNameNew, userName)) 205 Eventually(session).Should(Say("OK")) 206 207 Eventually(session).Should(Say(`Assigning role SpaceManager to user %s in org %s / space %s as %s\.\.\.`, userName, orgName, spaceNameNew, userName)) 208 Eventually(session).Should(Say(`OK\n`)) 209 210 Eventually(session).Should(Say(`Assigning role SpaceDeveloper to user %s in org %s / space %s as %s\.\.\.`, userName, orgName, spaceNameNew, userName)) 211 Eventually(session).Should(Say(`OK\n\n`)) 212 213 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s" -s "%s"' to target new space`, orgName, spaceNameNew)) 214 215 Eventually(session).Should(Exit(0)) 216 217 session = helpers.CF("space", spaceNameNew) 218 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 219 Eventually(session).Should(Exit(0)) 220 }) 221 }) 222 }) 223 }) 224 225 When("the space already exists", func() { 226 BeforeEach(func() { 227 Eventually(helpers.CF("create-space", spaceNameNew)).Should(Exit(0)) 228 }) 229 230 It("fails to create the space", func() { 231 session := helpers.CF("create-space", spaceNameNew) 232 userName, _ := helpers.GetCredentials() 233 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, userName)) 234 Eventually(session).Should(Say(`Space '%s' already exists\.`, spaceNameNew)) 235 Eventually(session).Should(Say("OK")) 236 Eventually(session).Should(Exit(0)) 237 }) 238 }) 239 }) 240 })