github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/commands/space/rename_space_test.go (about) 1 package space_test 2 3 import ( 4 testapi "github.com/cloudfoundry/cli/cf/api/fakes" 5 . "github.com/cloudfoundry/cli/cf/commands/space" 6 "github.com/cloudfoundry/cli/cf/configuration/core_config" 7 "github.com/cloudfoundry/cli/cf/models" 8 testcmd "github.com/cloudfoundry/cli/testhelpers/commands" 9 testconfig "github.com/cloudfoundry/cli/testhelpers/configuration" 10 testreq "github.com/cloudfoundry/cli/testhelpers/requirements" 11 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 15 . "github.com/cloudfoundry/cli/testhelpers/matchers" 16 ) 17 18 var _ = Describe("rename-space command", func() { 19 var ( 20 ui *testterm.FakeUI 21 configRepo core_config.ReadWriter 22 requirementsFactory *testreq.FakeReqFactory 23 spaceRepo *testapi.FakeSpaceRepository 24 ) 25 26 BeforeEach(func() { 27 ui = new(testterm.FakeUI) 28 configRepo = testconfig.NewRepositoryWithDefaults() 29 requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true} 30 spaceRepo = &testapi.FakeSpaceRepository{} 31 }) 32 33 var callRenameSpace = func(args []string) bool { 34 cmd := NewRenameSpace(ui, configRepo, spaceRepo) 35 return testcmd.RunCommand(cmd, args, requirementsFactory) 36 } 37 38 Describe("when the user is not logged in", func() { 39 It("does not pass requirements", func() { 40 requirementsFactory.LoginSuccess = false 41 42 Expect(callRenameSpace([]string{"my-space", "my-new-space"})).To(BeFalse()) 43 }) 44 }) 45 46 Describe("when the user has not targeted an org", func() { 47 It("does not pass requirements", func() { 48 requirementsFactory.TargetedOrgSuccess = false 49 50 Expect(callRenameSpace([]string{"my-space", "my-new-space"})).To(BeFalse()) 51 }) 52 }) 53 54 Describe("when the user provides fewer than two args", func() { 55 It("fails with usage", func() { 56 callRenameSpace([]string{"foo"}) 57 Expect(ui.FailedWithUsage).To(BeTrue()) 58 }) 59 }) 60 61 Describe("when the user is logged in and has provided an old and new space name", func() { 62 BeforeEach(func() { 63 space := models.Space{} 64 space.Name = "the-old-space-name" 65 space.Guid = "the-old-space-guid" 66 requirementsFactory.Space = space 67 }) 68 69 It("renames a space", func() { 70 originalSpaceName := configRepo.SpaceFields().Name 71 callRenameSpace([]string{"the-old-space-name", "my-new-space"}) 72 73 Expect(ui.Outputs).To(ContainSubstrings( 74 []string{"Renaming space", "the-old-space-name", "my-new-space", "my-org", "my-user"}, 75 []string{"OK"}, 76 )) 77 78 Expect(spaceRepo.RenameSpaceGuid).To(Equal("the-old-space-guid")) 79 Expect(spaceRepo.RenameNewName).To(Equal("my-new-space")) 80 Expect(configRepo.SpaceFields().Name).To(Equal(originalSpaceName)) 81 }) 82 83 Describe("renaming the space the user has targeted", func() { 84 BeforeEach(func() { 85 configRepo.SetSpaceFields(requirementsFactory.Space.SpaceFields) 86 }) 87 88 It("renames the targeted space", func() { 89 callRenameSpace([]string{"the-old-space-name", "my-new-space-name"}) 90 Expect(configRepo.SpaceFields().Name).To(Equal("my-new-space-name")) 91 }) 92 }) 93 }) 94 })