github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/commands/servicebroker/update_service_broker_test.go (about) 1 package servicebroker_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/api/apifakes" 5 "code.cloudfoundry.org/cli/cf/commandregistry" 6 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 7 "code.cloudfoundry.org/cli/cf/models" 8 "code.cloudfoundry.org/cli/cf/requirements" 9 "code.cloudfoundry.org/cli/cf/requirements/requirementsfakes" 10 testcmd "code.cloudfoundry.org/cli/util/testhelpers/commands" 11 testconfig "code.cloudfoundry.org/cli/util/testhelpers/configuration" 12 testterm "code.cloudfoundry.org/cli/util/testhelpers/terminal" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 16 . "code.cloudfoundry.org/cli/util/testhelpers/matchers" 17 ) 18 19 var _ = Describe("update-service-broker command", func() { 20 var ( 21 ui *testterm.FakeUI 22 requirementsFactory *requirementsfakes.FakeFactory 23 configRepo coreconfig.Repository 24 serviceBrokerRepo *apifakes.FakeServiceBrokerRepository 25 deps commandregistry.Dependency 26 ) 27 28 updateCommandDependency := func(pluginCall bool) { 29 deps.UI = ui 30 deps.RepoLocator = deps.RepoLocator.SetServiceBrokerRepository(serviceBrokerRepo) 31 deps.Config = configRepo 32 commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("update-service-broker").SetDependency(deps, pluginCall)) 33 } 34 35 BeforeEach(func() { 36 configRepo = testconfig.NewRepositoryWithDefaults() 37 ui = &testterm.FakeUI{} 38 requirementsFactory = new(requirementsfakes.FakeFactory) 39 serviceBrokerRepo = new(apifakes.FakeServiceBrokerRepository) 40 }) 41 42 runCommand := func(args ...string) bool { 43 return testcmd.RunCLICommand("update-service-broker", args, requirementsFactory, updateCommandDependency, false, ui) 44 } 45 46 Describe("requirements", func() { 47 It("fails with usage when invoked without exactly four args", func() { 48 requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) 49 50 runCommand("arg1", "arg2", "arg3") 51 Expect(ui.Outputs()).To(ContainSubstrings( 52 []string{"Incorrect Usage", "Requires", "arguments"}, 53 )) 54 }) 55 56 It("fails when not logged in", func() { 57 requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) 58 Expect(runCommand("heeeeeeey", "yooouuuuuuu", "guuuuuuuuys", "ヾ(@*ー⌒ー*@)ノ")).To(BeFalse()) 59 }) 60 }) 61 62 Context("when logged in", func() { 63 BeforeEach(func() { 64 requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) 65 broker := models.ServiceBroker{} 66 broker.Name = "my-found-broker" 67 broker.GUID = "my-found-broker-guid" 68 serviceBrokerRepo.FindByNameReturns(broker, nil) 69 }) 70 71 It("updates the service broker with the provided properties", func() { 72 runCommand("my-broker", "new-username", "new-password", "new-url") 73 74 Expect(serviceBrokerRepo.FindByNameArgsForCall(0)).To(Equal("my-broker")) 75 76 Expect(ui.Outputs()).To(ContainSubstrings( 77 []string{"Updating service broker", "my-found-broker", "my-user"}, 78 []string{"OK"}, 79 )) 80 81 expectedServiceBroker := models.ServiceBroker{} 82 expectedServiceBroker.Name = "my-found-broker" 83 expectedServiceBroker.Username = "new-username" 84 expectedServiceBroker.Password = "new-password" 85 expectedServiceBroker.URL = "new-url" 86 expectedServiceBroker.GUID = "my-found-broker-guid" 87 88 Expect(serviceBrokerRepo.UpdateArgsForCall(0)).To(Equal(expectedServiceBroker)) 89 }) 90 }) 91 })