code.cloudfoundry.org/cli@v7.1.0+incompatible/integration/v6/global/bind_staging_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-staging-security-group command", func() {
    13  	var (
    14  		userName     string
    15  		secGroupName string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		secGroupName = helpers.NewSecurityGroupName()
    20  		userName = 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-staging-security-group", "--help")
    27  				helpText(session)
    28  				Eventually(session).Should(Exit(0))
    29  			})
    30  		})
    31  	})
    32  
    33  	When("the environment is not setup correctly", func() {
    34  		It("fails with the appropriate errors", func() {
    35  			helpers.UnrefactoredCheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "bind-staging-security-group", secGroupName)
    36  		})
    37  	})
    38  
    39  	When("the security group is not provided", func() {
    40  		It("fails with an incorrect usage message and displays help", func() {
    41  			session := helpers.CF("bind-staging-security-group")
    42  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SECURITY_GROUP` was not provided"))
    43  			helpText(session)
    44  			Eventually(session).Should(Exit(1))
    45  		})
    46  	})
    47  
    48  	When("the security group doesn't exist", func() {
    49  		It("fails with a security group not found message", func() {
    50  			session := helpers.CF("bind-staging-security-group", "some-security-group-that-doesn't-exist")
    51  			Eventually(session).Should(Say("FAILED"))
    52  			Eventually(session).Should(Say("security group some-security-group-that-doesn't-exist not found"))
    53  			Eventually(session).Should(Exit(1))
    54  		})
    55  	})
    56  
    57  	When("the security group exists", func() {
    58  		var (
    59  			someSecurityGroup resources.SecurityGroup
    60  			ports             string
    61  			description       string
    62  		)
    63  
    64  		BeforeEach(func() {
    65  			ports = "53"
    66  			description = "SG"
    67  			someSecurityGroup = helpers.NewSecurityGroup(secGroupName, "tcp", "0.0.0.0/0", &ports, &description)
    68  			helpers.CreateSecurityGroup(someSecurityGroup)
    69  		})
    70  
    71  		It(" globally binds the security group to staging lifecycle", func() {
    72  			session := helpers.CF("bind-staging-security-group", secGroupName)
    73  			Eventually(session).Should(Say("Binding security group %s to staging as %s", secGroupName, userName))
    74  			Eventually(session).Should(Say("OK"))
    75  			Eventually(session).Should(Exit(0))
    76  		})
    77  
    78  	})
    79  })
    80  
    81  func helpText(session *Session) {
    82  	Eventually(session).Should(Say("NAME:"))
    83  	Eventually(session).Should(Say(`\s+bind-staging-security-group - Bind a security group to the list of security groups to be used for staging applications`))
    84  	Eventually(session).Should(Say("USAGE:"))
    85  	Eventually(session).Should(Say(`\s+cf bind-staging-security-group SECURITY_GROUP`))
    86  	Eventually(session).Should(Say("SEE ALSO:"))
    87  	Eventually(session).Should(Say(`\s+apps, bind-running-security-group, bind-security-group, restart, security-groups, staging-security-groups`))
    88  }