github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/servicebroker/service_brokers_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 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 "strings" 16 17 . "github.com/cloudfoundry/cli/testhelpers/matchers" 18 ) 19 20 var _ = Describe("service-brokers command", func() { 21 var ( 22 ui *testterm.FakeUI 23 config core_config.Repository 24 repo *testapi.FakeServiceBrokerRepo 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.SetServiceBrokerRepository(repo) 32 deps.Config = config 33 command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("service-brokers").SetDependency(deps, pluginCall)) 34 } 35 36 BeforeEach(func() { 37 ui = &testterm.FakeUI{} 38 config = testconfig.NewRepositoryWithDefaults() 39 repo = &testapi.FakeServiceBrokerRepo{} 40 requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true} 41 }) 42 43 Describe("login requirements", func() { 44 It("fails if the user is not logged in", func() { 45 requirementsFactory.LoginSuccess = false 46 Expect(testcmd.RunCliCommand("service-brokers", []string{}, requirementsFactory, updateCommandDependency, false)).To(BeFalse()) 47 }) 48 It("should fail with usage when provided any arguments", func() { 49 requirementsFactory.LoginSuccess = true 50 Expect(testcmd.RunCliCommand("service-brokers", []string{"blahblah"}, requirementsFactory, updateCommandDependency, false)).To(BeFalse()) 51 Expect(ui.Outputs).To(ContainSubstrings( 52 []string{"Incorrect Usage", "No argument"}, 53 )) 54 }) 55 }) 56 57 It("lists service brokers", func() { 58 repo.ServiceBrokers = []models.ServiceBroker{models.ServiceBroker{ 59 Name: "service-broker-to-list-a", 60 Guid: "service-broker-to-list-guid-a", 61 Url: "http://service-a-url.com", 62 }, models.ServiceBroker{ 63 Name: "service-broker-to-list-b", 64 Guid: "service-broker-to-list-guid-b", 65 Url: "http://service-b-url.com", 66 }, models.ServiceBroker{ 67 Name: "service-broker-to-list-c", 68 Guid: "service-broker-to-list-guid-c", 69 Url: "http://service-c-url.com", 70 }} 71 72 testcmd.RunCliCommand("service-brokers", []string{}, requirementsFactory, updateCommandDependency, false) 73 74 Expect(ui.Outputs).To(ContainSubstrings( 75 []string{"Getting service brokers as", "my-user"}, 76 []string{"name", "url"}, 77 []string{"service-broker-to-list-a", "http://service-a-url.com"}, 78 []string{"service-broker-to-list-b", "http://service-b-url.com"}, 79 []string{"service-broker-to-list-c", "http://service-c-url.com"}, 80 )) 81 }) 82 83 It("lists service brokers by alphabetical order", func() { 84 repo.ServiceBrokers = []models.ServiceBroker{models.ServiceBroker{ 85 Name: "z-service-broker-to-list", 86 Guid: "z-service-broker-to-list-guid-a", 87 Url: "http://service-a-url.com", 88 }, models.ServiceBroker{ 89 Name: "a-service-broker-to-list", 90 Guid: "a-service-broker-to-list-guid-c", 91 Url: "http://service-c-url.com", 92 }, models.ServiceBroker{ 93 Name: "fun-service-broker-to-list", 94 Guid: "fun-service-broker-to-list-guid-b", 95 Url: "http://service-b-url.com", 96 }, models.ServiceBroker{ 97 Name: "123-service-broker-to-list", 98 Guid: "123-service-broker-to-list-guid-c", 99 Url: "http://service-d-url.com", 100 }} 101 102 testcmd.RunCliCommand("service-brokers", []string{}, requirementsFactory, updateCommandDependency, false) 103 104 Expect(ui.Outputs).To(BeInDisplayOrder( 105 []string{"Getting service brokers as", "my-user"}, 106 []string{"name", "url"}, 107 []string{"123-service-broker-to-list", "http://service-d-url.com"}, 108 []string{"a-service-broker-to-list", "http://service-c-url.com"}, 109 []string{"fun-service-broker-to-list", "http://service-b-url.com"}, 110 []string{"z-service-broker-to-list", "http://service-a-url.com"}, 111 )) 112 }) 113 114 It("says when no service brokers were found", func() { 115 testcmd.RunCliCommand("service-brokers", []string{}, requirementsFactory, updateCommandDependency, false) 116 117 Expect(ui.Outputs).To(ContainSubstrings( 118 []string{"Getting service brokers as", "my-user"}, 119 []string{"No service brokers found"}, 120 )) 121 }) 122 123 It("reports errors when listing service brokers", func() { 124 repo.ListErr = true 125 testcmd.RunCliCommand("service-brokers", []string{}, requirementsFactory, updateCommandDependency, false) 126 127 Expect(ui.Outputs).To(ContainSubstrings( 128 []string{"Getting service brokers as ", "my-user"}, 129 )) 130 Expect(strings.Join(ui.Outputs, "\n")).To(MatchRegexp(`FAILED\nError finding service brokers`)) 131 }) 132 })