github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/servicebroker/create_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/configuration/core_config"
     6  	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
     7  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
     8  	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
     9  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    10  
    11  	"github.com/cloudfoundry/cli/cf/command_registry"
    12  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    13  	. "github.com/onsi/ginkgo"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("create-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("create-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("create-service-broker", args, requirementsFactory, updateCommandDependency, false)
    43  	}
    44  
    45  	Describe("requirements", func() {
    46  		It("fails with usage when called without exactly four args", func() {
    47  			requirementsFactory.LoginSuccess = true
    48  			runCommand("whoops", "not-enough", "args")
    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("Just", "Enough", "Args", "Provided")).To(BeFalse())
    56  		})
    57  	})
    58  
    59  	Context("when logged in", func() {
    60  		BeforeEach(func() {
    61  			requirementsFactory.LoginSuccess = true
    62  		})
    63  
    64  		It("creates a service broker, obviously", func() {
    65  			runCommand("my-broker", "my-username", "my-password", "http://example.com")
    66  
    67  			Expect(ui.Outputs).To(ContainSubstrings(
    68  				[]string{"Creating service broker", "my-broker", "my-user"},
    69  				[]string{"OK"},
    70  			))
    71  
    72  			Expect(serviceBrokerRepo.CreateName).To(Equal("my-broker"))
    73  			Expect(serviceBrokerRepo.CreateUrl).To(Equal("http://example.com"))
    74  			Expect(serviceBrokerRepo.CreateUsername).To(Equal("my-username"))
    75  			Expect(serviceBrokerRepo.CreatePassword).To(Equal("my-password"))
    76  		})
    77  	})
    78  })