github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/shared/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  			someSecurityGroup := helpers.NewSecurityGroup(securityGroupName, "tcp", "127.0.0.1", "8443", "some-description")
   108  			someSecurityGroup.Create()
   109  		})
   110  
   111  		When("the org doesn't exist", func() {
   112  			It("fails with an 'org not found' message", func() {
   113  				session := helpers.CF("unbind-security-group", securityGroupName, "some-other-org", "some-other-space")
   114  				Eventually(session).Should(Say("FAILED"))
   115  				Eventually(session.Err).Should(Say(`Organization 'some-other-org' not found\.`))
   116  				Eventually(session).Should(Exit(1))
   117  			})
   118  		})
   119  
   120  		When("the org exists", func() {
   121  			var username string
   122  
   123  			BeforeEach(func() {
   124  				username, _ = helpers.GetCredentials()
   125  
   126  				helpers.CreateOrg(orgName)
   127  				helpers.TargetOrg(orgName)
   128  			})
   129  
   130  			AfterEach(func() {
   131  				helpers.QuickDeleteOrg(orgName)
   132  			})
   133  
   134  			When("the space doesn't exist", func() {
   135  				It("fails with a 'space not found' message", func() {
   136  					session := helpers.CF("unbind-security-group", securityGroupName, orgName, "some-other-space")
   137  					Eventually(session).Should(Say("FAILED"))
   138  					Eventually(session.Err).Should(Say(`Space 'some-other-space' not found\.`))
   139  					Eventually(session).Should(Exit(1))
   140  				})
   141  			})
   142  
   143  			When("the space exists", func() {
   144  				BeforeEach(func() {
   145  					helpers.CreateSpace(spaceName)
   146  				})
   147  
   148  				When("the space isn't bound to the security group in any lifecycle", func() {
   149  					It("successfully runs the command", func() {
   150  						session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName)
   151  						Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   152  						Eventually(session).Should(Say("OK"))
   153  						Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   154  						Eventually(session).Should(Exit(0))
   155  					})
   156  				})
   157  
   158  				When("a space is bound to a security group in the running lifecycle", func() {
   159  					BeforeEach(func() {
   160  						Eventually(helpers.CF("bind-security-group", securityGroupName, orgName, spaceName)).Should(Exit(0))
   161  					})
   162  
   163  					When("the lifecycle flag is not set", func() {
   164  						When("the org and space are not provided", func() {
   165  							BeforeEach(func() {
   166  								helpers.TargetOrgAndSpace(orgName, spaceName)
   167  							})
   168  
   169  							It("successfully unbinds the space from the security group", func() {
   170  								session := helpers.CF("unbind-security-group", securityGroupName)
   171  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   172  								Eventually(session).Should(Say("OK"))
   173  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   174  								Eventually(session).Should(Exit(0))
   175  							})
   176  						})
   177  
   178  						When("the org and space are provided", func() {
   179  							BeforeEach(func() {
   180  								helpers.ClearTarget()
   181  							})
   182  
   183  							It("successfully unbinds the space from the security group", func() {
   184  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName)
   185  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   186  								Eventually(session).Should(Say("OK"))
   187  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   188  								Eventually(session).Should(Exit(0))
   189  							})
   190  						})
   191  					})
   192  
   193  					When("the lifecycle flag is running", func() {
   194  						When("the org and space are not provided", func() {
   195  							BeforeEach(func() {
   196  								helpers.TargetOrgAndSpace(orgName, spaceName)
   197  							})
   198  
   199  							It("successfully unbinds the space from the security group", func() {
   200  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "running")
   201  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   202  								Eventually(session).Should(Say("OK"))
   203  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   204  								Eventually(session).Should(Exit(0))
   205  							})
   206  						})
   207  
   208  						When("the org and space are provided", func() {
   209  							BeforeEach(func() {
   210  								helpers.ClearTarget()
   211  							})
   212  
   213  							It("successfully unbinds the space from the security group", func() {
   214  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "running")
   215  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   216  								Eventually(session).Should(Say("OK"))
   217  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   218  								Eventually(session).Should(Exit(0))
   219  							})
   220  						})
   221  					})
   222  
   223  					When("the lifecycle flag is staging", func() {
   224  						When("the org and space are not provided", func() {
   225  							BeforeEach(func() {
   226  								helpers.TargetOrgAndSpace(orgName, spaceName)
   227  							})
   228  
   229  							It("displays an error and exits 1", func() {
   230  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "staging")
   231  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   232  								Eventually(session).Should(Say("OK"))
   233  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'staging'\.`, securityGroupName))
   234  								Eventually(session).Should(Exit(0))
   235  							})
   236  						})
   237  
   238  						When("the org and space are provided", func() {
   239  							BeforeEach(func() {
   240  								helpers.ClearTarget()
   241  							})
   242  
   243  							It("displays an error and exits 1", func() {
   244  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging")
   245  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   246  								Eventually(session).Should(Say("OK"))
   247  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'staging'\.`, securityGroupName))
   248  								Eventually(session).Should(Exit(0))
   249  							})
   250  						})
   251  					})
   252  				})
   253  
   254  				When("a space is bound to a security group in the staging lifecycle", func() {
   255  					BeforeEach(func() {
   256  						Eventually(helpers.CF("bind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging")).Should(Exit(0))
   257  					})
   258  
   259  					When("the lifecycle flag is not set", func() {
   260  						When("the org and space are not provided", func() {
   261  							BeforeEach(func() {
   262  								helpers.TargetOrgAndSpace(orgName, spaceName)
   263  							})
   264  
   265  							It("displays an error and exits 1", func() {
   266  								session := helpers.CF("unbind-security-group", securityGroupName)
   267  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   268  								Eventually(session).Should(Say("OK"))
   269  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   270  								Eventually(session).Should(Exit(0))
   271  							})
   272  						})
   273  
   274  						When("the org and space are provided", func() {
   275  							BeforeEach(func() {
   276  								helpers.ClearTarget()
   277  							})
   278  
   279  							It("displays an error and exits 1", func() {
   280  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName)
   281  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   282  								Eventually(session).Should(Say("OK"))
   283  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   284  								Eventually(session).Should(Exit(0))
   285  							})
   286  						})
   287  					})
   288  
   289  					When("the lifecycle flag is running", func() {
   290  						When("the org and space are not provided", func() {
   291  							BeforeEach(func() {
   292  								helpers.TargetOrgAndSpace(orgName, spaceName)
   293  							})
   294  
   295  							It("displays an error and exits 1", func() {
   296  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "running")
   297  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   298  								Eventually(session).Should(Say("OK"))
   299  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   300  								Eventually(session).Should(Exit(0))
   301  							})
   302  						})
   303  
   304  						When("the org and space are provided", func() {
   305  							BeforeEach(func() {
   306  								helpers.ClearTarget()
   307  							})
   308  
   309  							It("displays an error and exits 1", func() {
   310  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "running")
   311  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   312  								Eventually(session).Should(Say("OK"))
   313  								Eventually(session.Err).Should(Say(`Security group %s not bound to this space for lifecycle phase 'running'\.`, securityGroupName))
   314  								Eventually(session).Should(Exit(0))
   315  							})
   316  						})
   317  					})
   318  
   319  					When("the lifecycle flag is staging", func() {
   320  						When("the org and space are not provided", func() {
   321  							BeforeEach(func() {
   322  								helpers.TargetOrgAndSpace(orgName, spaceName)
   323  							})
   324  
   325  							It("successfully unbinds the space from the security group", func() {
   326  								session := helpers.CF("unbind-security-group", securityGroupName, "--lifecycle", "staging")
   327  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   328  								Eventually(session).Should(Say("OK"))
   329  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   330  								Eventually(session).Should(Exit(0))
   331  							})
   332  						})
   333  
   334  						When("the org and space are provided", func() {
   335  							BeforeEach(func() {
   336  								helpers.ClearTarget()
   337  							})
   338  
   339  							It("successfully unbinds the space from the security group", func() {
   340  								session := helpers.CF("unbind-security-group", securityGroupName, orgName, spaceName, "--lifecycle", "staging")
   341  								Eventually(session).Should(Say(`Unbinding security group %s from org %s / space %s as %s\.\.\.`, securityGroupName, orgName, spaceName, username))
   342  								Eventually(session).Should(Say("OK"))
   343  								Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   344  								Eventually(session).Should(Exit(0))
   345  							})
   346  						})
   347  					})
   348  				})
   349  			})
   350  		})
   351  	})
   352  })