github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/isolated/spaces_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("spaces command", func() {
    12  	var orgName string
    13  
    14  	BeforeEach(func() {
    15  		orgName = helpers.NewOrgName()
    16  	})
    17  
    18  	Describe("help", func() {
    19  		Context("when --help flag is set", func() {
    20  			It("displays command usage to output", func() {
    21  				session := helpers.CF("spaces", "--help")
    22  				Eventually(session).Should(Say("NAME:"))
    23  				Eventually(session).Should(Say("\\s+spaces - List all spaces in an org"))
    24  				Eventually(session).Should(Say("USAGE:"))
    25  				Eventually(session).Should(Say("\\s+cf spaces"))
    26  				Eventually(session).Should(Say("SEE ALSO:"))
    27  				Eventually(session).Should(Say("\\s+target"))
    28  				Eventually(session).Should(Exit(0))
    29  			})
    30  		})
    31  	})
    32  
    33  	Context("when the environment is not setup correctly", func() {
    34  		It("fails with the appropriate errors", func() {
    35  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "spaces")
    36  		})
    37  	})
    38  
    39  	Context("when the environment is setup correctly", func() {
    40  		var username string
    41  
    42  		BeforeEach(func() {
    43  			username = helpers.LoginCF()
    44  			helpers.CreateOrg(orgName)
    45  			helpers.TargetOrg(orgName)
    46  		})
    47  
    48  		Context("when there are no spaces", func() {
    49  			It("displays no spaces found", func() {
    50  				session := helpers.CF("spaces")
    51  				Eventually(session).Should(Say("Getting spaces in org %s as %s\\.\\.\\.", orgName, username))
    52  				Eventually(session).Should(Say(""))
    53  				Eventually(session).Should(Say("No spaces found\\."))
    54  				Eventually(session).Should(Exit(0))
    55  			})
    56  		})
    57  
    58  		Context("when there are multiple spaces", func() {
    59  			var spaceName1, spaceName2, spaceName3, spaceName4, spaceName5, spaceName6 string
    60  
    61  			BeforeEach(func() {
    62  				spaceName1 = helpers.PrefixedRandomName("INTEGRATION-SPACE-DEF")
    63  				spaceName2 = helpers.PrefixedRandomName("INTEGRATION-SPACE-XYZ")
    64  				spaceName3 = helpers.PrefixedRandomName("INTEGRATION-SPACE-jop")
    65  				spaceName4 = helpers.PrefixedRandomName("INTEGRATION-SPACE-ABC")
    66  				spaceName5 = helpers.PrefixedRandomName("INTEGRATION-SPACE-123")
    67  				spaceName6 = helpers.PrefixedRandomName("INTEGRATION-SPACE--")
    68  				helpers.CreateSpace(spaceName1)
    69  				helpers.CreateSpace(spaceName2)
    70  				helpers.CreateSpace(spaceName3)
    71  				helpers.CreateSpace(spaceName4)
    72  				helpers.CreateSpace(spaceName5)
    73  				helpers.CreateSpace(spaceName6)
    74  			})
    75  
    76  			It("displays a list of all spaces in the org in alphabetical order", func() {
    77  				session := helpers.CF("spaces")
    78  				Eventually(session).Should(Say("Getting spaces in org %s as %s\\.\\.\\.", orgName, username))
    79  				Eventually(session).Should(Say(""))
    80  				Eventually(session).Should(Say("name"))
    81  				Eventually(session).Should(Say("%s\n%s\n%s\n%s\n%s\n%s", spaceName6, spaceName5, spaceName4, spaceName1, spaceName3, spaceName2))
    82  				Eventually(session).Should(Exit(0))
    83  			})
    84  		})
    85  	})
    86  })