github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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("SEE ALSO:")) 46 Eventually(session).Should(Say("set-space-isolation-segment, space-quotas, spaces, target")) 47 Eventually(session).Should(Exit(0)) 48 }) 49 }) 50 }) 51 52 When("the space name is not provided", func() { 53 It("tells the user that the space name is required, prints help text, and exits 1", func() { 54 session := helpers.CF("create-space") 55 56 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE` was not provided")) 57 Eventually(session).Should(Say("NAME:")) 58 Eventually(session).Should(Exit(1)) 59 }) 60 }) 61 62 When("the environment is not setup correctly", func() { 63 It("fails with the appropriate errors", func() { 64 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-space", spaceNameNew) 65 }) 66 }) 67 68 When("the environment is set up correctly", func() { 69 BeforeEach(func() { 70 helpers.SetupCF(orgName, spaceName) 71 }) 72 73 AfterEach(func() { 74 helpers.QuickDeleteOrg(orgName) 75 }) 76 77 When("org does not exist", func() { 78 It("tells the user that the org does not exist, prints help text, and exits 1", func() { 79 session := helpers.CF("create-space", spaceNameNew, "-o", "not-an-org") 80 81 Eventually(session.Err).Should(Say("Organization 'not-an-org' not found.")) 82 Eventually(session).Should(Exit(1)) 83 }) 84 }) 85 86 When("the space does not exist", func() { 87 88 When("the actor is a user", func() { 89 90 It("creates the space in the targeted org", func() { 91 session := helpers.CF("create-space", spaceNameNew) 92 userName, _ := helpers.GetCredentials() 93 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, userName)) 94 Eventually(session).Should(Say("OK")) 95 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s" -s "%s"' to target new space`, orgName, spaceNameNew)) 96 Eventually(session).Should(Exit(0)) 97 98 session = helpers.CF("space", spaceNameNew) 99 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 100 Eventually(session).Should(Exit(0)) 101 }) 102 }) 103 104 When("the actor is a client", func() { 105 var clientID string 106 107 BeforeEach(func() { 108 clientID = helpers.LoginCFWithClientCredentials() 109 helpers.TargetOrg(orgName) 110 }) 111 112 It("creates the space in the targeted org", func() { 113 session := helpers.CF("create-space", spaceNameNew) 114 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, clientID)) 115 Eventually(session).Should(Say("OK")) 116 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s" -s "%s"' to target new space`, orgName, spaceNameNew)) 117 Eventually(session).Should(Exit(0)) 118 119 session = helpers.CF("space", spaceNameNew) 120 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 121 Eventually(session).Should(Exit(0)) 122 123 session = helpers.CF("space-users", orgName, spaceNameNew) 124 Eventually(session).Should(Say("SPACE MANAGER")) 125 Eventually(session).Should(Say(`\s+%s \(client\)`, clientID)) 126 Eventually(session).Should(Say("SPACE DEVELOPER")) 127 Eventually(session).Should(Say(`\s+%s \(client\)`, clientID)) 128 }) 129 }) 130 131 When("org is specified", func() { 132 BeforeEach(func() { 133 helpers.CreateOrg(otherOrgName) 134 }) 135 136 AfterEach(func() { 137 helpers.QuickDeleteOrg(otherOrgName) 138 }) 139 140 It("creates the space in the specified org and assigns roles to the user", func() { 141 session := helpers.CF("create-space", spaceNameNew, "-o", otherOrgName) 142 143 userName, _ := helpers.GetCredentials() 144 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, otherOrgName, userName)) 145 Eventually(session).Should(Say("OK")) 146 Eventually(session).Should(Say(`Assigning role SpaceManager to user %s in org %s / space %s as %s\.\.\.`, userName, otherOrgName, spaceNameNew, userName)) 147 Eventually(session).Should(Say(`OK\n`)) 148 Eventually(session).Should(Say(`Assigning role SpaceDeveloper to user %s in org %s / space %s as %s\.\.\.`, userName, otherOrgName, spaceNameNew, userName)) 149 Eventually(session).Should(Say(`OK\n\n`)) 150 Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s" -s "%s"' to target new space`, otherOrgName, spaceNameNew)) 151 Eventually(session).Should(Exit(0)) 152 153 helpers.TargetOrg(otherOrgName) 154 session = helpers.CF("space", spaceNameNew) 155 Eventually(session).Should(Say(`name:\s+%s`, spaceNameNew)) 156 Eventually(session).Should(Exit(0)) 157 158 session = helpers.CF("space-users", otherOrgName, spaceNameNew) 159 Eventually(session).Should(Say("SPACE MANAGER")) 160 Eventually(session).Should(Say(`\s+%s`, userName)) 161 Eventually(session).Should(Say("SPACE DEVELOPER")) 162 Eventually(session).Should(Say(`\s+%s`, userName)) 163 }) 164 }) 165 }) 166 167 When("the space already exists", func() { 168 BeforeEach(func() { 169 Eventually(helpers.CF("create-space", spaceNameNew)).Should(Exit(0)) 170 }) 171 172 It("fails to create the space", func() { 173 session := helpers.CF("create-space", spaceNameNew) 174 userName, _ := helpers.GetCredentials() 175 Eventually(session).Should(Say("Creating space %s in org %s as %s...", spaceNameNew, orgName, userName)) 176 Eventually(session).Should(Say(`Space '%s' already exists\.`, spaceNameNew)) 177 Eventually(session).Should(Say("OK")) 178 Eventually(session).Should(Exit(0)) 179 }) 180 }) 181 }) 182 })