github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/global/unbind_security_group_command_test.go (about) 1 package global 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("unbind-security-group command", func() { 12 var ( 13 orgName string 14 securityGroupName string 15 spaceName string 16 ) 17 18 BeforeEach(func() { 19 orgName = helpers.NewOrgName() 20 securityGroupName = helpers.NewSecurityGroupName() 21 spaceName = helpers.NewSpaceName() 22 23 helpers.LoginCF() 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("unbind-security-group", "--help") 30 Eventually(session).Should(Say("NAME:")) 31 Eventually(session).Should(Say(`\s+unbind-security-group - Unbind a security group from a space`)) 32 Eventually(session).Should(Say("USAGE:")) 33 Eventually(session).Should(Say(`\s+cf unbind-security-group SECURITY_GROUP ORG SPACE \[--lifecycle \(running \| staging\)\]`)) 34 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 35 Eventually(session).Should(Say("OPTIONS:")) 36 Eventually(session).Should(Say(`\s+--lifecycle Lifecycle phase the group applies to \(Default: running\)`)) 37 Eventually(session).Should(Say("SEE ALSO:")) 38 Eventually(session).Should(Say(`\s+apps, restart, security-groups`)) 39 Eventually(session).Should(Exit(0)) 40 }) 41 }) 42 }) 43 44 When("the lifecycle flag is invalid", func() { 45 It("outputs a message and usage", func() { 46 session := helpers.CF("unbind-security-group", securityGroupName, "some-org", "some-space", "--lifecycle", "invalid") 47 Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `invalid' for option `--lifecycle'. Allowed values are: running or staging")) 48 Eventually(session).Should(Say("USAGE:")) 49 Eventually(session).Should(Exit(1)) 50 }) 51 }) 52 53 When("the lifecycle flag has no argument", func() { 54 It("outputs a message and usage", func() { 55 session := helpers.CF("unbind-security-group", securityGroupName, "some-org", "some-space", "--lifecycle") 56 Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `--lifecycle'")) 57 Eventually(session).Should(Say("USAGE:")) 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, "unbind-security-group", securityGroupName, "some-org", "some-space") 65 }) 66 }) 67 68 When("the input is invalid", func() { 69 When("the security group is not provided", func() { 70 It("fails with an incorrect usage message and displays help", func() { 71 session := helpers.CF("unbind-security-group") 72 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SECURITY_GROUP`, `ORG` and `SPACE` were not provided")) 73 Eventually(session).Should(Say("USAGE:")) 74 Eventually(session).Should(Exit(1)) 75 }) 76 }) 77 78 When("the space is not provided", func() { 79 It("fails with an incorrect usage message and displays help", func() { 80 session := helpers.CF("unbind-security-group", securityGroupName, "some-org") 81 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE` was not provided")) 82 Eventually(session).Should(Say("USAGE:")) 83 Eventually(session).Should(Exit(1)) 84 }) 85 }) 86 }) 87 88 When("the security group doesn't exist", func() { 89 BeforeEach(func() { 90 helpers.CreateOrgAndSpace(orgName, spaceName) 91 }) 92 93 AfterEach(func() { 94 helpers.QuickDeleteOrg(orgName) 95 }) 96 97 It("fails with a 'security group not found' message", func() { 98 session := helpers.CF("unbind-security-group", "some-other-security-group", orgName, spaceName) 99 Eventually(session).Should(Say("FAILED")) 100 Eventually(session.Err).Should(Say(`Security group 'some-other-security-group' not found\.`)) 101 Eventually(session).Should(Exit(1)) 102 }) 103 }) 104 105 When("the security group exists", func() { 106 BeforeEach(func() { 107 port := "8443" 108 description := "some-description" 109 someSecurityGroup := helpers.NewSecurityGroup(securityGroupName, "tcp", "127.0.0.1", &port, &description) 110 helpers.CreateSecurityGroup(someSecurityGroup) 111 }) 112 113 When("the org doesn't exist", func() { 114 It("fails with an 'org not found' message", func() { 115 session := helpers.CF("unbind-security-group", securityGroupName, "some-other-org", "some-other-space") 116 Eventually(session).Should(Say("FAILED")) 117 Eventually(session.Err).Should(Say(`Organization 'some-other-org' not found\.`)) 118 Eventually(session).Should(Exit(1)) 119 }) 120 }) 121 122 When("the org exists", func() { 123 var username string 124 125 BeforeEach(func() { 126 username, _ = helpers.GetCredentials() 127 128 helpers.CreateOrg(orgName) 129 helpers.TargetOrg(orgName) 130 }) 131 132 AfterEach(func() { 133 helpers.QuickDeleteOrg(orgName) 134 }) 135 136 When("the space doesn't exist", func() { 137 It("fails with a 'space not found' message", func() { 138 session := helpers.CF("unbind-security-group", securityGroupName, orgName, "some-other-space") 139 Eventually(session).Should(Say("FAILED")) 140 Eventually(session.Err).Should(Say(`Space 'some-other-space' not found\.`)) 141 Eventually(session).Should(Exit(1)) 142 }) 143 }) 144 145 When("the space exists", func() { 146 BeforeEach(func() { 147 helpers.CreateSpace(spaceName) 148 }) 149 150 When("the space isn't bound to the security group in any lifecycle", func() { 151 It("successfully runs the command", func() { 152 session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName) 153 Eventually(session).Should(Say(`Unbinding running security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username)) 154 Eventually(session.Err).Should(Say(`Security group %s not bound to space %s for lifecycle phase 'running'\.`, securityGroupName, spaceName)) 155 Eventually(session).Should(Say("OK")) 156 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 157 Eventually(session).Should(Exit(0)) 158 }) 159 }) 160 161 When("a space is bound to a security group in the running lifecycle", func() { 162 BeforeEach(func() { 163 Eventually(helpers.CF("bind-security-group", securityGroupName, orgName, "--space", spaceName)).Should(Exit(0)) 164 }) 165 166 When("the lifecycle flag is not set", func() { 167 BeforeEach(func() { 168 helpers.ClearTarget() 169 }) 170 171 It("successfully unbinds the space from the security group", func() { 172 session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName) 173 Eventually(session).Should(Say(`Unbinding running security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username)) 174 Eventually(session).Should(Say("OK")) 175 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 176 Eventually(session).Should(Exit(0)) 177 }) 178 }) 179 180 When("the lifecycle flag is running", func() { 181 BeforeEach(func() { 182 helpers.ClearTarget() 183 }) 184 185 It("successfully unbinds the space from the security group", func() { 186 session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "running") 187 Eventually(session).Should(Say(`Unbinding running security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username)) 188 Eventually(session).Should(Say("OK")) 189 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 190 Eventually(session).Should(Exit(0)) 191 }) 192 }) 193 194 When("the lifecycle flag is staging", func() { 195 BeforeEach(func() { 196 helpers.ClearTarget() 197 }) 198 199 It("displays an error and exits 1", func() { 200 session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging") 201 Eventually(session).Should(Say(`Unbinding staging security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username)) 202 Eventually(session).Should(Say("OK")) 203 Eventually(session.Err).Should(Say(`Security group %s not bound to space %s for lifecycle phase 'staging'\.`, securityGroupName, spaceName)) 204 Eventually(session).Should(Exit(0)) 205 }) 206 }) 207 }) 208 209 When("a space is bound to a security group in the staging lifecycle", func() { 210 BeforeEach(func() { 211 Eventually(helpers.CF("bind-security-group", securityGroupName, orgName, "--space", spaceName, "--lifecycle", "staging")).Should(Exit(0)) 212 }) 213 214 When("the lifecycle flag is not set", func() { 215 BeforeEach(func() { 216 helpers.ClearTarget() 217 }) 218 219 It("displays an error and exits 1", func() { 220 session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName) 221 Eventually(session).Should(Say(`Unbinding running security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username)) 222 Eventually(session).Should(Say("OK")) 223 Eventually(session.Err).Should(Say(`Security group %s not bound to space %s for lifecycle phase 'running'\.`, securityGroupName, spaceName)) 224 Eventually(session).Should(Exit(0)) 225 }) 226 }) 227 228 When("the lifecycle flag is running", func() { 229 BeforeEach(func() { 230 helpers.ClearTarget() 231 }) 232 233 It("displays an error and exits 1", func() { 234 session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "running") 235 Eventually(session).Should(Say(`Unbinding running security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username)) 236 Eventually(session).Should(Say("OK")) 237 Eventually(session.Err).Should(Say(`Security group %s not bound to space %s for lifecycle phase 'running'\.`, securityGroupName, spaceName)) 238 Eventually(session).Should(Exit(0)) 239 }) 240 }) 241 242 When("the lifecycle flag is staging", func() { 243 BeforeEach(func() { 244 helpers.ClearTarget() 245 }) 246 247 It("successfully unbinds the space from the security group", func() { 248 session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging") 249 Eventually(session).Should(Say(`Unbinding staging security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username)) 250 Eventually(session).Should(Say("OK")) 251 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 252 Eventually(session).Should(Exit(0)) 253 }) 254 }) 255 }) 256 }) 257 }) 258 }) 259 })