github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/isolated/security_groups_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("security-groups command", func() { 13 Describe("help", func() { 14 When("--help flag is set", func() { 15 It("Displays command usage to output", func() { 16 session := helpers.CF("security-groups", "--help") 17 Eventually(session).Should(Say("NAME:")) 18 Eventually(session).Should(Say("security-groups - List all security groups")) 19 Eventually(session).Should(Say("USAGE:")) 20 Eventually(session).Should(Say("cf security-groups")) 21 Eventually(session).Should(Say("SEE ALSO:")) 22 Eventually(session).Should(Say("bind-running-security-group, bind-security-group, bind-staging-security-group, security-group")) 23 Eventually(session).Should(Exit(0)) 24 }) 25 }) 26 }) 27 28 When("the environment is not setup correctly", func() { 29 It("fails with the appropriate errors", func() { 30 helpers.CheckEnvironmentTargetedCorrectly(false, false, "", "security-groups") 31 }) 32 }) 33 34 When("the environment is set up correctly", func() { 35 var userName string 36 37 BeforeEach(func() { 38 userName = helpers.LoginCF() 39 }) 40 41 When("security groups exists", func() { 42 var ( 43 securityGroup1 resources.SecurityGroup 44 securityGroup2 resources.SecurityGroup 45 securityGroup3 resources.SecurityGroup 46 securityGroup4 resources.SecurityGroup 47 securityGroup5 resources.SecurityGroup 48 orgName string 49 spaceName string 50 ports string 51 description string 52 ) 53 54 BeforeEach(func() { 55 orgName = helpers.NewOrgName() 56 spaceName = helpers.NewSpaceName() 57 helpers.CreateOrg(orgName) 58 helpers.TargetOrg(orgName) 59 helpers.CreateSpace(spaceName) 60 61 ports = "3360" 62 description = "Test security group" 63 securityGroup1 = helpers.NewSecurityGroup( 64 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP"), 65 "tcp", 66 "10.244.1.18", 67 &ports, 68 &description, 69 ) 70 securityGroup2 = helpers.NewSecurityGroup( 71 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP"), 72 "udp", 73 "127.0.0.1", 74 &ports, 75 &description, 76 ) 77 securityGroup3 = helpers.NewSecurityGroup( 78 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP"), 79 "all", 80 "0.0.0.0-5.6.7.8", 81 nil, 82 &description, 83 ) 84 securityGroup4 = helpers.NewSecurityGroup( 85 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP"), 86 "all", 87 "192.168.5.6", 88 nil, 89 &description, 90 ) 91 securityGroup5 = helpers.NewSecurityGroup( 92 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP"), 93 "tcp", 94 "172.16.0.1", 95 &ports, 96 &description, 97 ) 98 helpers.CreateSecurityGroup(securityGroup1) 99 helpers.CreateSecurityGroup(securityGroup2) 100 helpers.CreateSecurityGroup(securityGroup3) 101 helpers.CreateSecurityGroup(securityGroup4) 102 helpers.CreateSecurityGroup(securityGroup5) 103 104 session1 := helpers.CF(`bind-running-security-group`, securityGroup1.Name) 105 session2 := helpers.CF("bind-security-group", securityGroup2.Name, orgName, "--space", spaceName) 106 session3 := helpers.CF(`bind-staging-security-group`, securityGroup4.Name) 107 session4 := helpers.CF("bind-security-group", securityGroup5.Name, orgName, "--space", spaceName, "--lifecycle", "staging") 108 109 Eventually(session1).Should(Exit(0)) 110 Eventually(session2).Should(Exit(0)) 111 Eventually(session3).Should(Exit(0)) 112 Eventually(session4).Should(Exit(0)) 113 }) 114 115 AfterEach(func() { 116 helpers.DeleteSecurityGroup(securityGroup1) 117 helpers.DeleteSecurityGroup(securityGroup2) 118 helpers.DeleteSecurityGroup(securityGroup3) 119 helpers.DeleteSecurityGroup(securityGroup4) 120 helpers.DeleteSecurityGroup(securityGroup5) 121 }) 122 123 It("displays the security groups exits 0", func() { 124 session := helpers.CF("security-groups") 125 126 Eventually(session).Should(Say(`Getting security groups as %s\.\.\.`, userName)) 127 Eventually(session).Should(Say(`name\s+organization\s+space\s+lifecycle`)) 128 Eventually(session).Should(Say(`%s\s+<all>\s+<all>\s+running`, securityGroup1.Name)) 129 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+running`, securityGroup2.Name, orgName, spaceName)) 130 Eventually(session).Should(Say(`%s\s+`, securityGroup3.Name)) 131 Eventually(session).Should(Say(`%s\s+<all>\s+<all>\s+staging`, securityGroup4.Name)) 132 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+staging`, securityGroup5.Name, orgName, spaceName)) 133 134 Eventually(session).Should(Exit(0)) 135 }) 136 }) 137 }) 138 })