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

     1  package service_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  
    13  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    14  	. "github.com/onsi/ginkgo"
    15  	. "github.com/onsi/gomega"
    16  )
    17  
    18  var _ = Describe("rename-service command", func() {
    19  	var (
    20  		ui                  *testterm.FakeUI
    21  		config              core_config.Repository
    22  		serviceRepo         *testapi.FakeServiceRepo
    23  		requirementsFactory *testreq.FakeReqFactory
    24  		deps                command_registry.Dependency
    25  	)
    26  
    27  	updateCommandDependency := func(pluginCall bool) {
    28  		deps.Ui = ui
    29  		deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
    30  		deps.Config = config
    31  		command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("rename-service").SetDependency(deps, pluginCall))
    32  	}
    33  
    34  	BeforeEach(func() {
    35  		ui = &testterm.FakeUI{}
    36  		config = testconfig.NewRepositoryWithDefaults()
    37  		serviceRepo = &testapi.FakeServiceRepo{}
    38  		requirementsFactory = &testreq.FakeReqFactory{}
    39  	})
    40  
    41  	runCommand := func(args ...string) bool {
    42  		return testcmd.RunCliCommand("rename-service", args, requirementsFactory, updateCommandDependency, false)
    43  	}
    44  
    45  	Describe("requirements", func() {
    46  		It("Fails with usage when exactly two parameters not passed", func() {
    47  			runCommand("whatever")
    48  			Expect(ui.Outputs).To(ContainSubstrings(
    49  				[]string{"Incorrect Usage", "Requires", "arguments"},
    50  			))
    51  		})
    52  
    53  		It("fails when not logged in", func() {
    54  			requirementsFactory.TargetedSpaceSuccess = true
    55  
    56  			Expect(runCommand("banana", "fppants")).To(BeFalse())
    57  		})
    58  
    59  		It("fails when a space is not targeted", func() {
    60  			requirementsFactory.LoginSuccess = true
    61  
    62  			Expect(runCommand("banana", "faaaaasdf")).To(BeFalse())
    63  		})
    64  	})
    65  
    66  	Context("when logged in and a space is targeted", func() {
    67  		var serviceInstance models.ServiceInstance
    68  
    69  		BeforeEach(func() {
    70  			serviceInstance = models.ServiceInstance{}
    71  			serviceInstance.Name = "different-name"
    72  			serviceInstance.Guid = "different-name-guid"
    73  
    74  			requirementsFactory.LoginSuccess = true
    75  			requirementsFactory.TargetedSpaceSuccess = true
    76  			requirementsFactory.ServiceInstance = serviceInstance
    77  		})
    78  
    79  		It("renames the service, obviously", func() {
    80  			runCommand("my-service", "new-name")
    81  
    82  			Expect(ui.Outputs).To(ContainSubstrings(
    83  				[]string{"Renaming service", "different-name", "new-name", "my-org", "my-space", "my-user"},
    84  				[]string{"OK"},
    85  			))
    86  
    87  			Expect(serviceRepo.RenameServiceServiceInstance).To(Equal(serviceInstance))
    88  			Expect(serviceRepo.RenameServiceNewName).To(Equal("new-name"))
    89  		})
    90  	})
    91  })