github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+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 Context("when an API endpoint is not set", func() { 35 BeforeEach(func() { 36 helpers.UnsetAPI() 37 }) 38 39 It("displays an error and exits 1", func() { 40 session := helpers.CF("spaces") 41 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 42 Eventually(session).Should(Say("FAILED")) 43 Eventually(session).Should(Exit(1)) 44 }) 45 }) 46 47 Context("when an API endpoint is set", func() { 48 Context("when the user is not logged in", func() { 49 It("displays an error and exits 1", func() { 50 session := helpers.CF("spaces") 51 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 52 Eventually(session).Should(Say("FAILED")) 53 Eventually(session).Should(Exit(1)) 54 }) 55 }) 56 57 Context("when the user is logged in", func() { 58 BeforeEach(func() { 59 helpers.LoginCF() 60 }) 61 62 Context("when an org is not targeted", func() { 63 It("displays an error and exits 1", func() { 64 session := helpers.CF("spaces") 65 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 66 Eventually(session).Should(Say("FAILED")) 67 Eventually(session).Should(Exit(1)) 68 }) 69 }) 70 }) 71 }) 72 }) 73 74 Context("when the environment is setup correctly", func() { 75 var username string 76 77 BeforeEach(func() { 78 username = helpers.LoginCF() 79 helpers.CreateOrg(orgName) 80 helpers.TargetOrg(orgName) 81 }) 82 83 Context("when there are no spaces", func() { 84 It("displays no spaces found", func() { 85 session := helpers.CF("spaces") 86 Eventually(session).Should(Say("Getting spaces in org %s as %s\\.\\.\\.", orgName, username)) 87 Eventually(session).Should(Say("")) 88 Eventually(session).Should(Say("No spaces found\\.")) 89 Eventually(session).Should(Exit(0)) 90 }) 91 }) 92 93 Context("when there are multiple spaces", func() { 94 var spaceName1, spaceName2, spaceName3, spaceName4, spaceName5, spaceName6 string 95 96 BeforeEach(func() { 97 spaceName1 = helpers.PrefixedRandomName("INTEGRATION-SPACE-DEF") 98 spaceName2 = helpers.PrefixedRandomName("INTEGRATION-SPACE-XYZ") 99 spaceName3 = helpers.PrefixedRandomName("INTEGRATION-SPACE-jop") 100 spaceName4 = helpers.PrefixedRandomName("INTEGRATION-SPACE-ABC") 101 spaceName5 = helpers.PrefixedRandomName("INTEGRATION-SPACE-123") 102 spaceName6 = helpers.PrefixedRandomName("INTEGRATION-SPACE--") 103 helpers.CreateSpace(spaceName1) 104 helpers.CreateSpace(spaceName2) 105 helpers.CreateSpace(spaceName3) 106 helpers.CreateSpace(spaceName4) 107 helpers.CreateSpace(spaceName5) 108 helpers.CreateSpace(spaceName6) 109 }) 110 111 It("displays a list of all spaces in the org in alphabetical order", func() { 112 session := helpers.CF("spaces") 113 Eventually(session).Should(Say("Getting spaces in org %s as %s\\.\\.\\.", orgName, username)) 114 Eventually(session).Should(Say("")) 115 Eventually(session).Should(Say("name")) 116 Eventually(session).Should(Say("%s\n%s\n%s\n%s\n%s\n%s", spaceName6, spaceName5, spaceName4, spaceName1, spaceName3, spaceName2)) 117 Eventually(session).Should(Exit(0)) 118 }) 119 }) 120 }) 121 })