github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/commands/buildpack/rename_buildpack_test.go (about) 1 package buildpack_test 2 3 import ( 4 testapi "github.com/cloudfoundry/cli/cf/api/fakes" 5 . "github.com/cloudfoundry/cli/cf/commands/buildpack" 6 "github.com/cloudfoundry/cli/cf/errors" 7 "github.com/cloudfoundry/cli/cf/models" 8 testcmd "github.com/cloudfoundry/cli/testhelpers/commands" 9 testreq "github.com/cloudfoundry/cli/testhelpers/requirements" 10 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 14 . "github.com/cloudfoundry/cli/testhelpers/matchers" 15 ) 16 17 var _ = Describe("rename-buildpack command", func() { 18 var ( 19 cmd *RenameBuildpack 20 fakeRepo *testapi.FakeBuildpackRepository 21 ui *testterm.FakeUI 22 requirementsFactory *testreq.FakeReqFactory 23 ) 24 25 BeforeEach(func() { 26 requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, BuildpackSuccess: true} 27 ui = new(testterm.FakeUI) 28 fakeRepo = &testapi.FakeBuildpackRepository{} 29 cmd = NewRenameBuildpack(ui, fakeRepo) 30 }) 31 32 runCommand := func(args ...string) bool { 33 return testcmd.RunCommand(cmd, args, requirementsFactory) 34 } 35 36 It("fails requirements when called without the current name and the new name to use", func() { 37 passed := runCommand("my-buildpack-name") 38 Expect(ui.FailedWithUsage).To(BeTrue()) 39 Expect(passed).To(BeFalse()) 40 }) 41 42 Context("when logged in", func() { 43 BeforeEach(func() { 44 requirementsFactory.LoginSuccess = true 45 }) 46 47 It("renames a buildpack", func() { 48 fakeRepo.FindByNameBuildpack = models.Buildpack{ 49 Name: "my-buildpack", 50 Guid: "my-buildpack-guid", 51 } 52 53 runCommand("my-buildpack", "new-buildpack") 54 Expect(ui.Outputs).To(ContainSubstrings( 55 []string{"Renaming buildpack", "my-buildpack"}, 56 []string{"OK"}, 57 )) 58 }) 59 60 It("fails when the buildpack does not exist", func() { 61 fakeRepo.FindByNameNotFound = true 62 63 runCommand("my-buildpack1", "new-buildpack") 64 Expect(ui.Outputs).To(ContainSubstrings( 65 []string{"Renaming buildpack", "my-buildpack"}, 66 []string{"FAILED"}, 67 []string{"Buildpack my-buildpack1 not found"}, 68 )) 69 }) 70 71 It("fails when there is an error updating the buildpack", func() { 72 fakeRepo.FindByNameBuildpack = models.Buildpack{ 73 Name: "my-buildpack", 74 Guid: "my-buildpack-guid", 75 } 76 fakeRepo.UpdateBuildpackReturns.Error = errors.New("SAD TROMBONE") 77 78 runCommand("my-buildpack1", "new-buildpack") 79 Expect(ui.Outputs).To(ContainSubstrings( 80 []string{"Renaming buildpack", "my-buildpack"}, 81 []string{"SAD TROMBONE"}, 82 )) 83 }) 84 }) 85 })