github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/bind_running_security_group_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("bind-security-group command", func() {
    13  	var (
    14  		secGroupName string
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		secGroupName = helpers.NewSecurityGroupName()
    19  
    20  		helpers.LoginCF()
    21  	})
    22  
    23  	Describe("help", func() {
    24  		When("--help flag is set", func() {
    25  			It("Displays command usage to output", func() {
    26  				session := helpers.CF("bind-running-security-group", "--help")
    27  				Eventually(session).Should(Say("NAME:"))
    28  				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`))
    29  				Eventually(session).Should(Say("USAGE:"))
    30  				Eventually(session).Should(Say(`\s+cf bind-running-security-group SECURITY_GROUP`))
    31  				Eventually(session).Should(Say(`TIP: Changes will not apply to existing running applications until they are restarted.`))
    32  				Eventually(session).Should(Say("SEE ALSO:"))
    33  				Eventually(session).Should(Say(`\s+apps, bind-security-group, bind-staging-security-group, restart, running-security-groups, security-groups`))
    34  				Eventually(session).Should(Exit(0))
    35  			})
    36  		})
    37  	})
    38  
    39  	When("the input is invalid", func() {
    40  		When("the security group is not provided", func() {
    41  			It("fails with an incorrect usage message and displays help", func() {
    42  				session := helpers.CF("bind-running-security-group")
    43  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SECURITY_GROUP` was not provided"))
    44  				Eventually(session).Should(Say("USAGE:"))
    45  				Eventually(session).Should(Exit(1))
    46  			})
    47  		})
    48  	})
    49  
    50  	When("the security group doesn't exist", func() {
    51  		It("fails with a security group not found message", func() {
    52  			session := helpers.CF("bind-running-security-group", "fake-group")
    53  			Eventually(session).Should(Say("FAILED"))
    54  			Eventually(session).Should(Say("security group fake-group not found"))
    55  			Eventually(session).Should(Exit(1))
    56  		})
    57  	})
    58  
    59  	When("the security group exists", func() {
    60  		var (
    61  			someSecurityGroup resources.SecurityGroup
    62  			ports             string
    63  			description       string
    64  		)
    65  
    66  		BeforeEach(func() {
    67  			ports = "53"
    68  			description = "SG"
    69  			someSecurityGroup = helpers.NewSecurityGroup(secGroupName, "tcp", "0.0.0.0/0", &ports, &description)
    70  			helpers.CreateSecurityGroup(someSecurityGroup)
    71  		})
    72  
    73  		It("binds the security group to the list of security groups for running apps", func() {
    74  			session := helpers.CF("bind-running-security-group", secGroupName)
    75  			Eventually(session).Should(Say(`Binding security group %s to defaults for running`, secGroupName))
    76  			Eventually(session).Should(Say("OK"))
    77  			Eventually(session).Should(Say(`TIP: Changes will not apply to existing running applications until they are restarted.`))
    78  			Eventually(session).Should(Exit(0))
    79  		})
    80  	})
    81  })