github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/unbind_security_group_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gbytes"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = Describe("unbind-security-group command", func() {
    12  	var (
    13  		orgName           string
    14  		securityGroupName string
    15  		spaceName         string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		orgName = helpers.NewOrgName()
    20  		securityGroupName = helpers.NewSecurityGroupName()
    21  		spaceName = helpers.NewSpaceName()
    22  
    23  		helpers.LoginCF()
    24  	})
    25  
    26  	Describe("help", func() {
    27  		When("--help flag is set", func() {
    28  			It("Displays command usage to output", func() {
    29  				session := helpers.CF("unbind-security-group", "--help")
    30  				Eventually(session).Should(Say("NAME:"))
    31  				Eventually(session).Should(Say(`\s+unbind-security-group - Unbind a security group from a space`))
    32  				Eventually(session).Should(Say("USAGE:"))
    33  				Eventually(session).Should(Say(`\s+cf unbind-security-group SECURITY_GROUP ORG SPACE \[--lifecycle \(running \| staging\)\]`))
    34  				Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
    35  				Eventually(session).Should(Say("OPTIONS:"))
    36  				Eventually(session).Should(Say(`\s+--lifecycle      Lifecycle phase the group applies to \(Default: running\)`))
    37  				Eventually(session).Should(Say("SEE ALSO:"))
    38  				Eventually(session).Should(Say(`\s+apps, restart, security-groups`))
    39  				Eventually(session).Should(Exit(0))
    40  			})
    41  		})
    42  	})
    43  
    44  	When("the lifecycle flag is invalid", func() {
    45  		It("outputs a message and usage", func() {
    46  			session := helpers.CF("unbind-security-group", securityGroupName, "some-org", "--lifecycle", "invalid")
    47  			Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `invalid' for option `--lifecycle'. Allowed values are: running or staging"))
    48  			Eventually(session).Should(Say("USAGE:"))
    49  			Eventually(session).Should(Exit(1))
    50  		})
    51  	})
    52  
    53  	When("the lifecycle flag has no argument", func() {
    54  		It("outputs a message and usage", func() {
    55  			session := helpers.CF("unbind-security-group", securityGroupName, "some-org", "--lifecycle")
    56  			Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `--lifecycle'"))
    57  			Eventually(session).Should(Say("USAGE:"))
    58  			Eventually(session).Should(Exit(1))
    59  		})
    60  	})
    61  
    62  	When("the environment is not setup correctly", func() {
    63  		It("fails with the appropriate errors", func() {
    64  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "unbind-security-group", securityGroupName)
    65  		})
    66  	})
    67  
    68  	When("the input is invalid", func() {
    69  		When("the security group is not provided", func() {
    70  			It("fails with an incorrect usage message and displays help", func() {
    71  				session := helpers.CF("unbind-security-group")
    72  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SECURITY_GROUP` was not provided"))
    73  				Eventually(session).Should(Say("USAGE:"))
    74  				Eventually(session).Should(Exit(1))
    75  			})
    76  		})
    77  
    78  		When("the space is not provided", func() {
    79  			It("fails with an incorrect usage message and displays help", func() {
    80  				session := helpers.CF("unbind-security-group", securityGroupName, "some-org")
    81  				Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SECURITY_GROUP`, `ORG`, and `SPACE` were not provided"))
    82  				Eventually(session).Should(Say("USAGE:"))
    83  				Eventually(session).Should(Exit(1))
    84  			})
    85  		})
    86  	})
    87  
    88  	When("the security group doesn't exist", func() {
    89  		BeforeEach(func() {
    90  			helpers.CreateOrgAndSpace(orgName, spaceName)
    91  		})
    92  
    93  		AfterEach(func() {
    94  			helpers.QuickDeleteOrg(orgName)
    95  		})
    96  
    97  		It("fails with a 'security group not found' message", func() {
    98  			session := helpers.CF("unbind-security-group", "some-other-security-group", orgName, spaceName)
    99  			Eventually(session).Should(Say("FAILED"))
   100  			Eventually(session.Err).Should(Say(`Security group 'some-other-security-group' not found\.`))
   101  			Eventually(session).Should(Exit(1))
   102  		})
   103  	})
   104  
   105  	When("the security group exists", func() {
   106  		BeforeEach(func() {
   107  			port := "8443"
   108  			description := "some-description"
   109  			someSecurityGroup := helpers.NewSecurityGroup(securityGroupName, "tcp", "127.0.0.1", &port, &description)
   110  			helpers.CreateSecurityGroup(someSecurityGroup)
   111  		})
   112  
   113  		When("the org doesn't exist", func() {
   114  			It("fails with an 'org not found' message", func() {
   115  				session := helpers.CF("unbind-security-group", securityGroupName, "some-other-org", "some-other-space")
   116  				Eventually(session).Should(Say("FAILED"))
   117  				Eventually(session.Err).Should(Say(`Organization 'some-other-org' not found\.`))
   118  				Eventually(session).Should(Exit(1))
   119  			})
   120  		})
   121  
   122  		When("the org exists", func() {
   123  			var username string
   124  
   125  			BeforeEach(func() {
   126  				username, _ = helpers.GetCredentials()
   127  
   128  				helpers.CreateOrg(orgName)
   129  				helpers.TargetOrg(orgName)
   130  			})
   131  
   132  			AfterEach(func() {
   133  				helpers.QuickDeleteOrg(orgName)
   134  			})
   135  
   136  			When("the space doesn't exist", func() {
   137  				It("fails with a 'space not found' message", func() {
   138  					session := helpers.CF("unbind-security-group", securityGroupName, orgName, "some-other-space")
   139  					Eventually(session).Should(Say("FAILED"))
   140  					Eventually(session.Err).Should(Say(`Space 'some-other-space' not found\.`))
   141  					Eventually(session).Should(Exit(1))
   142  				})
   143  			})
   144  
   145  			When("the space exists", func() {
   146  				BeforeEach(func() {
   147  					helpers.CreateSpace(spaceName)
   148  				})
   149  
   150  				When("the space isn't bound to the security group in any lifecycle", func() {
   151  					It("successfully runs the command", func() {
   152  						session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName)
   153  						Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   154  						Eventually(session).Should(Say("OK"))
   155  						Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   156  						Eventually(session).Should(Exit(0))
   157  					})
   158  				})
   159  
   160  				When("a space is bound to a security group in the running lifecycle", func() {
   161  					BeforeEach(func() {
   162  						Eventually(helpers.CF("bind-security-group", securityGroupName, orgName, spaceName)).Should(Exit(0))
   163  					})
   164  
   165  					When("the lifecycle flag is not set", func() {
   166  						When("the org and space are not provided", func() {
   167  							BeforeEach(func() {
   168  								helpers.TargetOrgAndSpace(orgName, spaceName)
   169  							})
   170  
   171  							It("successfully unbinds the space from the security group", func() {
   172  								session := helpers.CF("unbind-security-group", securityGroupName)
   173  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   174  								Eventually(session).Should(Say("OK"))
   175  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   176  								Eventually(session).Should(Exit(0))
   177  							})
   178  						})
   179  
   180  						When("the org and space are provided", func() {
   181  							BeforeEach(func() {
   182  								helpers.ClearTarget()
   183  							})
   184  
   185  							It("successfully unbinds the space from the security group", func() {
   186  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName)
   187  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   188  								Eventually(session).Should(Say("OK"))
   189  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   190  								Eventually(session).Should(Exit(0))
   191  							})
   192  						})
   193  					})
   194  
   195  					When("the lifecycle flag is running", func() {
   196  						When("the org and space are not provided", func() {
   197  							BeforeEach(func() {
   198  								helpers.TargetOrgAndSpace(orgName, spaceName)
   199  							})
   200  
   201  							It("successfully unbinds the space from the security group", func() {
   202  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "running")
   203  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   204  								Eventually(session).Should(Say("OK"))
   205  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   206  								Eventually(session).Should(Exit(0))
   207  							})
   208  						})
   209  
   210  						When("the org and space are provided", func() {
   211  							BeforeEach(func() {
   212  								helpers.ClearTarget()
   213  							})
   214  
   215  							It("successfully unbinds the space from the security group", func() {
   216  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "running")
   217  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   218  								Eventually(session).Should(Say("OK"))
   219  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   220  								Eventually(session).Should(Exit(0))
   221  							})
   222  						})
   223  					})
   224  
   225  					When("the lifecycle flag is staging", func() {
   226  						When("the org and space are not provided", func() {
   227  							BeforeEach(func() {
   228  								helpers.TargetOrgAndSpace(orgName, spaceName)
   229  							})
   230  
   231  							It("displays an error and exits 1", func() {
   232  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "staging")
   233  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   234  								Eventually(session).Should(Say("OK"))
   235  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'staging'\.`, securityGroupName))
   236  								Eventually(session).Should(Exit(0))
   237  							})
   238  						})
   239  
   240  						When("the org and space are provided", func() {
   241  							BeforeEach(func() {
   242  								helpers.ClearTarget()
   243  							})
   244  
   245  							It("displays an error and exits 1", func() {
   246  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging")
   247  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   248  								Eventually(session).Should(Say("OK"))
   249  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'staging'\.`, securityGroupName))
   250  								Eventually(session).Should(Exit(0))
   251  							})
   252  						})
   253  					})
   254  				})
   255  
   256  				When("a space is bound to a security group in the staging lifecycle", func() {
   257  					BeforeEach(func() {
   258  						Eventually(helpers.CF("bind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging")).Should(Exit(0))
   259  					})
   260  
   261  					When("the lifecycle flag is not set", func() {
   262  						When("the org and space are not provided", func() {
   263  							BeforeEach(func() {
   264  								helpers.TargetOrgAndSpace(orgName, spaceName)
   265  							})
   266  
   267  							It("displays an error and exits 1", func() {
   268  								session := helpers.CF("unbind-security-group", securityGroupName)
   269  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   270  								Eventually(session).Should(Say("OK"))
   271  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   272  								Eventually(session).Should(Exit(0))
   273  							})
   274  						})
   275  
   276  						When("the org and space are provided", func() {
   277  							BeforeEach(func() {
   278  								helpers.ClearTarget()
   279  							})
   280  
   281  							It("displays an error and exits 1", func() {
   282  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName)
   283  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   284  								Eventually(session).Should(Say("OK"))
   285  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   286  								Eventually(session).Should(Exit(0))
   287  							})
   288  						})
   289  					})
   290  
   291  					When("the lifecycle flag is running", func() {
   292  						When("the org and space are not provided", func() {
   293  							BeforeEach(func() {
   294  								helpers.TargetOrgAndSpace(orgName, spaceName)
   295  							})
   296  
   297  							It("displays an error and exits 1", func() {
   298  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "running")
   299  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   300  								Eventually(session).Should(Say("OK"))
   301  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   302  								Eventually(session).Should(Exit(0))
   303  							})
   304  						})
   305  
   306  						When("the org and space are provided", func() {
   307  							BeforeEach(func() {
   308  								helpers.ClearTarget()
   309  							})
   310  
   311  							It("displays an error and exits 1", func() {
   312  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "running")
   313  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   314  								Eventually(session).Should(Say("OK"))
   315  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   316  								Eventually(session).Should(Exit(0))
   317  							})
   318  						})
   319  					})
   320  
   321  					When("the lifecycle flag is staging", func() {
   322  						When("the org and space are not provided", func() {
   323  							BeforeEach(func() {
   324  								helpers.TargetOrgAndSpace(orgName, spaceName)
   325  							})
   326  
   327  							It("successfully unbinds the space from the security group", func() {
   328  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "staging")
   329  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   330  								Eventually(session).Should(Say("OK"))
   331  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   332  								Eventually(session).Should(Exit(0))
   333  							})
   334  						})
   335  
   336  						When("the org and space are provided", func() {
   337  							BeforeEach(func() {
   338  								helpers.ClearTarget()
   339  							})
   340  
   341  							It("successfully unbinds the space from the security group", func() {
   342  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging")
   343  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   344  								Eventually(session).Should(Say("OK"))
   345  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   346  								Eventually(session).Should(Exit(0))
   347  							})
   348  						})
   349  					})
   350  				})
   351  			})
   352  		})
   353  	})
   354  })