github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/global/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("security-group 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-group", "--help") 17 Eventually(session).Should(Say("NAME:")) 18 Eventually(session).Should(Say("security-group - Show a single security group")) 19 Eventually(session).Should(Say("USAGE:")) 20 Eventually(session).Should(Say("cf security-group SECURITY_GROUP")) 21 Eventually(session).Should(Say("SEE ALSO:")) 22 Eventually(session).Should(Say("bind-running-security-group, bind-security-group, bind-staging-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-group", "bogus") 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("the security group does not exist", func() { 42 It("displays security group not found and exits 1", func() { 43 session := helpers.CF("security-group", "bogus") 44 userName, _ := helpers.GetCredentials() 45 Eventually(session).Should(Say(`Getting info for security group %s as %s\.\.\.`, "bogus", userName)) 46 Eventually(session.Err).Should(Say("Security group '%s' not found.", "bogus")) 47 Eventually(session).Should(Say("FAILED")) 48 Eventually(session).Should(Exit(1)) 49 }) 50 }) 51 52 When("the security group exists", func() { 53 var ( 54 securityGroup resources.SecurityGroup 55 orgName string 56 spaceName string 57 ports string 58 description string 59 ) 60 61 BeforeEach(func() { 62 orgName = helpers.NewOrgName() 63 spaceName = helpers.NewSpaceName() 64 helpers.CreateOrg(orgName) 65 helpers.TargetOrg(orgName) 66 helpers.CreateSpace(spaceName) 67 68 ports = "3360" 69 description = "Test security group" 70 securityGroup = helpers.NewSecurityGroup( 71 helpers.PrefixedRandomName("INTEGRATION-SECURITY-GROUP"), 72 "tcp", 73 "10.244.1.18", 74 &ports, 75 &description, 76 ) 77 helpers.CreateSecurityGroup(securityGroup) 78 }) 79 80 AfterEach(func() { 81 helpers.DeleteSecurityGroup(securityGroup) 82 helpers.QuickDeleteOrg(orgName) 83 }) 84 85 When("the security group does not have assigned spaces", func() { 86 It("displays the security group without assigned spaces and exits 0", func() { 87 session := helpers.CF("security-group", securityGroup.Name) 88 89 Eventually(session).Should(Say(`Getting info for security group %s as %s\.\.\.`, securityGroup.Name, userName)) 90 Eventually(session).Should(Say(`name:\s+%s`, securityGroup.Name)) 91 Eventually(session).Should(Say(`rules:`)) 92 Eventually(session).Should(Say(`\[`)) 93 Eventually(session).Should(Say(`{`)) 94 Eventually(session).Should(Say(`"protocol": "%s"`, securityGroup.Rules[0].Protocol)) 95 Eventually(session).Should(Say(`"destination": "%s"`, securityGroup.Rules[0].Destination)) 96 Eventually(session).Should(Say(`"ports": "%s"`, ports)) 97 Eventually(session).Should(Say(`"description": "%s"`, description)) 98 Eventually(session).Should(Say(`}`)) 99 Eventually(session).Should(Say(`\]`)) 100 Eventually(session).Should(Say(`No spaces assigned`)) 101 102 Eventually(session).Should(Exit(0)) 103 }) 104 }) 105 106 When("the security group has assigned spaces", func() { 107 BeforeEach(func() { 108 session := helpers.CF("bind-security-group", securityGroup.Name, orgName, "--space", spaceName) 109 Eventually(session).Should(Exit(0)) 110 }) 111 112 It("displays the security group with assigned spaces and exits 0", func() { 113 session := helpers.CF("security-group", securityGroup.Name) 114 115 Eventually(session).Should(Say(`Getting info for security group %s as %s\.\.\.`, securityGroup.Name, userName)) 116 Eventually(session).Should(Say(`name:\s+%s`, securityGroup.Name)) 117 Eventually(session).Should(Say(`rules:`)) 118 Eventually(session).Should(Say(`\[`)) 119 Eventually(session).Should(Say(`{`)) 120 Eventually(session).Should(Say(`"protocol": "%s"`, securityGroup.Rules[0].Protocol)) 121 Eventually(session).Should(Say(`"destination": "%s"`, securityGroup.Rules[0].Destination)) 122 Eventually(session).Should(Say(`"ports": "%s"`, ports)) 123 Eventually(session).Should(Say(`"description": "%s"`, description)) 124 Eventually(session).Should(Say(`}`)) 125 Eventually(session).Should(Say(`\]`)) 126 Eventually(session).Should(Say(`organization\s+space`)) 127 Eventually(session).Should(Say(`%s\s+%s`, orgName, spaceName)) 128 129 Eventually(session).Should(Exit(0)) 130 }) 131 }) 132 }) 133 }) 134 })