github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/servicebroker/update_service_broker_test.go (about)

     1  package servicebroker_test
     2  
     3  import (
     4  	testapi "github.com/cloudfoundry/cli/cf/api/fakes"
     5  	"github.com/cloudfoundry/cli/cf/command_registry"
     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("update-service-broker command", func() {
    19  	var (
    20  		ui                  *testterm.FakeUI
    21  		requirementsFactory *testreq.FakeReqFactory
    22  		configRepo          core_config.Repository
    23  		serviceBrokerRepo   *testapi.FakeServiceBrokerRepo
    24  		deps                command_registry.Dependency
    25  	)
    26  
    27  	updateCommandDependency := func(pluginCall bool) {
    28  		deps.Ui = ui
    29  		deps.RepoLocator = deps.RepoLocator.SetServiceBrokerRepository(serviceBrokerRepo)
    30  		deps.Config = configRepo
    31  		command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("update-service-broker").SetDependency(deps, pluginCall))
    32  	}
    33  
    34  	BeforeEach(func() {
    35  		configRepo = testconfig.NewRepositoryWithDefaults()
    36  		ui = &testterm.FakeUI{}
    37  		requirementsFactory = &testreq.FakeReqFactory{}
    38  		serviceBrokerRepo = &testapi.FakeServiceBrokerRepo{}
    39  	})
    40  
    41  	runCommand := func(args ...string) bool {
    42  		return testcmd.RunCliCommand("update-service-broker", args, requirementsFactory, updateCommandDependency, false)
    43  	}
    44  
    45  	Describe("requirements", func() {
    46  		It("fails with usage when invoked without exactly four args", func() {
    47  			requirementsFactory.LoginSuccess = true
    48  
    49  			runCommand("arg1", "arg2", "arg3")
    50  			Expect(ui.Outputs).To(ContainSubstrings(
    51  				[]string{"Incorrect Usage", "Requires", "arguments"},
    52  			))
    53  		})
    54  
    55  		It("fails when not logged in", func() {
    56  			Expect(runCommand("heeeeeeey", "yooouuuuuuu", "guuuuuuuuys", "ヾ(@*ー⌒ー*@)ノ")).To(BeFalse())
    57  		})
    58  	})
    59  
    60  	Context("when logged in", func() {
    61  		BeforeEach(func() {
    62  			requirementsFactory.LoginSuccess = true
    63  			broker := models.ServiceBroker{}
    64  			broker.Name = "my-found-broker"
    65  			broker.Guid = "my-found-broker-guid"
    66  			serviceBrokerRepo.FindByNameServiceBroker = broker
    67  		})
    68  
    69  		It("updates the service broker with the provided properties", func() {
    70  			runCommand("my-broker", "new-username", "new-password", "new-url")
    71  
    72  			Expect(serviceBrokerRepo.FindByNameName).To(Equal("my-broker"))
    73  
    74  			Expect(ui.Outputs).To(ContainSubstrings(
    75  				[]string{"Updating service broker", "my-found-broker", "my-user"},
    76  				[]string{"OK"},
    77  			))
    78  
    79  			expectedServiceBroker := models.ServiceBroker{}
    80  			expectedServiceBroker.Name = "my-found-broker"
    81  			expectedServiceBroker.Username = "new-username"
    82  			expectedServiceBroker.Password = "new-password"
    83  			expectedServiceBroker.Url = "new-url"
    84  			expectedServiceBroker.Guid = "my-found-broker-guid"
    85  
    86  			Expect(serviceBrokerRepo.UpdatedServiceBroker).To(Equal(expectedServiceBroker))
    87  		})
    88  	})
    89  })