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