github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/spaces_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("spaces command", func() {
    14  	var orgName string
    15  
    16  	BeforeEach(func() {
    17  		orgName = helpers.NewOrgName()
    18  	})
    19  
    20  	Describe("help", func() {
    21  		When("--help flag is set", func() {
    22  			It("displays command usage to output", func() {
    23  				session := helpers.CF("spaces", "--help")
    24  				Eventually(session).Should(Say("NAME:"))
    25  				Eventually(session).Should(Say("spaces - List all spaces in an org"))
    26  				Eventually(session).Should(Say("USAGE:"))
    27  				Eventually(session).Should(Say(regexp.QuoteMeta("cf spaces [--labels SELECTOR]")))
    28  				Eventually(session).Should(Say("EXAMPLES:"))
    29  				Eventually(session).Should(Say("cf spaces"))
    30  				Eventually(session).Should(Say(regexp.QuoteMeta("cf spaces --labels 'environment in (production,staging),tier in (backend)'")))
    31  				Eventually(session).Should(Say(regexp.QuoteMeta("cf spaces --labels 'env=dev,!chargeback-code,tier in (backend,worker)'")))
    32  				Eventually(session).Should(Say("OPTIONS:"))
    33  				Eventually(session).Should(Say(`--labels\s+Selector to filter spaces by labels`))
    34  				Eventually(session).Should(Say("SEE ALSO:"))
    35  				Eventually(session).Should(Say("create-space, set-space-role, space, space-users"))
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	When("the environment is setup correctly", func() {
    42  		var username, spaceName1, spaceName2, spaceName3, spaceName4, spaceName5, spaceName6 string
    43  
    44  		BeforeEach(func() {
    45  			username = helpers.LoginCF()
    46  			helpers.CreateOrg(orgName)
    47  			helpers.TargetOrg(orgName)
    48  
    49  			spaceName1 = helpers.PrefixedRandomName("INTEGRATION-SPACE-DEF")
    50  			spaceName2 = helpers.PrefixedRandomName("INTEGRATION-SPACE-XYZ")
    51  			spaceName3 = helpers.PrefixedRandomName("INTEGRATION-SPACE-jop")
    52  			spaceName4 = helpers.PrefixedRandomName("INTEGRATION-SPACE-ABC")
    53  			spaceName5 = helpers.PrefixedRandomName("INTEGRATION-SPACE-543")
    54  			spaceName6 = helpers.PrefixedRandomName("INTEGRATION-SPACE-125")
    55  			helpers.CreateSpace(spaceName1)
    56  			helpers.CreateSpace(spaceName2)
    57  			helpers.CreateSpace(spaceName3)
    58  			helpers.CreateSpace(spaceName4)
    59  			helpers.CreateSpace(spaceName5)
    60  			helpers.CreateSpace(spaceName6)
    61  		})
    62  
    63  		When("the --labels flag is given", func() {
    64  
    65  			BeforeEach(func() {
    66  				Eventually(helpers.CF("set-label", "space", spaceName1, "environment=production", "tier=backend")).Should(Exit(0))
    67  				Eventually(helpers.CF("set-label", "space", spaceName2, "environment=staging", "tier=frontend")).Should(Exit(0))
    68  			})
    69  
    70  			It("displays spaces with provided labels", func() {
    71  				session := helpers.CF("spaces", "--labels", "environment in (production,staging),tier in (backend)")
    72  				Eventually(session).Should(Say(`Getting spaces in org %s as %s\.\.\.`, orgName, username))
    73  				Eventually(session).Should(Exit(0))
    74  				Expect(session).Should(Say(spaceName1))
    75  				Expect(session).ShouldNot(Say(spaceName2))
    76  				Expect(session).ShouldNot(Say(spaceName3))
    77  				Expect(session).ShouldNot(Say(spaceName4))
    78  				Expect(session).ShouldNot(Say(spaceName5))
    79  				Expect(session).ShouldNot(Say(spaceName6))
    80  			})
    81  
    82  			It("displays no spaces when no labels match", func() {
    83  				session := helpers.CF("spaces", "--labels", "environment in (production,staging),environment notin (production,staging)")
    84  				Eventually(session).Should(Exit(0))
    85  				Expect(session).Should(Say("No spaces found"))
    86  			})
    87  		})
    88  	})
    89  })