github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/security_groups_command_test.go (about) 1 package isolated 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("security-groups command", func() { 12 var ( 13 session *Session 14 ) 15 16 Describe("help", func() { 17 Context("when --help flag is provided", func() { 18 It("displays command usage to output", func() { 19 session = helpers.CF("security-groups", "--help") 20 Eventually(session.Out).Should(Say("NAME:")) 21 Eventually(session.Out).Should(Say("security-groups - List all security groups")) 22 Eventually(session.Out).Should(Say("USAGE:")) 23 Eventually(session.Out).Should(Say("cf security-groups")) 24 Eventually(session.Out).Should(Say("SEE ALSO:")) 25 Eventually(session.Out).Should(Say("bind-running-security-group, bind-security-group, bind-staging-security-group, security-group")) 26 Eventually(session).Should(Exit(0)) 27 }) 28 }) 29 }) 30 31 Describe("everything but help", func() { 32 BeforeEach(func() { 33 helpers.LoginCF() 34 }) 35 36 JustBeforeEach(func() { 37 session = helpers.CF("security-groups") 38 }) 39 40 Context("when no API endpoint is set", func() { 41 BeforeEach(func() { 42 helpers.UnsetAPI() 43 }) 44 45 It("fails with no API endpoint set message", func() { 46 Eventually(session.Out).Should(Say("FAILED")) 47 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 48 Eventually(session).Should(Exit(1)) 49 }) 50 }) 51 52 Context("when not logged in", func() { 53 BeforeEach(func() { 54 helpers.LogoutCF() 55 }) 56 57 It("fails with not logged in message", func() { 58 session = helpers.CF("security-groups") 59 Eventually(session.Out).Should(Say("FAILED")) 60 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 61 Eventually(session).Should(Exit(1)) 62 }) 63 }) 64 65 Context("when too many arguments are provided", func() { 66 It("succeeds and ignores the additional arguments", func() { 67 session = helpers.CF("security-groups", "foooo") 68 Eventually(session.Out).Should(Say("OK")) 69 Eventually(session).Should(Exit(0)) 70 }) 71 }) 72 73 Context("when there are security groups", func() { 74 var ( 75 securityGroup1 helpers.SecurityGroup 76 securityGroup2 helpers.SecurityGroup 77 securityGroup3 helpers.SecurityGroup 78 securityGroup4 helpers.SecurityGroup 79 securityGroup5 helpers.SecurityGroup 80 securityGroup6 helpers.SecurityGroup 81 securityGroup7 helpers.SecurityGroup 82 83 org11 string 84 org12 string 85 org13 string 86 org21 string 87 org23 string 88 org33 string 89 90 space11 string 91 space12 string 92 space13 string 93 space21 string 94 space22 string 95 space23 string 96 space31 string 97 space32 string 98 space33 string 99 ) 100 101 BeforeEach(func() { 102 helpers.ClearTarget() 103 104 // Create Security Groups, Organizations, and Spaces with predictable and unique names for testing sorting 105 securityGroup1 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-1"), "tcp", "11.1.1.0/24", "80,443", "SG1") 106 securityGroup1.Create() 107 securityGroup2 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-2"), "tcp", "11.1.1.0/24", "80,443", "SG1") 108 securityGroup2.Create() 109 securityGroup3 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-3"), "tcp", "11.1.1.0/24", "80,443", "SG1") 110 securityGroup3.Create() 111 securityGroup4 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-4"), "tcp", "11.1.1.0/24", "80,443", "SG1") 112 securityGroup4.Create() 113 securityGroup5 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-5"), "tcp", "11.1.1.0/24", "80,443", "SG1") 114 securityGroup5.Create() 115 securityGroup6 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-6"), "tcp", "11.1.1.0/24", "80,443", "SG1") 116 securityGroup6.Create() 117 securityGroup7 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-7"), "tcp", "11.1.1.0/24", "80,443", "SG1") 118 securityGroup7.Create() 119 120 org11 = helpers.PrefixedRandomName("INTEGRATION-ORG-11") 121 org12 = helpers.PrefixedRandomName("INTEGRATION-ORG-12") 122 org13 = helpers.PrefixedRandomName("INTEGRATION-ORG-13") 123 org21 = helpers.PrefixedRandomName("INTEGRATION-ORG-21") 124 org23 = helpers.PrefixedRandomName("INTEGRATION-ORG-23") 125 org33 = helpers.PrefixedRandomName("INTEGRATION-ORG-33") 126 127 space11 = helpers.PrefixedRandomName("INTEGRATION-SPACE-11") 128 space12 = helpers.PrefixedRandomName("INTEGRATION-SPACE-12") 129 space13 = helpers.PrefixedRandomName("INTEGRATION-SPACE-13") 130 space21 = helpers.PrefixedRandomName("INTEGRATION-SPACE-21") 131 space22 = helpers.PrefixedRandomName("INTEGRATION-SPACE-22") 132 space23 = helpers.PrefixedRandomName("INTEGRATION-SPACE-23") 133 space31 = helpers.PrefixedRandomName("INTEGRATION-SPACE-31") 134 space32 = helpers.PrefixedRandomName("INTEGRATION-SPACE-32") 135 space33 = helpers.PrefixedRandomName("INTEGRATION-SPACE-33") 136 137 helpers.CreateOrgAndSpace(org11, space11) 138 Eventually(helpers.CF("bind-running-security-group", securityGroup1.Name)).Should(Exit(0)) 139 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org11, space11)).Should(Exit(0)) 140 helpers.CreateSpace(space22) 141 Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org11, space22, "--lifecycle", "staging")).Should(Exit(0)) 142 helpers.CreateSpace(space32) 143 Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org11, space32)).Should(Exit(0)) 144 helpers.CreateOrgAndSpace(org12, space12) 145 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org12, space12, "--lifecycle", "staging")).Should(Exit(0)) 146 helpers.CreateOrgAndSpace(org13, space13) 147 Eventually(helpers.CF("bind-staging-security-group", securityGroup2.Name)).Should(Exit(0)) 148 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org13, space13)).Should(Exit(0)) 149 helpers.CreateOrgAndSpace(org21, space21) 150 Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org21, space21)).Should(Exit(0)) 151 helpers.CreateOrgAndSpace(org23, space23) 152 Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org23, space23)).Should(Exit(0)) 153 helpers.CreateSpace(space31) 154 Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org23, space31)).Should(Exit(0)) 155 helpers.CreateOrgAndSpace(org33, space33) 156 Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org33, space33)).Should(Exit(0)) 157 Eventually(helpers.CF("bind-running-security-group", securityGroup5.Name)).Should(Exit(0)) 158 Eventually(helpers.CF("bind-staging-security-group", securityGroup6.Name)).Should(Exit(0)) 159 Eventually(helpers.CF("bind-running-security-group", securityGroup7.Name)).Should(Exit(0)) 160 Eventually(helpers.CF("bind-staging-security-group", securityGroup7.Name)).Should(Exit(0)) 161 }) 162 163 AfterEach(func() { 164 helpers.QuickDeleteOrg(org11) 165 helpers.QuickDeleteOrg(org12) 166 helpers.QuickDeleteOrg(org13) 167 helpers.QuickDeleteOrg(org21) 168 helpers.QuickDeleteOrg(org23) 169 helpers.QuickDeleteOrg(org33) 170 }) 171 172 It("lists the security groups", func() { 173 Eventually(session.Out).Should(Say("Getting security groups as admin")) 174 Eventually(session.Out).Should(Say("OK\\n\\n")) 175 Eventually(session.Out).Should(Say("\\s+name\\s+organization\\s+space\\s+lifecycle")) 176 // How to test alphabetization with auto-generated names? Here's how. 177 Eventually(session.Out).Should(Say("#\\d+\\s+%s\\s+<all>\\s+<all>\\s+running", securityGroup1.Name)) 178 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+running", securityGroup1.Name, org11, space11)) 179 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+staging", securityGroup1.Name, org12, space12)) 180 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+running", securityGroup1.Name, org13, space13)) 181 Eventually(session.Out).Should(Say("#\\d+\\s+%s\\s+<all>\\s+<all>\\s+staging", securityGroup2.Name)) 182 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+staging", securityGroup2.Name, org11, space22)) 183 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+running", securityGroup2.Name, org21, space21)) 184 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+running", securityGroup2.Name, org23, space23)) 185 Eventually(session.Out).Should(Say("#\\d+\\s+%s", securityGroup3.Name)) 186 Eventually(session.Out).Should(Say("#\\d+\\s+%s\\s+%s\\s+%s\\s+running", securityGroup4.Name, org11, space32)) 187 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+running", securityGroup4.Name, org23, space31)) 188 Eventually(session.Out).Should(Say("\\s+%s\\s+%s\\s+%s\\s+running", securityGroup4.Name, org33, space33)) 189 Eventually(session.Out).Should(Say("#\\d+\\s+%s\\s+<all>\\s+<all>\\s+running", securityGroup5.Name)) 190 Eventually(session.Out).Should(Say("#\\d+\\s+%s\\s+<all>\\s+<all>\\s+staging", securityGroup6.Name)) 191 Eventually(session.Out).Should(Say("#\\d+\\s+%s\\s+<all>\\s+<all>\\s+running", securityGroup7.Name)) 192 Eventually(session.Out).Should(Say("\\s+%s\\s+<all>\\s+<all>\\s+staging", securityGroup7.Name)) 193 Eventually(session).Should(Exit(0)) 194 }) 195 }) 196 }) 197 })