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