github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/orgs_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gbytes"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("orgs command", func() {
    14  	Describe("help", func() {
    15  		When("--help flag is set", func() {
    16  			It("displays command usage to output", func() {
    17  				session := helpers.CF("orgs", "--help")
    18  				Eventually(session).Should(Say("NAME:"))
    19  				Eventually(session).Should(Say("orgs - List all orgs"))
    20  				Eventually(session).Should(Say("USAGE:"))
    21  				Eventually(session).Should(Say(regexp.QuoteMeta("cf orgs [--labels SELECTOR]")))
    22  				Eventually(session).Should(Say("EXAMPLES:"))
    23  				Eventually(session).Should(Say("cf orgs"))
    24  				Eventually(session).Should(Say(regexp.QuoteMeta("cf orgs --labels 'environment in (production,staging),tier in (backend)'")))
    25  				Eventually(session).Should(Say(regexp.QuoteMeta("cf orgs --labels 'env=dev,!chargeback-code,tier in (backend,worker)'")))
    26  				Eventually(session).Should(Say("ALIAS:"))
    27  				Eventually(session).Should(Say("o"))
    28  				Eventually(session).Should(Say("OPTIONS:"))
    29  				Eventually(session).Should(Say(`--labels\s+Selector to filter orgs by labels`))
    30  				Eventually(session).Should(Say("SEE ALSO:"))
    31  				Eventually(session).Should(Say("create-org, org, org-users, set-org-role"))
    32  				Eventually(session).Should(Exit(0))
    33  			})
    34  		})
    35  	})
    36  
    37  	When("the environment is not setup correctly", func() {
    38  		It("fails with the appropriate errors", func() {
    39  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "orgs")
    40  		})
    41  	})
    42  
    43  	When("the environment is setup correctly", func() {
    44  		var username string
    45  
    46  		BeforeEach(func() {
    47  			username = helpers.LoginCF()
    48  		})
    49  
    50  		When("there are multiple orgs", func() {
    51  			var orgName1, orgName2, orgName3, orgName4, orgName5 string
    52  
    53  			BeforeEach(func() {
    54  				orgName1 = helpers.PrefixedRandomName("INTEGRATION-ORG-XYZ")
    55  				orgName2 = helpers.PrefixedRandomName("INTEGRATION-ORG-456")
    56  				orgName3 = helpers.PrefixedRandomName("INTEGRATION-ORG-ABC")
    57  				orgName4 = helpers.PrefixedRandomName("INTEGRATION-ORG-123")
    58  				orgName5 = helpers.PrefixedRandomName("INTEGRATION-ORG-ghi")
    59  				helpers.CreateOrg(orgName1)
    60  				helpers.CreateOrg(orgName2)
    61  				helpers.CreateOrg(orgName3)
    62  				helpers.CreateOrg(orgName4)
    63  				helpers.CreateOrg(orgName5)
    64  			})
    65  
    66  			AfterEach(func() {
    67  				helpers.QuickDeleteOrg(orgName1)
    68  				helpers.QuickDeleteOrg(orgName2)
    69  				helpers.QuickDeleteOrg(orgName3)
    70  				helpers.QuickDeleteOrg(orgName4)
    71  				helpers.QuickDeleteOrg(orgName5)
    72  			})
    73  
    74  			It("displays a list of all orgs", func() {
    75  				session := helpers.CF("orgs")
    76  				Eventually(session).Should(Say(`Getting orgs as %s\.\.\.`, username))
    77  				Eventually(session).Should(Say(""))
    78  				Eventually(session).Should(Say("name"))
    79  				Eventually(session).Should(Say("%s", orgName4))
    80  				Eventually(session).Should(Say("%s", orgName2))
    81  				Eventually(session).Should(Say("%s", orgName3))
    82  				Eventually(session).Should(Say("%s", orgName5))
    83  				Eventually(session).Should(Say("%s", orgName1))
    84  				Eventually(session).Should(Exit(0))
    85  			})
    86  
    87  			When("the --labels flag is given", func() {
    88  				When("the --labels selector is malformed", func() {
    89  					It("errors", func() {
    90  						session := helpers.CF("orgs", "--labels", "malformed in (")
    91  						Eventually(session).Should(Exit(1))
    92  					})
    93  				})
    94  
    95  				When("there are labels on an org", func() {
    96  					BeforeEach(func() {
    97  						Eventually(helpers.CF("set-label", "org", orgName1, "environment=production", "tier=backend")).Should(Exit(0))
    98  						Eventually(helpers.CF("set-label", "org", orgName2, "environment=staging", "tier=frontend")).Should(Exit(0))
    99  					})
   100  
   101  					It("displays only the organizations with labels that match the expression", func() {
   102  						session := helpers.CF("orgs", "--labels", "environment in (production,staging),tier in (backend)")
   103  						Eventually(session).Should(Exit(0))
   104  						Expect(session).ShouldNot(Say(orgName2))
   105  						Expect(session).Should(Say(orgName1))
   106  					})
   107  				})
   108  			})
   109  		})
   110  	})
   111  })