github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/commands/application/rename_test.go (about) 1 package application_test 2 3 import ( 4 testApplication "github.com/cloudfoundry/cli/cf/api/applications/fakes" 5 "github.com/cloudfoundry/cli/cf/configuration/core_config" 6 "github.com/cloudfoundry/cli/cf/models" 7 testcmd "github.com/cloudfoundry/cli/testhelpers/commands" 8 testconfig "github.com/cloudfoundry/cli/testhelpers/configuration" 9 testreq "github.com/cloudfoundry/cli/testhelpers/requirements" 10 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 11 12 . "github.com/cloudfoundry/cli/cf/commands/application" 13 . "github.com/cloudfoundry/cli/testhelpers/matchers" 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 ) 17 18 var _ = Describe("Rename command", func() { 19 var ( 20 ui *testterm.FakeUI 21 requirementsFactory *testreq.FakeReqFactory 22 configRepo core_config.ReadWriter 23 appRepo *testApplication.FakeApplicationRepository 24 ) 25 26 BeforeEach(func() { 27 ui = &testterm.FakeUI{} 28 configRepo = testconfig.NewRepositoryWithDefaults() 29 requirementsFactory = &testreq.FakeReqFactory{} 30 appRepo = &testApplication.FakeApplicationRepository{} 31 }) 32 33 runCommand := func(args ...string) bool { 34 return testcmd.RunCommand(NewRenameApp(ui, configRepo, appRepo), args, requirementsFactory) 35 } 36 37 Describe("requirements", func() { 38 It("fails with usage when not invoked with an old name and a new name", func() { 39 requirementsFactory.LoginSuccess = true 40 runCommand("foo") 41 Expect(ui.FailedWithUsage).To(BeTrue()) 42 }) 43 44 It("fails when not logged in", func() { 45 Expect(runCommand("my-app", "my-new-app")).To(BeFalse()) 46 }) 47 }) 48 49 It("renames an application", func() { 50 app := models.Application{} 51 app.Name = "my-app" 52 app.Guid = "my-app-guid" 53 requirementsFactory.LoginSuccess = true 54 requirementsFactory.Application = app 55 runCommand("my-app", "my-new-app") 56 57 Expect(appRepo.UpdateAppGuid).To(Equal(app.Guid)) 58 Expect(*appRepo.UpdateParams.Name).To(Equal("my-new-app")) 59 Expect(ui.Outputs).To(ContainSubstrings( 60 []string{"Renaming app", "my-app", "my-new-app", "my-org", "my-space", "my-user"}, 61 []string{"OK"}, 62 )) 63 }) 64 })