github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v6/isolated/space_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("space command", func() { 16 var ( 17 orgName string 18 spaceName string 19 ) 20 21 BeforeEach(func() { 22 orgName = helpers.NewOrgName() 23 spaceName = helpers.NewSpaceName() 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("space", "--help") 30 Eventually(session).Should(Say("NAME:")) 31 Eventually(session).Should(Say("space - Show space info")) 32 Eventually(session).Should(Say("USAGE:")) 33 Eventually(session).Should(Say(`cf space SPACE \[--guid\] \[--security-group-rules\]`)) 34 Eventually(session).Should(Say("OPTIONS:")) 35 Eventually(session).Should(Say(`--guid\s+Retrieve and display the given space's guid\. All other output for the space is suppressed\.`)) 36 Eventually(session).Should(Say(`--security-group-rules\s+Retrieve the rules for all the security groups associated with the space\.`)) 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 var ( 84 securityGroup0 helpers.SecurityGroup 85 securityGroup1 helpers.SecurityGroup 86 securityGroupName2 string 87 securityGroupRules2 *os.File 88 err error 89 ) 90 91 BeforeEach(func() { 92 securityGroup0 = helpers.NewSecurityGroup(helpers.NewSecurityGroupName("0"), "tcp", "4.3.2.1/24", "80,443", "foo security group") 93 securityGroup0.Create() 94 Eventually(helpers.CF("bind-security-group", securityGroup0.Name, orgName, spaceName, "--lifecycle", "staging")).Should(Exit(0)) 95 96 securityGroup1 = helpers.NewSecurityGroup(helpers.NewSecurityGroupName("1"), "tcp", "1.2.3.4/24", "80,443", "some security group") 97 securityGroup1.Create() 98 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, orgName, spaceName)).Should(Exit(0)) 99 100 securityGroupName2 = helpers.NewSecurityGroupName("2") 101 securityGroupRules2, err = ioutil.TempFile("", "security-group-rules") 102 Expect(err).ToNot(HaveOccurred()) 103 104 _, err := securityGroupRules2.Write([]byte(` 105 [ 106 { 107 "protocol": "udp", 108 "destination": "92.0.0.1/24", 109 "ports": "80,443", 110 "description": "some other other security group" 111 }, 112 { 113 "protocol": "tcp", 114 "destination": "5.7.9.11/24", 115 "ports": "80,443", 116 "description": "some other security group" 117 } 118 ] 119 `)) 120 Expect(err).ToNot(HaveOccurred()) 121 122 Eventually(helpers.CF("create-security-group", securityGroupName2, securityGroupRules2.Name())).Should(Exit(0)) 123 os.Remove(securityGroupRules2.Name()) 124 125 Eventually(helpers.CF("bind-security-group", securityGroupName2, orgName, spaceName)).Should(Exit(0)) 126 Eventually(helpers.CF("bind-security-group", securityGroupName2, orgName, spaceName, "--lifecycle", "staging")).Should(Exit(0)) 127 }) 128 129 When("no flags are used", func() { 130 var ( 131 appName string 132 spaceQuotaName string 133 serviceInstance string 134 isolationSegmentName string 135 ) 136 137 BeforeEach(func() { 138 appName = helpers.PrefixedRandomName("app") 139 helpers.WithHelloWorldApp(func(appDir string) { 140 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 141 }) 142 serviceInstance = helpers.PrefixedRandomName("si") 143 Eventually(helpers.CF("create-user-provided-service", serviceInstance, "-p", "{}")).Should(Exit(0)) 144 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 145 spaceQuotaName = helpers.PrefixedRandomName("space-quota") 146 Eventually(helpers.CF("create-space-quota", spaceQuotaName)).Should(Exit(0)) 147 Eventually(helpers.CF("set-space-quota", spaceName, spaceQuotaName)).Should(Exit(0)) 148 149 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, orgName, spaceName)).Should(Exit(0)) 150 }) 151 152 It("displays a table with space name, org, apps, services, space quota and security groups", func() { 153 session := helpers.CF("space", spaceName) 154 userName, _ := helpers.GetCredentials() 155 Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, spaceName, orgName, userName)) 156 157 Eventually(session).Should(Say(`name:\s+%s`, spaceName)) 158 Eventually(session).Should(Say(`org:\s+%s`, orgName)) 159 Eventually(session).Should(Say(`apps:\s+%s`, appName)) 160 Eventually(session).Should(Say(`services:\s+%s`, serviceInstance)) 161 Eventually(session).Should(Say(`space quota:\s+%s`, spaceQuotaName)) 162 Eventually(session).Should(Say(`running security groups:\s+.*%s,.* %s`, securityGroup1.Name, securityGroupName2)) 163 Eventually(session).Should(Say(`staging security groups:\s+.*%s,.* %s`, securityGroup0.Name, securityGroupName2)) 164 Eventually(session).Should(Exit(0)) 165 }) 166 167 When("isolations segments are enabled", func() { 168 BeforeEach(func() { 169 isolationSegmentName = helpers.NewIsolationSegmentName() 170 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 171 Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName)).Should(Exit(0)) 172 Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0)) 173 }) 174 175 It("displays the isolation segment in the table", func() { 176 session := helpers.CF("space", spaceName) 177 userName, _ := helpers.GetCredentials() 178 Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, spaceName, orgName, userName)) 179 180 Eventually(session).Should(Say(`isolation segment:\s+%s`, isolationSegmentName)) 181 }) 182 }) 183 }) 184 185 When("the space does not have an isolation segment and its org has a default isolation segment", func() { 186 var orgIsolationSegmentName string 187 188 BeforeEach(func() { 189 orgIsolationSegmentName = helpers.NewIsolationSegmentName() 190 Eventually(helpers.CF("create-isolation-segment", orgIsolationSegmentName)).Should(Exit(0)) 191 Eventually(helpers.CF("enable-org-isolation", orgName, orgIsolationSegmentName)).Should(Exit(0)) 192 Eventually(helpers.CF("set-org-default-isolation-segment", orgName, orgIsolationSegmentName)).Should(Exit(0)) 193 }) 194 195 It("shows the org default isolation segment", func() { 196 session := helpers.CF("space", spaceName) 197 Eventually(session).Should(Say(`isolation segment:\s+%s`, orgIsolationSegmentName)) 198 Eventually(session).Should(Exit(0)) 199 }) 200 }) 201 202 When("the security group rules flag is used", func() { 203 It("displays the space information as well as all security group rules", func() { 204 session := helpers.CF("space", "--security-group-rules", spaceName) 205 userName, _ := helpers.GetCredentials() 206 Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, spaceName, orgName, userName)) 207 208 Eventually(session).Should(Say("name:")) 209 Eventually(session).Should(Say("org:")) 210 Eventually(session).Should(Say("apps:")) 211 Eventually(session).Should(Say("services:")) 212 Eventually(session).Should(Say("space quota:")) 213 Eventually(session).Should(Say("running security groups:")) 214 Eventually(session).Should(Say("staging security groups:")) 215 Eventually(session).Should(Say("\n\n")) 216 217 Eventually(session).Should(Say(`security group\s+destination\s+ports\s+protocol\s+lifecycle\s+description`)) 218 Eventually(session).Should(Say(`#\d+\s+%s\s+4.3.2.1/24\s+80,443\s+tcp\s+staging\s+foo security group`, securityGroup0.Name)) 219 Eventually(session).Should(Say(`#\d+\s+%s\s+1.2.3.4/24\s+80,443\s+tcp\s+running\s+some security group`, securityGroup1.Name)) 220 Eventually(session).Should(Say(`#\d+\s+%s\s+5.7.9.11/24\s+80,443\s+tcp\s+running\s+some other security group`, securityGroupName2)) 221 Eventually(session).Should(Say(`\s+%s\s+5.7.9.11/24\s+80,443\s+tcp\s+staging\s+some other security group`, securityGroupName2)) 222 Eventually(session).Should(Say(`\s+%s\s+92.0.0.1/24\s+80,443\s+udp\s+running\s+some other other security group`, securityGroupName2)) 223 Eventually(session).Should(Say(`\s+%s\s+92.0.0.1/24\s+80,443\s+udp\s+staging\s+some other other security group`, securityGroupName2)) 224 Eventually(session).Should(Exit(0)) 225 }) 226 }) 227 }) 228 }) 229 }) 230 })