github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/global/unbind_running_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("unbind-running-security-group command", func() { 13 var ( 14 secGroupName string 15 ) 16 17 BeforeEach(func() { 18 secGroupName = helpers.NewSecurityGroupName() 19 helpers.LoginCF() 20 }) 21 22 Describe("help", func() { 23 When("--help flag is set", func() { 24 It("Displays command usage to output", func() { 25 session := helpers.CF("unbind-running-security-group", "--help") 26 Eventually(session).Should(Say("NAME:")) 27 Eventually(session).Should(Say(`\s+unbind-running-security-group - Unbind a security group from the set of security groups for running applications globally`)) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say(`\s+cf unbind-running-security-group SECURITY_GROUP`)) 30 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 31 Eventually(session).Should(Say("SEE ALSO:")) 32 Eventually(session).Should(Say(`\s+apps, restart, running-security-groups, security-groups`)) 33 Eventually(session).Should(Exit(0)) 34 }) 35 }) 36 }) 37 38 When("the environment is not setup correctly", func() { 39 It("fails with the appropriate errors", func() { 40 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "unbind-running-security-group", "security-group-name") 41 }) 42 }) 43 44 When("the input is invalid", func() { 45 When("the security group is not provided", func() { 46 It("fails with an incorrect usage message and displays help", func() { 47 session := helpers.CF("unbind-running-security-group") 48 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SECURITY_GROUP` was not provided")) 49 Eventually(session).Should(Say("USAGE:")) 50 Eventually(session).Should(Exit(1)) 51 }) 52 }) 53 }) 54 55 When("the security group doesn't exist", func() { 56 It("succeeds with a security group not found message", func() { 57 session := helpers.CF("unbind-running-security-group", "some-security-group-that-doesn't-exist") 58 userName, _ := helpers.GetCredentials() 59 Eventually(session).Should(Say("Unbinding security group %s from defaults for running as %s...", "some-security-group-that-doesn't-exist", userName)) 60 Eventually(session.Err).Should(Say("Security group 'some-security-group-that-doesn't-exist' not found.")) 61 Eventually(session).Should(Say("OK")) 62 Eventually(session).Should(Exit(0)) 63 }) 64 }) 65 66 When("the security group exists", func() { 67 var ( 68 someSecurityGroup resources.SecurityGroup 69 ports string 70 description string 71 ) 72 73 BeforeEach(func() { 74 ports = "53" 75 description = "SG" 76 someSecurityGroup = helpers.NewSecurityGroup(secGroupName, "tcp", "0.0.0.0/0", &ports, &description) 77 helpers.CreateSecurityGroup(someSecurityGroup) 78 session := helpers.CF("bind-running-security-group", secGroupName) 79 Eventually(session).Should(Exit(0)) 80 }) 81 82 It("it unbinds the running security group globally", func() { 83 session := helpers.CF("unbind-running-security-group", secGroupName) 84 userName, _ := helpers.GetCredentials() 85 Eventually(session).Should(Say("Unbinding security group %s from defaults for running as %s...", secGroupName, userName)) 86 Eventually(session).Should(Say("OK")) 87 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 88 Eventually(session).Should(Exit(0)) 89 90 session = helpers.CF("unbind-running-security-group", secGroupName) 91 Eventually(session).Should(Say("Unbinding security group %s from defaults for running as %s...", secGroupName, userName)) 92 Eventually(session).Should(Say("OK")) 93 Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 94 Eventually(session).Should(Exit(0)) 95 }) 96 }) 97 })