github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v6/isolated/bind_security_group_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 "code.cloudfoundry.org/cli/resources" 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("bind-security-group command", func() { 13 var ( 14 orgName string 15 secGroupName string 16 someOrgName string 17 spaceName1 string 18 spaceName2 string 19 ) 20 21 BeforeEach(func() { 22 orgName = helpers.NewOrgName() 23 secGroupName = helpers.NewSecurityGroupName() 24 someOrgName = helpers.NewOrgName() 25 spaceName1 = helpers.NewSpaceName() 26 spaceName2 = helpers.NewSpaceName() 27 28 helpers.LoginCF() 29 }) 30 31 Describe("help", func() { 32 When("--help flag is set", func() { 33 It("Displays command usage to output", func() { 34 session := helpers.CF("bind-security-group", "--help") 35 Eventually(session).Should(Say("NAME:")) 36 Eventually(session).Should(Say(`\s+bind-security-group - Bind a security group to a particular space, or all existing spaces of an org`)) 37 Eventually(session).Should(Say("USAGE:")) 38 Eventually(session).Should(Say(`\s+cf bind-security-group SECURITY_GROUP ORG \[SPACE\] \[--lifecycle \(running \| staging\)\]`)) 39 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 40 Eventually(session).Should(Say("OPTIONS:")) 41 Eventually(session).Should(Say(`\s+--lifecycle Lifecycle phase the group applies to \(Default: running\)`)) 42 Eventually(session).Should(Say("SEE ALSO:")) 43 Eventually(session).Should(Say(`\s+apps, bind-running-security-group, bind-staging-security-group, restart, security-groups`)) 44 Eventually(session).Should(Exit(0)) 45 }) 46 }) 47 }) 48 49 When("the lifecycle flag is invalid", func() { 50 It("outputs a message and usage", func() { 51 session := helpers.CF("bind-security-group", secGroupName, someOrgName, "--lifecycle", "invalid") 52 Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `invalid' for option `--lifecycle'. Allowed values are: running or staging")) 53 Eventually(session).Should(Say("USAGE:")) 54 Eventually(session).Should(Exit(1)) 55 }) 56 }) 57 58 When("the lifecycle flag has no argument", func() { 59 It("outputs a message and usage", func() { 60 session := helpers.CF("bind-security-group", secGroupName, someOrgName, "--lifecycle") 61 Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `--lifecycle'")) 62 Eventually(session).Should(Say("USAGE:")) 63 Eventually(session).Should(Exit(1)) 64 }) 65 }) 66 67 When("the environment is not setup correctly", func() { 68 It("fails with the appropriate errors", func() { 69 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "bind-security-group", "security-group-name", "org-name", "space-name") 70 }) 71 }) 72 73 When("the input is invalid", func() { 74 When("the security group is not provided", func() { 75 It("fails with an incorrect usage message and displays help", func() { 76 session := helpers.CF("bind-security-group") 77 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SECURITY_GROUP` and `ORG` were not provided")) 78 Eventually(session).Should(Say("USAGE:")) 79 Eventually(session).Should(Exit(1)) 80 }) 81 }) 82 83 When("the org is not provided", func() { 84 It("fails with an incorrect usage message and displays help", func() { 85 session := helpers.CF("bind-security-group", secGroupName) 86 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided")) 87 Eventually(session).Should(Say("USAGE:")) 88 Eventually(session).Should(Exit(1)) 89 }) 90 }) 91 }) 92 93 When("the security group doesn't exist", func() { 94 It("fails with a security group not found message", func() { 95 session := helpers.CF("bind-security-group", "some-security-group-that-doesn't-exist", someOrgName) 96 Eventually(session.Err).Should(Say("Security group 'some-security-group-that-doesn't-exist' not found.")) 97 Eventually(session).Should(Say("FAILED")) 98 Eventually(session).Should(Exit(1)) 99 }) 100 }) 101 102 When("the security group exists", func() { 103 var ( 104 someSecurityGroup resources.SecurityGroup 105 ports string 106 description string 107 ) 108 109 BeforeEach(func() { 110 ports = "53" 111 description = "SG" 112 someSecurityGroup = helpers.NewSecurityGroup(secGroupName, "tcp", "0.0.0.0/0", &ports, &description) 113 helpers.CreateSecurityGroup(someSecurityGroup) 114 }) 115 116 When("the org doesn't exist", func() { 117 It("fails with an org not found message", func() { 118 session := helpers.CF("bind-security-group", secGroupName, someOrgName) 119 Eventually(session.Err).Should(Say("Organization '%s' not found.", someOrgName)) 120 Eventually(session).Should(Say("FAILED")) 121 Eventually(session).Should(Exit(1)) 122 }) 123 }) 124 125 When("the org exists", func() { 126 BeforeEach(func() { 127 helpers.CreateOrg(orgName) 128 helpers.TargetOrg(orgName) 129 }) 130 131 AfterEach(func() { 132 helpers.QuickDeleteOrg(orgName) 133 }) 134 135 When("the space doesn't exist", func() { 136 It("fails with a space not found message", func() { 137 session := helpers.CF("bind-security-group", secGroupName, orgName, "space-doesnt-exist") 138 Eventually(session.Err).Should(Say("Space 'space-doesnt-exist' not found.")) 139 Eventually(session).Should(Say("FAILED")) 140 Eventually(session).Should(Exit(1)) 141 }) 142 }) 143 144 When("there are no spaces in this org", func() { 145 It("does not bind the security group to any space", func() { 146 session := helpers.CF("bind-security-group", secGroupName, orgName) 147 Consistently(session).ShouldNot(Say("Assigning security group")) 148 Consistently(session).ShouldNot(Say("OK")) 149 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 150 Eventually(session).Should(Exit(0)) 151 }) 152 }) 153 154 When("there are spaces in this org", func() { 155 BeforeEach(func() { 156 helpers.CreateSpace(spaceName1) 157 helpers.CreateSpace(spaceName2) 158 }) 159 160 When("the lifecycle flag is not set", func() { 161 When("binding to all spaces in an org", func() { 162 It("binds the security group to each space", func() { 163 session := helpers.CF("bind-security-group", secGroupName, orgName) 164 userName, _ := helpers.GetCredentials() 165 Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName)) 166 Eventually(session).Should(Say("OK")) 167 Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName)) 168 Eventually(session).Should(Say("OK")) 169 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 170 Eventually(session).Should(Exit(0)) 171 }) 172 }) 173 }) 174 175 When("binding to a particular space", func() { 176 It("binds the security group to the space", func() { 177 session := helpers.CF("bind-security-group", secGroupName, orgName, spaceName1) 178 userName, _ := helpers.GetCredentials() 179 Eventually(session).Should(Say(`Assigning security group %s to space %s in org %s as %s\.\.\.`, secGroupName, spaceName1, orgName, userName)) 180 Eventually(session).Should(Say("OK")) 181 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 182 Eventually(session).Should(Exit(0)) 183 }) 184 }) 185 186 When("the lifecycle flag is running", func() { 187 When("binding to a particular space", func() { 188 It("binds the security group to the space", func() { 189 session := helpers.CF("bind-security-group", secGroupName, orgName, spaceName1, "--lifecycle", "running") 190 userName, _ := helpers.GetCredentials() 191 Eventually(session).Should(Say(`Assigning security group %s to space %s in org %s as %s\.\.\.`, secGroupName, spaceName1, orgName, userName)) 192 Eventually(session).Should(Say("OK")) 193 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 194 Eventually(session).Should(Exit(0)) 195 }) 196 }) 197 }) 198 199 When("the lifecycle flag is staging", func() { 200 When("binding to all spaces in an org", func() { 201 It("binds the security group to each space", func() { 202 session := helpers.CF("bind-security-group", secGroupName, orgName, "--lifecycle", "staging") 203 userName, _ := helpers.GetCredentials() 204 Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName)) 205 Eventually(session).Should(Say("OK")) 206 Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName)) 207 Eventually(session).Should(Say("OK")) 208 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 209 Eventually(session).Should(Exit(0)) 210 }) 211 }) 212 213 When("binding to a particular space", func() { 214 It("binds the security group to the space", func() { 215 session := helpers.CF("bind-security-group", secGroupName, orgName, spaceName1, "--lifecycle", "staging") 216 userName, _ := helpers.GetCredentials() 217 Eventually(session).Should(Say(`Assigning security group %s to space %s in org %s as %s\.\.\.`, secGroupName, spaceName1, orgName, userName)) 218 Eventually(session).Should(Say("OK")) 219 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 220 Eventually(session).Should(Exit(0)) 221 }) 222 }) 223 }) 224 }) 225 }) 226 }) 227 })