github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/isolated/space_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 "code.cloudfoundry.org/cli/resources" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gbytes" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("space command", func() { 17 var ( 18 orgName string 19 spaceName string 20 ) 21 22 BeforeEach(func() { 23 orgName = helpers.NewOrgName() 24 spaceName = helpers.NewSpaceName() 25 }) 26 27 Describe("help", func() { 28 When("--help flag is set", func() { 29 It("Displays command usage to output", func() { 30 session := helpers.CF("space", "--help") 31 Eventually(session).Should(Say("NAME:")) 32 Eventually(session).Should(Say("space - Show space info")) 33 Eventually(session).Should(Say("USAGE:")) 34 Eventually(session).Should(Say(`cf space SPACE \[--guid\]`)) 35 Eventually(session).Should(Say("OPTIONS:")) 36 Eventually(session).Should(Say(`--guid\s+Retrieve and display the given space's guid\. All other output for the space is suppressed\.`)) 37 Eventually(session).Should(Say("SEE ALSO:")) 38 Eventually(session).Should(Say("set-space-isolation-segment, space-quota, space-users")) 39 Eventually(session).Should(Exit(0)) 40 }) 41 }) 42 }) 43 44 When("the environment is not setup correctly", func() { 45 It("fails with the appropriate errors", func() { 46 helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "space", "space-name") 47 }) 48 }) 49 50 When("the environment is set up correctly", func() { 51 BeforeEach(func() { 52 helpers.LoginCF() 53 helpers.SetupCF(orgName, spaceName) 54 }) 55 56 AfterEach(func() { 57 helpers.QuickDeleteOrg(orgName) 58 helpers.ClearTarget() 59 }) 60 61 When("the space does not exist", func() { 62 It("displays not found and exits 1", func() { 63 badSpaceName := fmt.Sprintf("%s-1", spaceName) 64 session := helpers.CF("space", badSpaceName) 65 userName, _ := helpers.GetCredentials() 66 Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, badSpaceName, orgName, userName)) 67 Eventually(session).Should(Say("FAILED")) 68 Eventually(session.Err).Should(Say("Space '%s' not found.", badSpaceName)) 69 Eventually(session).Should(Exit(1)) 70 }) 71 }) 72 73 When("the space exists", func() { 74 When("the --guid flag is used", func() { 75 It("displays the space guid", func() { 76 session := helpers.CF("space", "--guid", spaceName) 77 Eventually(session).Should(Say(`[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}`)) 78 Eventually(session).Should(Exit(0)) 79 }) 80 }) 81 82 When("the --guid flag is not used", func() { 83 When("no flags are used", func() { 84 var ( 85 appName string 86 isolationSegmentName string 87 ) 88 89 BeforeEach(func() { 90 appName = helpers.PrefixedRandomName("app") 91 helpers.WithHelloWorldApp(func(appDir string) { 92 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 93 }) 94 }) 95 96 It("displays a table with space name, org and apps", func() { 97 session := helpers.CF("space", spaceName) 98 userName, _ := helpers.GetCredentials() 99 Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, spaceName, orgName, userName)) 100 101 Eventually(session).Should(Say(`name:\s+%s`, spaceName)) 102 Eventually(session).Should(Say(`org:\s+%s`, orgName)) 103 Eventually(session).Should(Say(`apps:\s+%s`, appName)) 104 Eventually(session).Should(Say(`services:`)) 105 Eventually(session).Should(Say("isolation segment:")) 106 Eventually(session).Should(Say("quota:")) 107 Eventually(session).Should(Say(`running security groups:\s+(.*)dns`)) 108 Eventually(session).Should(Say(`staging security groups:\s+(.*)dns`)) 109 Eventually(session).Should(Exit(0)) 110 }) 111 112 When("isolation segments are enabled", func() { 113 BeforeEach(func() { 114 isolationSegmentName = helpers.NewIsolationSegmentName() 115 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 116 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName)).Should(Exit(0)) 117 Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0)) 118 }) 119 120 It("displays the isolation segment in the table", func() { 121 session := helpers.CF("space", spaceName) 122 userName, _ := helpers.GetCredentials() 123 124 Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, spaceName, orgName, userName)) 125 Eventually(session).Should(Say(`isolation segment:\s+%s`, isolationSegmentName)) 126 }) 127 }) 128 }) 129 130 When("the --security-group-rules flag is used", func() { 131 var ( 132 ports string 133 description string 134 runningSecurityGroup resources.SecurityGroup 135 stagingSecurityGroup resources.SecurityGroup 136 ) 137 138 BeforeEach(func() { 139 ports = "25,465,587" 140 description = "Email our friends" 141 runningSecurityGroup = helpers.NewSecurityGroup( 142 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP-A"), 143 "tcp", 144 "0.0.0.0/0", 145 &ports, 146 &description, 147 ) 148 stagingSecurityGroup = helpers.NewSecurityGroup( 149 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP-B"), 150 "tcp", 151 "0.0.0.0/0", 152 &ports, 153 &description, 154 ) 155 helpers.CreateSecurityGroup(runningSecurityGroup) 156 helpers.CreateSecurityGroup(stagingSecurityGroup) 157 session1 := helpers.CF("bind-security-group", runningSecurityGroup.Name, orgName, "--lifecycle", "running") 158 session2 := helpers.CF("bind-security-group", stagingSecurityGroup.Name, orgName, "--lifecycle", "staging") 159 160 Eventually(session1).Should(Exit(0)) 161 Eventually(session2).Should(Exit(0)) 162 }) 163 164 AfterEach(func() { 165 helpers.DeleteSecurityGroup(runningSecurityGroup) 166 helpers.DeleteSecurityGroup(stagingSecurityGroup) 167 }) 168 169 It("shows the security groups applied to that space", func() { 170 session := helpers.CF("space", spaceName, "--security-group-rules") 171 Eventually(session).Should(Say(`running security groups:\s+(.*)+%s`, runningSecurityGroup.Name)) 172 Eventually(session).Should(Say(`staging security groups:\s+(.*)+%s`, stagingSecurityGroup.Name)) 173 174 Eventually(session).Should(Say(`security group\s+destination\s+ports\s+protocol\s+lifecycle\s+description`)) 175 Eventually(session).Should(Say(`%s\s+0.0.0.0/0\s+%s\s+tcp\s+running\s+%s`, runningSecurityGroup.Name, ports, description)) 176 Eventually(session).Should(Say(`%s\s+0.0.0.0/0\s+%s\s+tcp\s+staging\s+%s`, stagingSecurityGroup.Name, ports, description)) 177 178 Eventually(session).Should(Exit(0)) 179 }) 180 }) 181 182 When("the space does not have an isolation segment and its org has a default isolation segment", func() { 183 var orgIsolationSegmentName string 184 185 BeforeEach(func() { 186 orgIsolationSegmentName = helpers.NewIsolationSegmentName() 187 Eventually(helpers.CF("create-isolation-segment", orgIsolationSegmentName)).Should(Exit(0)) 188 Eventually(helpers.CF("enable-org-isolation", orgName, orgIsolationSegmentName)).Should(Exit(0)) 189 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, orgIsolationSegmentName)).Should(Exit(0)) 190 }) 191 192 It("shows the org default isolation segment", func() { 193 session := helpers.CF("space", spaceName) 194 Eventually(session).Should(Say(`isolation segment:\s+%s \(org default\)`, orgIsolationSegmentName)) 195 Eventually(session).Should(Exit(0)) 196 }) 197 }) 198 199 When("the space has service instances", func() { 200 var ( 201 service string 202 servicePlan string 203 serviceInstanceName string 204 broker *servicebrokerstub.ServiceBrokerStub 205 ) 206 207 BeforeEach(func() { 208 broker = servicebrokerstub.EnableServiceAccess() 209 service = broker.FirstServiceOfferingName() 210 servicePlan = broker.FirstServicePlanName() 211 serviceInstanceName = helpers.NewServiceInstanceName() 212 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName)).Should(Exit(0)) 213 }) 214 215 AfterEach(func() { 216 broker.Forget() 217 }) 218 219 It("shows the service instance", func() { 220 session := helpers.CF("space", spaceName) 221 Eventually(session).Should(Say(`services:\s+%s`, serviceInstanceName)) 222 Eventually(session).Should(Exit(0)) 223 }) 224 }) 225 226 When("the space has an applied quota", func() { 227 var spaceQuotaName = helpers.QuotaName() 228 BeforeEach(func() { 229 session := helpers.CF("create-space-quota", spaceQuotaName) 230 Eventually(session).Should(Exit(0)) 231 232 session = helpers.CF("set-space-quota", spaceName, spaceQuotaName) 233 Eventually(session).Should(Exit(0)) 234 }) 235 236 It("shows the applied quota", func() { 237 session := helpers.CF("space", spaceName) 238 Eventually(session).Should(Say(`quota:\s+%s`, spaceQuotaName)) 239 Eventually(session).Should(Exit(0)) 240 }) 241 }) 242 }) 243 }) 244 }) 245 })