github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/security_groups_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("security-groups command", func() {
    13  	var (
    14  		session *Session
    15  	)
    16  
    17  	Describe("help", func() {
    18  		When("--help flag is provided", func() {
    19  			It("displays command usage to output", func() {
    20  				session = helpers.CF("security-groups", "--help")
    21  				Eventually(session).Should(Say("NAME:"))
    22  				Eventually(session).Should(Say("security-groups - List all security groups"))
    23  				Eventually(session).Should(Say("USAGE:"))
    24  				Eventually(session).Should(Say("cf security-groups"))
    25  				Eventually(session).Should(Say("SEE ALSO:"))
    26  				Eventually(session).Should(Say("bind-running-security-group, bind-security-group, bind-staging-security-group, security-group"))
    27  				Eventually(session).Should(Exit(0))
    28  			})
    29  		})
    30  	})
    31  
    32  	When("the environment is not setup correctly", func() {
    33  		It("fails with the appropriate errors", func() {
    34  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "security-groups")
    35  		})
    36  	})
    37  
    38  	When("the environment is set up correctly", func() {
    39  		BeforeEach(func() {
    40  			helpers.LoginCF()
    41  		})
    42  
    43  		JustBeforeEach(func() {
    44  			session = helpers.CF("security-groups")
    45  		})
    46  
    47  		When("there are security groups", func() {
    48  			var (
    49  				username string
    50  
    51  				securityGroup1 resources.SecurityGroup
    52  				securityGroup2 resources.SecurityGroup
    53  				securityGroup3 resources.SecurityGroup
    54  				securityGroup4 resources.SecurityGroup
    55  				securityGroup5 resources.SecurityGroup
    56  				securityGroup6 resources.SecurityGroup
    57  				securityGroup7 resources.SecurityGroup
    58  
    59  				org11 string
    60  				org12 string
    61  				org13 string
    62  				org21 string
    63  				org23 string
    64  				org33 string
    65  
    66  				space11 string
    67  				space12 string
    68  				space13 string
    69  				space21 string
    70  				space22 string
    71  				space23 string
    72  				space31 string
    73  				space32 string
    74  				space33 string
    75  
    76  				ports1 string
    77  				ports2 string
    78  				ports3 string
    79  				ports4 string
    80  				ports5 string
    81  				ports6 string
    82  				ports7 string
    83  
    84  				description1 string
    85  				description2 string
    86  				description3 string
    87  				description4 string
    88  				description5 string
    89  				description6 string
    90  				description7 string
    91  			)
    92  
    93  			BeforeEach(func() {
    94  				helpers.ClearTarget()
    95  
    96  				username, _ = helpers.GetCredentials()
    97  
    98  				ports1 = "81,443"
    99  				ports2 = "82,444"
   100  				ports3 = "83,445"
   101  				ports4 = "84,446"
   102  				ports5 = "85,447"
   103  				ports6 = "86,448"
   104  				ports7 = "87,449"
   105  
   106  				description1 = "SG1"
   107  				description2 = "SG2"
   108  				description3 = "SG3"
   109  				description4 = "SG4"
   110  				description5 = "SG5"
   111  				description6 = "SG6"
   112  				description7 = "SG7"
   113  
   114  				// Create Security Groups, Organizations, and Spaces with predictable and unique names for testing sorting
   115  				securityGroup1 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-1"), "tcp", "11.1.1.0/24", &ports1, &description1)
   116  				helpers.CreateSecurityGroup(securityGroup1)
   117  				securityGroup2 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-2"), "tcp", "11.1.1.0/24", &ports2, &description2)
   118  				helpers.CreateSecurityGroup(securityGroup2)
   119  				securityGroup3 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-3"), "tcp", "11.1.1.0/24", &ports3, &description3)
   120  				helpers.CreateSecurityGroup(securityGroup3)
   121  				securityGroup4 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-4"), "tcp", "11.1.1.0/24", &ports4, &description4)
   122  				helpers.CreateSecurityGroup(securityGroup4)
   123  				securityGroup5 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-5"), "tcp", "11.1.1.0/24", &ports5, &description5)
   124  				helpers.CreateSecurityGroup(securityGroup5)
   125  				securityGroup6 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-6"), "tcp", "11.1.1.0/24", &ports6, &description6)
   126  				helpers.CreateSecurityGroup(securityGroup6)
   127  				securityGroup7 = helpers.NewSecurityGroup(helpers.PrefixedRandomName("INTEGRATION-SEC-GROUP-7"), "tcp", "11.1.1.0/24", &ports7, &description7)
   128  				helpers.CreateSecurityGroup(securityGroup7)
   129  
   130  				org11 = helpers.PrefixedRandomName("INTEGRATION-ORG-11")
   131  				org12 = helpers.PrefixedRandomName("INTEGRATION-ORG-12")
   132  				org13 = helpers.PrefixedRandomName("INTEGRATION-ORG-13")
   133  				org21 = helpers.PrefixedRandomName("INTEGRATION-ORG-21")
   134  				org23 = helpers.PrefixedRandomName("INTEGRATION-ORG-23")
   135  				org33 = helpers.PrefixedRandomName("INTEGRATION-ORG-33")
   136  
   137  				space11 = helpers.PrefixedRandomName("INTEGRATION-SPACE-11")
   138  				space12 = helpers.PrefixedRandomName("INTEGRATION-SPACE-12")
   139  				space13 = helpers.PrefixedRandomName("INTEGRATION-SPACE-13")
   140  				space21 = helpers.PrefixedRandomName("INTEGRATION-SPACE-21")
   141  				space22 = helpers.PrefixedRandomName("INTEGRATION-SPACE-22")
   142  				space23 = helpers.PrefixedRandomName("INTEGRATION-SPACE-23")
   143  				space31 = helpers.PrefixedRandomName("INTEGRATION-SPACE-31")
   144  				space32 = helpers.PrefixedRandomName("INTEGRATION-SPACE-32")
   145  				space33 = helpers.PrefixedRandomName("INTEGRATION-SPACE-33")
   146  
   147  				helpers.CreateOrgAndSpace(org11, space11)
   148  				Eventually(helpers.CF("bind-running-security-group", securityGroup1.Name)).Should(Exit(0))
   149  				Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org11, space11)).Should(Exit(0))
   150  				helpers.CreateSpace(space22)
   151  				Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org11, space22, "--lifecycle", "staging")).Should(Exit(0))
   152  				helpers.CreateSpace(space32)
   153  				Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org11, space32)).Should(Exit(0))
   154  				helpers.CreateOrgAndSpace(org12, space12)
   155  				Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org12, space12, "--lifecycle", "staging")).Should(Exit(0))
   156  				helpers.CreateOrgAndSpace(org13, space13)
   157  				Eventually(helpers.CF("bind-staging-security-group", securityGroup2.Name)).Should(Exit(0))
   158  				Eventually(helpers.CF("bind-security-group", securityGroup1.Name, org13, space13)).Should(Exit(0))
   159  				helpers.CreateOrgAndSpace(org21, space21)
   160  				Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org21, space21)).Should(Exit(0))
   161  				helpers.CreateOrgAndSpace(org23, space23)
   162  				Eventually(helpers.CF("bind-security-group", securityGroup2.Name, org23, space23)).Should(Exit(0))
   163  				helpers.CreateSpace(space31)
   164  				Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org23, space31)).Should(Exit(0))
   165  				helpers.CreateOrgAndSpace(org33, space33)
   166  				Eventually(helpers.CF("bind-security-group", securityGroup4.Name, org33, space33)).Should(Exit(0))
   167  				Eventually(helpers.CF("bind-running-security-group", securityGroup5.Name)).Should(Exit(0))
   168  				Eventually(helpers.CF("bind-staging-security-group", securityGroup6.Name)).Should(Exit(0))
   169  				Eventually(helpers.CF("bind-running-security-group", securityGroup7.Name)).Should(Exit(0))
   170  				Eventually(helpers.CF("bind-staging-security-group", securityGroup7.Name)).Should(Exit(0))
   171  			})
   172  
   173  			AfterEach(func() {
   174  				helpers.QuickDeleteOrg(org11)
   175  				helpers.QuickDeleteOrg(org12)
   176  				helpers.QuickDeleteOrg(org13)
   177  				helpers.QuickDeleteOrg(org21)
   178  				helpers.QuickDeleteOrg(org23)
   179  				helpers.QuickDeleteOrg(org33)
   180  			})
   181  
   182  			It("lists the security groups", func() {
   183  				Eventually(session).Should(Say("Getting security groups as %s", username))
   184  				Eventually(session).Should(Say(`OK\n\n`))
   185  				Eventually(session).Should(Say(`\s+name\s+organization\s+space\s+lifecycle`))
   186  				// How to test alphabetization with auto-generated names?  Here's how.
   187  				Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+running`, securityGroup1.Name))
   188  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup1.Name, org11, space11))
   189  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+staging`, securityGroup1.Name, org12, space12))
   190  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup1.Name, org13, space13))
   191  				Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+staging`, securityGroup2.Name))
   192  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+staging`, securityGroup2.Name, org11, space22))
   193  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup2.Name, org21, space21))
   194  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup2.Name, org23, space23))
   195  				Eventually(session).Should(Say(`#\d+\s+%s`, securityGroup3.Name))
   196  				Eventually(session).Should(Say(`#\d+\s+%s\s+%s\s+%s\s+running`, securityGroup4.Name, org11, space32))
   197  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup4.Name, org23, space31))
   198  				Eventually(session).Should(Say(`\s+%s\s+%s\s+%s\s+running`, securityGroup4.Name, org33, space33))
   199  				Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+running`, securityGroup5.Name))
   200  				Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+staging`, securityGroup6.Name))
   201  				Eventually(session).Should(Say(`#\d+\s+%s\s+<all>\s+<all>\s+running`, securityGroup7.Name))
   202  				Eventually(session).Should(Say(`\s+%s\s+<all>\s+<all>\s+staging`, securityGroup7.Name))
   203  				Eventually(session).Should(Exit(0))
   204  			})
   205  		})
   206  	})
   207  })