github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/global/bind_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("bind-running-security-group command", func() {
    13  	var (
    14  		userName     string
    15  		secGroupName string
    16  		helpText     func(session *Session)
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		secGroupName = helpers.NewSecurityGroupName()
    21  		userName = helpers.LoginCF()
    22  		helpText = func(session *Session) {
    23  			Eventually(session).Should(Say("NAME:"))
    24  			Eventually(session).Should(Say(`\s+bind-running-security-group - Bind a security group to the list of security groups to be used for running applications`))
    25  			Eventually(session).Should(Say("USAGE:"))
    26  			Eventually(session).Should(Say(`\s+cf bind-running-security-group SECURITY_GROUP`))
    27  			Eventually(session).Should(Say("SEE ALSO:"))
    28  			Eventually(session).Should(Say(`\s+apps, bind-security-group, bind-staging-security-group, restart, running-security-groups, security-groups`))
    29  		}
    30  	})
    31  
    32  	Describe("help", func() {
    33  		When("--help flag is set", func() {
    34  			It("Displays command usage to output", func() {
    35  				session := helpers.CF("bind-running-security-group", "--help")
    36  				helpText(session)
    37  				Eventually(session).Should(Exit(0))
    38  			})
    39  		})
    40  	})
    41  
    42  	When("the environment is not setup correctly", func() {
    43  		It("fails with the appropriate errors", func() {
    44  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "bind-running-security-group", secGroupName)
    45  		})
    46  	})
    47  
    48  	When("the security group is not provided", func() {
    49  		It("fails with an incorrect usage message and displays help", func() {
    50  			session := helpers.CF("bind-running-security-group")
    51  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SECURITY_GROUP` was not provided"))
    52  			helpText(session)
    53  			Eventually(session).Should(Exit(1))
    54  		})
    55  	})
    56  
    57  	When("the security group doesn't exist", func() {
    58  		It("fails with a security group not found message", func() {
    59  			session := helpers.CF("bind-running-security-group", "some-security-group-that-doesn't-exist")
    60  			Eventually(session.Err).Should(Say("Security group 'some-security-group-that-doesn't-exist' not found"))
    61  			Eventually(session).Should(Say("FAILED"))
    62  			Eventually(session).Should(Exit(1))
    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  		})
    79  
    80  		It("globally binds the security group to running lifecycle", func() {
    81  			session := helpers.CF("bind-running-security-group", secGroupName)
    82  			Eventually(session).Should(Say("Binding security group %s to running as %s", secGroupName, userName))
    83  			Eventually(session).Should(Say("OK"))
    84  			Eventually(session).Should(Exit(0))
    85  		})
    86  	})
    87  })