func newCurlDependencies() (deps curlDependencies) { deps.ui = &testterm.FakeUI{} deps.config = testconfig.NewRepository() deps.requirementsFactory = &testreq.FakeReqFactory{} deps.curlRepo = &testapi.FakeCurlRepository{} return }
func getPasswordDeps() passwordDeps { return passwordDeps{ ReqFactory: &testreq.FakeReqFactory{LoginSuccess: true}, PwdRepo: &testapi.FakePasswordRepo{UpdateUnauthorized: true}, Config: testconfig.NewRepository(), } }
func setupDependencies() (obj commandDependencies) { obj.ui = &testterm.FakeUI{} obj.config = testconfig.NewRepository() obj.requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true} obj.serviceRepo = new(testapi.FakeServiceRepo) return }
func createAuthenticationRepository(apiServer *httptest.Server, authServer *httptest.Server) (core_config.ReadWriter, authentication.AuthenticationRepository) { config := testconfig.NewRepository() config.SetAuthenticationEndpoint(authServer.URL) config.SetApiEndpoint(apiServer.URL) config.SetAccessToken("bearer initial-access-token") config.SetRefreshToken("initial-refresh-token") authGateway := NewUAAGateway(config, &testterm.FakeUI{}) authGateway.SetTrustedCerts(authServer.TLS.Certificates) authenticator := authentication.NewUAAAuthenticationRepository(authGateway, config) return config, authenticator }
func createCommandFactory() command_factory.Factory { fakeUI := &testterm.FakeUI{} configRepo := testconfig.NewRepository() pluginConfig := &testPluginConfig.FakePluginConfiguration{} manifestRepo := manifest.NewManifestDiskRepository() apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{ "auth": net.NewUAAGateway(configRepo, fakeUI), "cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI), "uaa": net.NewUAAGateway(configRepo, fakeUI), }) return command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig) }
func findCommand(cmdName string) (cmd cli.Command) { fakeUI := &testterm.FakeUI{} configRepo := testconfig.NewRepository() pluginConfig := &testPluginConfig.FakePluginConfiguration{} manifestRepo := manifest.NewManifestDiskRepository() apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{ "auth": net.NewUAAGateway(configRepo, fakeUI), "cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI), "uaa": net.NewUAAGateway(configRepo, fakeUI), }) cmdFactory := command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig) requirementsFactory := &testreq.FakeReqFactory{} cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, fakeUI) myApp := app.NewApp(cmdRunner, cmdFactory.CommandMetadatas()...) for _, cmd := range myApp.Commands { if cmd.Name == cmdName { return cmd } } panic(fmt.Sprintf("command %s does not exist", cmdName)) return }
. "github.com/onsi/gomega" . "github.com/nttlabs/cli/testhelpers/matchers" ) var _ = Describe("bind-service command", func() { var ( requirementsFactory *testreq.FakeReqFactory ) BeforeEach(func() { requirementsFactory = &testreq.FakeReqFactory{} }) It("fails requirements when not logged in", func() { cmd := NewBindService(&testterm.FakeUI{}, testconfig.NewRepository(), &testapi.FakeServiceBindingRepo{}) testcmd.RunCommand(cmd, []string{"service", "app"}, requirementsFactory) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) Context("when logged in", func() { BeforeEach(func() { requirementsFactory.LoginSuccess = true }) It("binds a service instance to an app", func() { app := models.Application{} app.Name = "my-app" app.Guid = "my-app-guid" serviceInstance := models.ServiceInstance{}
jsonResponse := `{ "code": 210003, "description": "The host is taken: test1" }` fmt.Fprintln(writer, jsonResponse) } var invalidTokenCloudControllerRequest = func(writer http.ResponseWriter, request *http.Request) { writer.WriteHeader(http.StatusBadRequest) jsonResponse := `{ "code": 1000, "description": "The token is invalid" }` fmt.Fprintln(writer, jsonResponse) } var _ = Describe("Cloud Controller Gateway", func() { var gateway Gateway var config core_config.Reader BeforeEach(func() { config = testconfig.NewRepository() gateway = NewCloudControllerGateway(config, time.Now, &testterm.FakeUI{}) }) It("parses error responses", func() { ts := httptest.NewTLSServer(http.HandlerFunc(failingCloudControllerRequest)) defer ts.Close() gateway.SetTrustedCerts(ts.TLS.Certificates) request, apiErr := gateway.NewRequest("GET", ts.URL, "TOKEN", nil) _, apiErr = gateway.PerformRequest(request) Expect(apiErr).NotTo(BeNil()) Expect(apiErr.Error()).To(ContainSubstring("The host is taken: test1")) Expect(apiErr.(errors.HttpError).ErrorCode()).To(ContainSubstring("210003")) })
var ui *testterm.FakeUI BeforeEach(func() { ui = new(testterm.FakeUI) }) It("succeeds when given a config with an API endpoint and authentication", func() { config := testconfig.NewRepositoryWithAccessToken(core_config.TokenInfo{Username: "******"}) config.SetApiEndpoint("api.example.com") req := NewLoginRequirement(ui, config) success := req.Execute() Expect(success).To(BeTrue()) }) It("fails when given a config with only an API endpoint", func() { config := testconfig.NewRepository() config.SetApiEndpoint("api.example.com") req := NewLoginRequirement(ui, config) success := req.Execute() Expect(success).To(BeFalse()) Expect(ui.Outputs).To(ContainSubstrings([]string{"Not logged in."})) }) It("fails when given a config with neither an API endpoint nor authentication", func() { config := testconfig.NewRepository() req := NewLoginRequirement(ui, config) success := req.Execute() Expect(success).To(BeFalse()) Expect(ui.Outputs).To(ContainSubstrings([]string{"No API endpoint"}))
app.Name = "my-app" app.Guid = "my-app-guid" serviceInstance.Name = "my-service" serviceInstance.Guid = "my-service-guid" requirementsFactory = &testreq.FakeReqFactory{} requirementsFactory.Application = app requirementsFactory.ServiceInstance = serviceInstance serviceBindingRepo = &testapi.FakeServiceBindingRepo{} }) Context("when not logged in", func() { It("fails requirements when not logged in", func() { cmd := NewUnbindService(&testterm.FakeUI{}, testconfig.NewRepository(), serviceBindingRepo) testcmd.RunCommand(cmd, []string{"my-service", "my-app"}, requirementsFactory) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) }) Context("when logged in", func() { BeforeEach(func() { requirementsFactory.LoginSuccess = true }) Context("when the service instance exists", func() { It("unbinds a service from an app", func() { ui := callUnbindService([]string{"my-app", "my-service"}, requirementsFactory, serviceBindingRepo) Expect(requirementsFactory.ApplicationName).To(Equal("my-app"))
func newCurlDependencies() (deps curlDependencies) { deps.config = testconfig.NewRepository() deps.config.SetAccessToken("BEARER my_access_token") deps.gateway = net.NewCloudControllerGateway(deps.config, time.Now, &testterm.FakeUI{}) return }
logsForTail = []*logmessage.LogMessage{ testlogs.NewLogMessage("Log Line 1", app.Guid, LogMessageTypeStaging, time.Now()), testlogs.NewLogMessage("Log Line 2", app.Guid, LogMessageTypeStaging, time.Now()), } args := []string{"my-app"} requirementsFactory.Application = app ui = callStart(args, configRepo, requirementsFactory, displayApp, appRepo, appInstancesRepo, logRepo) return } It("fails requirements when not logged in", func() { requirementsFactory.LoginSuccess = false cmd := NewStart(new(testterm.FakeUI), testconfig.NewRepository(), &testcmd.FakeAppDisplayer{}, &testApplication.FakeApplicationRepository{}, &testAppInstanaces.FakeAppInstancesRepository{}, &testapi.FakeLogsRepository{}) testcmd.RunCommand(cmd, []string{"some-app-name"}, requirementsFactory) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) Describe("timeouts", func() { It("has sane default timeout values", func() { cmd := NewStart(new(testterm.FakeUI), testconfig.NewRepository(), &testcmd.FakeAppDisplayer{}, &testApplication.FakeApplicationRepository{}, &testAppInstanaces.FakeAppInstancesRepository{}, &testapi.FakeLogsRepository{}) Expect(cmd.StagingTimeout).To(Equal(15 * time.Minute)) Expect(cmd.StartupTimeout).To(Equal(5 * time.Minute)) }) It("can read timeout values from environment variables", func() { oldStaging := os.Getenv("CF_STAGING_TIMEOUT") oldStart := os.Getenv("CF_STARTUP_TIMEOUT") defer func() {