github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/space/delete_space_test.go (about) 1 package space_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/maker" 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 . "github.com/cloudfoundry/cli/testhelpers/matchers" 17 ) 18 19 var _ = Describe("delete-space command", func() { 20 var ( 21 ui *testterm.FakeUI 22 space models.Space 23 config core_config.Repository 24 spaceRepo *testapi.FakeSpaceRepository 25 requirementsFactory *testreq.FakeReqFactory 26 deps command_registry.Dependency 27 ) 28 29 updateCommandDependency := func(pluginCall bool) { 30 deps.Ui = ui 31 deps.RepoLocator = deps.RepoLocator.SetSpaceRepository(spaceRepo) 32 deps.Config = config 33 command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("delete-space").SetDependency(deps, pluginCall)) 34 } 35 36 runCommand := func(args ...string) bool { 37 return testcmd.RunCliCommand("delete-space", args, requirementsFactory, updateCommandDependency, false) 38 } 39 40 BeforeEach(func() { 41 ui = &testterm.FakeUI{} 42 spaceRepo = &testapi.FakeSpaceRepository{} 43 config = testconfig.NewRepositoryWithDefaults() 44 45 space = maker.NewSpace(maker.Overrides{ 46 "name": "space-to-delete", 47 "guid": "space-to-delete-guid", 48 }) 49 50 requirementsFactory = &testreq.FakeReqFactory{ 51 LoginSuccess: true, 52 TargetedOrgSuccess: true, 53 Space: space, 54 } 55 }) 56 57 Describe("requirements", func() { 58 BeforeEach(func() { 59 ui.Inputs = []string{"y"} 60 }) 61 It("fails when not logged in", func() { 62 requirementsFactory.LoginSuccess = false 63 64 Expect(runCommand("my-space")).To(BeFalse()) 65 }) 66 67 It("fails when not targeting a space", func() { 68 requirementsFactory.TargetedOrgSuccess = false 69 70 Expect(runCommand("my-space")).To(BeFalse()) 71 }) 72 }) 73 74 It("deletes a space, given its name", func() { 75 ui.Inputs = []string{"yes"} 76 runCommand("space-to-delete") 77 78 Expect(ui.Prompts).To(ContainSubstrings([]string{"Really delete the space space-to-delete"})) 79 Expect(ui.Outputs).To(ContainSubstrings( 80 []string{"Deleting space", "space-to-delete", "my-org", "my-user"}, 81 []string{"OK"}, 82 )) 83 Expect(spaceRepo.DeletedSpaceGuid).To(Equal("space-to-delete-guid")) 84 Expect(config.HasSpace()).To(Equal(true)) 85 }) 86 87 It("does not prompt when the -f flag is given", func() { 88 runCommand("-f", "space-to-delete") 89 90 Expect(ui.Prompts).To(BeEmpty()) 91 Expect(ui.Outputs).To(ContainSubstrings( 92 []string{"Deleting", "space-to-delete"}, 93 []string{"OK"}, 94 )) 95 Expect(spaceRepo.DeletedSpaceGuid).To(Equal("space-to-delete-guid")) 96 }) 97 98 It("clears the space from the config, when deleting the space currently targeted", func() { 99 config.SetSpaceFields(space.SpaceFields) 100 runCommand("-f", "space-to-delete") 101 102 Expect(config.HasSpace()).To(Equal(false)) 103 }) 104 105 It("clears the space from the config, when deleting the space currently targeted even if space name is case insensitive", func() { 106 config.SetSpaceFields(space.SpaceFields) 107 runCommand("-f", "Space-To-Delete") 108 109 Expect(config.HasSpace()).To(Equal(false)) 110 }) 111 })