github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/servicebroker/rename_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  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    11  	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
    12  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    13  	. "github.com/onsi/ginkgo"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("rename-service-broker command", func() {
    18  	var (
    19  		ui                  *testterm.FakeUI
    20  		requirementsFactory *testreq.FakeReqFactory
    21  		configRepo          core_config.Repository
    22  		serviceBrokerRepo   *testapi.FakeServiceBrokerRepo
    23  		deps                command_registry.Dependency
    24  	)
    25  
    26  	updateCommandDependency := func(pluginCall bool) {
    27  		deps.Ui = ui
    28  		deps.RepoLocator = deps.RepoLocator.SetServiceBrokerRepository(serviceBrokerRepo)
    29  		deps.Config = configRepo
    30  		command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("rename-service-broker").SetDependency(deps, pluginCall))
    31  	}
    32  
    33  	BeforeEach(func() {
    34  		configRepo = testconfig.NewRepositoryWithDefaults()
    35  
    36  		ui = &testterm.FakeUI{}
    37  		requirementsFactory = &testreq.FakeReqFactory{}
    38  		serviceBrokerRepo = &testapi.FakeServiceBrokerRepo{}
    39  	})
    40  
    41  	runCommand := func(args ...string) bool {
    42  		return testcmd.RunCliCommand("rename-service-broker", args, requirementsFactory, updateCommandDependency, false)
    43  	}
    44  
    45  	Describe("requirements", func() {
    46  		It("fails with usage when not invoked with exactly two args", func() {
    47  			requirementsFactory.LoginSuccess = true
    48  			runCommand("welp")
    49  			Expect(ui.Outputs).To(ContainSubstrings(
    50  				[]string{"Incorrect Usage", "Requires", "arguments"},
    51  			))
    52  		})
    53  
    54  		It("fails when not logged in", func() {
    55  			Expect(runCommand("okay", "DO---IIIIT")).To(BeFalse())
    56  		})
    57  	})
    58  
    59  	Context("when logged in", func() {
    60  		BeforeEach(func() {
    61  			requirementsFactory.LoginSuccess = true
    62  			broker := models.ServiceBroker{}
    63  			broker.Name = "my-found-broker"
    64  			broker.Guid = "my-found-broker-guid"
    65  			serviceBrokerRepo.FindByNameServiceBroker = broker
    66  		})
    67  
    68  		It("renames the given service broker", func() {
    69  			runCommand("my-broker", "my-new-broker")
    70  			Expect(serviceBrokerRepo.FindByNameName).To(Equal("my-broker"))
    71  
    72  			Expect(ui.Outputs).To(ContainSubstrings(
    73  				[]string{"Renaming service broker", "my-found-broker", "my-new-broker", "my-user"},
    74  				[]string{"OK"},
    75  			))
    76  
    77  			Expect(serviceBrokerRepo.RenamedServiceBrokerGuid).To(Equal("my-found-broker-guid"))
    78  			Expect(serviceBrokerRepo.RenamedServiceBrokerName).To(Equal("my-new-broker"))
    79  		})
    80  	})
    81  })