github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/shared/isolated/bind_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("bind-security-group command", func() {
    12  	var (
    13  		orgName      string
    14  		secGroupName string
    15  		someOrgName  string
    16  		spaceName1   string
    17  		spaceName2   string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		orgName = helpers.NewOrgName()
    22  		secGroupName = helpers.NewSecurityGroupName()
    23  		someOrgName = helpers.NewOrgName()
    24  		spaceName1 = helpers.NewSpaceName()
    25  		spaceName2 = helpers.NewSpaceName()
    26  
    27  		helpers.LoginCF()
    28  	})
    29  
    30  	Describe("help", func() {
    31  		When("--help flag is set", func() {
    32  			It("Displays command usage to output", func() {
    33  				session := helpers.CF("bind-security-group", "--help")
    34  				Eventually(session).Should(Say("NAME:"))
    35  				Eventually(session).Should(Say(`\s+bind-security-group - Bind a security group to a particular space, or all existing spaces of an org`))
    36  				Eventually(session).Should(Say("USAGE:"))
    37  				Eventually(session).Should(Say(`\s+cf bind-security-group SECURITY_GROUP ORG \[SPACE\] \[--lifecycle \(running \| staging\)\]`))
    38  				Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
    39  				Eventually(session).Should(Say("OPTIONS:"))
    40  				Eventually(session).Should(Say(`\s+--lifecycle      Lifecycle phase the group applies to \(Default: running\)`))
    41  				Eventually(session).Should(Say("SEE ALSO:"))
    42  				Eventually(session).Should(Say(`\s+apps, bind-running-security-group, bind-staging-security-group, restart, security-groups`))
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  	})
    47  
    48  	When("the lifecycle flag is invalid", func() {
    49  		It("outputs a message and usage", func() {
    50  			session := helpers.CF("bind-security-group", secGroupName, someOrgName, "--lifecycle", "invalid")
    51  			Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `invalid' for option `--lifecycle'. Allowed values are: running or staging"))
    52  			Eventually(session).Should(Say("USAGE:"))
    53  			Eventually(session).Should(Exit(1))
    54  		})
    55  	})
    56  
    57  	When("the lifecycle flag has no argument", func() {
    58  		It("outputs a message and usage", func() {
    59  			session := helpers.CF("bind-security-group", secGroupName, someOrgName, "--lifecycle")
    60  			Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `--lifecycle'"))
    61  			Eventually(session).Should(Say("USAGE:"))
    62  			Eventually(session).Should(Exit(1))
    63  		})
    64  	})
    65  
    66  	When("the environment is not setup correctly", func() {
    67  		It("fails with the appropriate errors", func() {
    68  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "bind-security-group", "security-group-name", "org-name", "space-name")
    69  		})
    70  	})
    71  
    72  	When("the input is invalid", func() {
    73  		When("the security group is not provided", func() {
    74  			It("fails with an incorrect usage message and displays help", func() {
    75  				session := helpers.CF("bind-security-group")
    76  				Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SECURITY_GROUP` and `ORG` were not provided"))
    77  				Eventually(session).Should(Say("USAGE:"))
    78  				Eventually(session).Should(Exit(1))
    79  			})
    80  		})
    81  
    82  		When("the org is not provided", func() {
    83  			It("fails with an incorrect usage message and displays help", func() {
    84  				session := helpers.CF("bind-security-group", secGroupName)
    85  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided"))
    86  				Eventually(session).Should(Say("USAGE:"))
    87  				Eventually(session).Should(Exit(1))
    88  			})
    89  		})
    90  	})
    91  
    92  	When("the security group doesn't exist", func() {
    93  		It("fails with a security group not found message", func() {
    94  			session := helpers.CF("bind-security-group", "some-security-group-that-doesn't-exist", someOrgName)
    95  			Eventually(session.Err).Should(Say("Security group 'some-security-group-that-doesn't-exist' not found."))
    96  			Eventually(session).Should(Say("FAILED"))
    97  			Eventually(session).Should(Exit(1))
    98  		})
    99  	})
   100  
   101  	When("the security group exists", func() {
   102  		var someSecurityGroup helpers.SecurityGroup
   103  
   104  		BeforeEach(func() {
   105  			someSecurityGroup = helpers.NewSecurityGroup(secGroupName, "tcp", "0.0.0.0/0", "53", "")
   106  			someSecurityGroup.Create()
   107  		})
   108  
   109  		When("the org doesn't exist", func() {
   110  			It("fails with an org not found message", func() {
   111  				session := helpers.CF("bind-security-group", secGroupName, someOrgName)
   112  				Eventually(session.Err).Should(Say("Organization '%s' not found.", someOrgName))
   113  				Eventually(session).Should(Say("FAILED"))
   114  				Eventually(session).Should(Exit(1))
   115  			})
   116  		})
   117  
   118  		When("the org exists", func() {
   119  			BeforeEach(func() {
   120  				helpers.CreateOrg(orgName)
   121  				helpers.TargetOrg(orgName)
   122  			})
   123  
   124  			AfterEach(func() {
   125  				helpers.QuickDeleteOrg(orgName)
   126  			})
   127  
   128  			When("the space doesn't exist", func() {
   129  				It("fails with a space not found message", func() {
   130  					session := helpers.CF("bind-security-group", secGroupName, orgName, "space-doesnt-exist")
   131  					Eventually(session.Err).Should(Say("Space 'space-doesnt-exist' not found."))
   132  					Eventually(session).Should(Say("FAILED"))
   133  					Eventually(session).Should(Exit(1))
   134  				})
   135  			})
   136  
   137  			When("there are no spaces in this org", func() {
   138  				It("does not bind the security group to any space", func() {
   139  					session := helpers.CF("bind-security-group", secGroupName, orgName)
   140  					Consistently(session).ShouldNot(Say("Assigning security group"))
   141  					Consistently(session).ShouldNot(Say("OK"))
   142  					Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   143  					Eventually(session).Should(Exit(0))
   144  				})
   145  			})
   146  
   147  			When("there are spaces in this org", func() {
   148  				BeforeEach(func() {
   149  					helpers.CreateSpace(spaceName1)
   150  					helpers.CreateSpace(spaceName2)
   151  				})
   152  
   153  				When("the lifecycle flag is not set", func() {
   154  					When("binding to all spaces in an org", func() {
   155  						It("binds the security group to each space", func() {
   156  							session := helpers.CF("bind-security-group", secGroupName, orgName)
   157  							userName, _ := helpers.GetCredentials()
   158  							Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName))
   159  							Eventually(session).Should(Say("OK"))
   160  							Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName))
   161  							Eventually(session).Should(Say("OK"))
   162  							Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   163  							Eventually(session).Should(Exit(0))
   164  						})
   165  					})
   166  				})
   167  
   168  				When("binding to a particular space", func() {
   169  					It("binds the security group to the space", func() {
   170  						session := helpers.CF("bind-security-group", secGroupName, orgName, spaceName1)
   171  						userName, _ := helpers.GetCredentials()
   172  						Eventually(session).Should(Say(`Assigning security group %s to space %s in org %s as %s\.\.\.`, secGroupName, spaceName1, orgName, userName))
   173  						Eventually(session).Should(Say("OK"))
   174  						Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   175  						Eventually(session).Should(Exit(0))
   176  					})
   177  				})
   178  
   179  				When("the lifecycle flag is running", func() {
   180  					When("binding to a particular space", func() {
   181  						It("binds the security group to the space", func() {
   182  							session := helpers.CF("bind-security-group", secGroupName, orgName, spaceName1, "--lifecycle", "running")
   183  							userName, _ := helpers.GetCredentials()
   184  							Eventually(session).Should(Say(`Assigning security group %s to space %s in org %s as %s\.\.\.`, secGroupName, spaceName1, orgName, userName))
   185  							Eventually(session).Should(Say("OK"))
   186  							Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   187  							Eventually(session).Should(Exit(0))
   188  						})
   189  					})
   190  				})
   191  
   192  				When("the lifecycle flag is staging", func() {
   193  					When("binding to all spaces in an org", func() {
   194  						It("binds the security group to each space", func() {
   195  							session := helpers.CF("bind-security-group", secGroupName, orgName, "--lifecycle", "staging")
   196  							userName, _ := helpers.GetCredentials()
   197  							Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName))
   198  							Eventually(session).Should(Say("OK"))
   199  							Eventually(session).Should(Say(`Assigning security group %s to space INTEGRATION-SPACE.* in org %s as %s\.\.\.`, secGroupName, orgName, userName))
   200  							Eventually(session).Should(Say("OK"))
   201  							Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   202  							Eventually(session).Should(Exit(0))
   203  						})
   204  					})
   205  
   206  					When("binding to a particular space", func() {
   207  						It("binds the security group to the space", func() {
   208  							session := helpers.CF("bind-security-group", secGroupName, orgName, spaceName1, "--lifecycle", "staging")
   209  							userName, _ := helpers.GetCredentials()
   210  							Eventually(session).Should(Say(`Assigning security group %s to space %s in org %s as %s\.\.\.`, secGroupName, spaceName1, orgName, userName))
   211  							Eventually(session).Should(Say("OK"))
   212  							Eventually(session).Should(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`))
   213  							Eventually(session).Should(Exit(0))
   214  						})
   215  					})
   216  				})
   217  			})
   218  		})
   219  	})
   220  })