github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/route/unmap_route_test.go (about) 1 package route_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("unmap-route command", func() { 19 var ( 20 ui *testterm.FakeUI 21 configRepo core_config.Repository 22 routeRepo *testapi.FakeRouteRepository 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.SetRouteRepository(routeRepo) 30 deps.Config = configRepo 31 command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("unmap-route").SetDependency(deps, pluginCall)) 32 } 33 34 BeforeEach(func() { 35 ui = new(testterm.FakeUI) 36 configRepo = testconfig.NewRepositoryWithDefaults() 37 routeRepo = new(testapi.FakeRouteRepository) 38 requirementsFactory = new(testreq.FakeReqFactory) 39 }) 40 41 runCommand := func(args ...string) bool { 42 return testcmd.RunCliCommand("unmap-route", args, requirementsFactory, updateCommandDependency, false) 43 } 44 45 Context("when the user is not logged in", func() { 46 It("fails requirements", func() { 47 Expect(runCommand("my-app", "some-domain.com")).To(BeFalse()) 48 }) 49 }) 50 51 Context("when the user is logged in", func() { 52 BeforeEach(func() { 53 requirementsFactory.LoginSuccess = true 54 }) 55 56 Context("when the user does not provide two args", func() { 57 It("fails with usage", func() { 58 runCommand() 59 Expect(ui.Outputs).To(ContainSubstrings( 60 []string{"Incorrect Usage", "Requires", "arguments"}, 61 )) 62 }) 63 }) 64 65 Context("when the user provides an app and a domain", func() { 66 BeforeEach(func() { 67 requirementsFactory.Application = models.Application{ 68 ApplicationFields: models.ApplicationFields{ 69 Guid: "my-app-guid", 70 Name: "my-app", 71 }, 72 Routes: []models.RouteSummary{ 73 models.RouteSummary{ 74 Guid: "my-route-guid", 75 }, 76 }, 77 } 78 79 requirementsFactory.Domain = models.DomainFields{ 80 Guid: "my-domain-guid", 81 Name: "example.com", 82 } 83 routeRepo.FindByHostAndDomainReturns.Route = models.Route{ 84 Domain: requirementsFactory.Domain, 85 Guid: "my-route-guid", 86 Host: "foo", 87 Apps: []models.ApplicationFields{ 88 models.ApplicationFields{ 89 Guid: "my-app-guid", 90 Name: "my-app", 91 }, 92 }, 93 } 94 }) 95 96 It("passes requirements", func() { 97 Expect(runCommand("-n", "my-host", "my-app", "my-domain.com")).To(BeTrue()) 98 }) 99 100 It("reads the app and domain from its requirements", func() { 101 runCommand("-n", "my-host", "my-app", "my-domain.com") 102 Expect(requirementsFactory.ApplicationName).To(Equal("my-app")) 103 Expect(requirementsFactory.DomainName).To(Equal("my-domain.com")) 104 }) 105 106 It("unmaps the route", func() { 107 runCommand("-n", "my-host", "my-app", "my-domain.com") 108 Expect(ui.Outputs).To(ContainSubstrings( 109 []string{"Removing route", "foo.example.com", "my-app", "my-org", "my-space", "my-user"}, 110 []string{"OK"}, 111 )) 112 113 Expect(ui.WarnOutputs).ToNot(ContainSubstrings( 114 []string{"Route to be unmapped is not currently mapped to the application."}, 115 )) 116 117 Expect(routeRepo.UnboundRouteGuid).To(Equal("my-route-guid")) 118 Expect(routeRepo.UnboundAppGuid).To(Equal("my-app-guid")) 119 }) 120 121 Context("when the route does not exist for the app", func() { 122 BeforeEach(func() { 123 requirementsFactory.Application = models.Application{ 124 ApplicationFields: models.ApplicationFields{ 125 Guid: "not-my-app-guid", 126 Name: "my-app", 127 }, 128 Routes: []models.RouteSummary{ 129 models.RouteSummary{ 130 Guid: "my-route-guid", 131 }, 132 }, 133 } 134 }) 135 136 It("informs the user the route did not exist on the applicaiton", func() { 137 runCommand("-n", "my-host", "my-app", "my-domain.com") 138 Expect(ui.Outputs).To(ContainSubstrings( 139 []string{"Removing route", "foo.example.com", "my-app", "my-org", "my-space", "my-user"}, 140 []string{"OK"}, 141 )) 142 143 Expect(ui.WarnOutputs).To(ContainSubstrings( 144 []string{"Route to be unmapped is not currently mapped to the application."}, 145 )) 146 }) 147 }) 148 }) 149 }) 150 })