github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/serviceauthtoken/service_auth_tokens_test.go (about) 1 package serviceauthtoken_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("service-auth-tokens command", func() { 19 var ( 20 ui *testterm.FakeUI 21 configRepo core_config.Repository 22 authTokenRepo *testapi.FakeAuthTokenRepo 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.SetServiceAuthTokenRepository(authTokenRepo) 30 deps.Config = configRepo 31 command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("service-auth-tokens").SetDependency(deps, pluginCall)) 32 } 33 34 BeforeEach(func() { 35 ui = &testterm.FakeUI{Inputs: []string{"y"}} 36 authTokenRepo = &testapi.FakeAuthTokenRepo{} 37 configRepo = testconfig.NewRepositoryWithDefaults() 38 requirementsFactory = &testreq.FakeReqFactory{} 39 }) 40 41 runCommand := func(args ...string) bool { 42 return testcmd.RunCliCommand("service-auth-tokens", args, requirementsFactory, updateCommandDependency, false) 43 } 44 45 Describe("requirements", func() { 46 It("fails when not logged in", func() { 47 Expect(runCommand()).To(BeFalse()) 48 }) 49 It("should fail with usage when provided any arguments", func() { 50 requirementsFactory.LoginSuccess = true 51 Expect(runCommand("blahblah")).To(BeFalse()) 52 Expect(ui.Outputs).To(ContainSubstrings( 53 []string{"Incorrect Usage", "No argument"}, 54 )) 55 }) 56 }) 57 58 Context("when logged in and some service auth tokens exist", func() { 59 BeforeEach(func() { 60 requirementsFactory.LoginSuccess = true 61 62 authTokenRepo.FindAllAuthTokens = []models.ServiceAuthTokenFields{ 63 models.ServiceAuthTokenFields{Label: "a label", Provider: "a provider"}, 64 models.ServiceAuthTokenFields{Label: "a second label", Provider: "a second provider"}, 65 } 66 }) 67 68 It("shows you the service auth tokens", func() { 69 runCommand() 70 71 Expect(ui.Outputs).To(ContainSubstrings( 72 []string{"Getting service auth tokens as", "my-user"}, 73 []string{"OK"}, 74 []string{"label", "provider"}, 75 []string{"a label", "a provider"}, 76 []string{"a second label", "a second provider"}, 77 )) 78 }) 79 }) 80 })