github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/shared/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 When("--help flag is provided", func() { 18 It("displays command usage to output", func() { 19 session = helpers.CF("security-groups", "--help") 20 Eventually(session).Should(Say("NAME:")) 21 Eventually(session).Should(Say("security-groups - List all security groups")) 22 Eventually(session).Should(Say("USAGE:")) 23 Eventually(session).Should(Say("cf security-groups")) 24 Eventually(session).Should(Say("SEE ALSO:")) 25 Eventually(session).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 When("the environment is not setup correctly", func() { 32 It("fails with the appropriate errors", func() { 33 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "security-groups") 34 }) 35 }) 36 37 When("the environment is set up correctly", func() { 38 BeforeEach(func() { 39 helpers.LoginCF() 40 }) 41 42 JustBeforeEach(func() { 43 session = helpers.CF("security-groups") 44 }) 45 46 When("there are security groups", func() { 47 var ( 48 username string 49 50 securityGroup1 helpers.SecurityGroup 51 securityGroup2 helpers.SecurityGroup 52 securityGroup3 helpers.SecurityGroup 53 securityGroup4 helpers.SecurityGroup 54 securityGroup5 helpers.SecurityGroup 55 securityGroup6 helpers.SecurityGroup 56 securityGroup7 helpers.SecurityGroup 57 58 org11 string 59 org12 string 60 org13 string 61 org21 string 62 org23 string 63 org33 string 64 65 space11 string 66 space12 string 67 space13 string 68 space21 string 69 space22 string 70 space23 string 71 space31 string 72 space32 string 73 space33 string 74 ) 75 76 BeforeEach(func() { 77 helpers.ClearTarget() 78 79 username, _ = helpers.GetCredentials() 80 81 // Create Security Groups, Organizations, and Spaces with predictable and unique names for testing sorting 82 securityGroup1 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-1"), "tcp", "11.1.1.0/24", "80,443", "SG1") 83 securityGroup1.Create() 84 securityGroup2 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-2"), "tcp", "11.1.1.0/24", "80,443", "SG1") 85 securityGroup2.Create() 86 securityGroup3 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-3"), "tcp", "11.1.1.0/24", "80,443", "SG1") 87 securityGroup3.Create() 88 securityGroup4 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-4"), "tcp", "11.1.1.0/24", "80,443", "SG1") 89 securityGroup4.Create() 90 securityGroup5 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-5"), "tcp", "11.1.1.0/24", "80,443", "SG1") 91 securityGroup5.Create() 92 securityGroup6 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-6"), "tcp", "11.1.1.0/24", "80,443", "SG1") 93 securityGroup6.Create() 94 securityGroup7 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-7"), "tcp", "11.1.1.0/24", "80,443", "SG1") 95 securityGroup7.Create() 96 97 org11 = helpers.PrefixedRandomName("INTEGRATION-ORG-11") 98 org12 = helpers.PrefixedRandomName("INTEGRATION-ORG-12") 99 org13 = helpers.PrefixedRandomName("INTEGRATION-ORG-13") 100 org21 = helpers.PrefixedRandomName("INTEGRATION-ORG-21") 101 org23 = helpers.PrefixedRandomName("INTEGRATION-ORG-23") 102 org33 = helpers.PrefixedRandomName("INTEGRATION-ORG-33") 103 104 space11 = helpers.PrefixedRandomName("INTEGRATION-SPACE-11") 105 space12 = helpers.PrefixedRandomName("INTEGRATION-SPACE-12") 106 space13 = helpers.PrefixedRandomName("INTEGRATION-SPACE-13") 107 space21 = helpers.PrefixedRandomName("INTEGRATION-SPACE-21") 108 space22 = helpers.PrefixedRandomName("INTEGRATION-SPACE-22") 109 space23 = helpers.PrefixedRandomName("INTEGRATION-SPACE-23") 110 space31 = helpers.PrefixedRandomName("INTEGRATION-SPACE-31") 111 space32 = helpers.PrefixedRandomName("INTEGRATION-SPACE-32") 112 space33 = helpers.PrefixedRandomName("INTEGRATION-SPACE-33") 113 114 helpers.CreateOrgAndSpace(org11, space11) 115 Eventually(helpers.CF("bind-running-security-group", securityGroup1.Name)).Should(Exit(0)) 116 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org11, space11)).Should(Exit(0)) 117 helpers.CreateSpace(space22) 118 Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org11, space22, "--lifecycle", "staging")).Should(Exit(0)) 119 helpers.CreateSpace(space32) 120 Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org11, space32)).Should(Exit(0)) 121 helpers.CreateOrgAndSpace(org12, space12) 122 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org12, space12, "--lifecycle", "staging")).Should(Exit(0)) 123 helpers.CreateOrgAndSpace(org13, space13) 124 Eventually(helpers.CF("bind-staging-security-group", securityGroup2.Name)).Should(Exit(0)) 125 Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org13, space13)).Should(Exit(0)) 126 helpers.CreateOrgAndSpace(org21, space21) 127 Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org21, space21)).Should(Exit(0)) 128 helpers.CreateOrgAndSpace(org23, space23) 129 Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org23, space23)).Should(Exit(0)) 130 helpers.CreateSpace(space31) 131 Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org23, space31)).Should(Exit(0)) 132 helpers.CreateOrgAndSpace(org33, space33) 133 Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org33, space33)).Should(Exit(0)) 134 Eventually(helpers.CF("bind-running-security-group", securityGroup5.Name)).Should(Exit(0)) 135 Eventually(helpers.CF("bind-staging-security-group", securityGroup6.Name)).Should(Exit(0)) 136 Eventually(helpers.CF("bind-running-security-group", securityGroup7.Name)).Should(Exit(0)) 137 Eventually(helpers.CF("bind-staging-security-group", securityGroup7.Name)).Should(Exit(0)) 138 }) 139 140 AfterEach(func() { 141 helpers.QuickDeleteOrg(org11) 142 helpers.QuickDeleteOrg(org12) 143 helpers.QuickDeleteOrg(org13) 144 helpers.QuickDeleteOrg(org21) 145 helpers.QuickDeleteOrg(org23) 146 helpers.QuickDeleteOrg(org33) 147 }) 148 149 It("lists the security groups", func() { 150 Eventually(session).Should(Say("Getting security groups as %s", username)) 151 Eventually(session).Should(Say(`OK\n\n`)) 152 Eventually(session).Should(Say(`\s+name\s+organization\s+space\s+lifecycle`)) 153 // How to test alphabetization with auto-generated names? Here's how. 154 Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+running`, securityGroup1.Name)) 155 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup1.Name, org11, space11)) 156 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+staging`, securityGroup1.Name, org12, space12)) 157 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup1.Name, org13, space13)) 158 Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+staging`, securityGroup2.Name)) 159 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+staging`, securityGroup2.Name, org11, space22)) 160 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup2.Name, org21, space21)) 161 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup2.Name, org23, space23)) 162 Eventually(session).Should(Say(`#\d+\s+%s`, securityGroup3.Name)) 163 Eventually(session).Should(Say(`#\d+\s+%s\s+%s\s+%s\s+running`, securityGroup4.Name, org11, space32)) 164 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup4.Name, org23, space31)) 165 Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup4.Name, org33, space33)) 166 Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+running`, securityGroup5.Name)) 167 Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+staging`, securityGroup6.Name)) 168 Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+running`, securityGroup7.Name)) 169 Eventually(session).Should(Say(`\s+%s\s+<all>\s+<all>\s+staging`, securityGroup7.Name)) 170 Eventually(session).Should(Exit(0)) 171 }) 172 }) 173 }) 174 })