Esempio n. 1
0
func setUpLoginTestContext() (c *LoginTestContext) {
	c = new(LoginTestContext)
	c.Config = testconfig.NewRepository()

	c.ui = &testterm.FakeUI{}

	c.authRepo = &testapi.FakeAuthenticationRepository{
		AccessToken:  "my_access_token",
		RefreshToken: "my_refresh_token",
		Config:       c.Config,
	}
	c.endpointRepo = &testapi.FakeEndpointRepo{Config: c.Config}

	org := models.Organization{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"

	c.orgRepo = &testapi.FakeOrgRepository{
		Organizations: []models.Organization{org},
	}

	space := models.Space{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"

	c.spaceRepo = &testapi.FakeSpaceRepository{
		Spaces: []models.Space{space},
	}

	return
}
Esempio n. 2
0
func newCurlDependencies() (deps curlDependencies) {
	deps.ui = &testterm.FakeUI{}
	deps.config = testconfig.NewRepository()
	deps.reqFactory = &testreq.FakeReqFactory{}
	deps.curlRepo = &testapi.FakeCurlRepository{}
	return
}
Esempio n. 3
0
func getPasswordDeps() passwordDeps {
	return passwordDeps{
		ReqFactory: &testreq.FakeReqFactory{ValidAccessTokenSuccess: true},
		PwdRepo:    &testapi.FakePasswordRepo{UpdateUnauthorized: true},
		Config:     testconfig.NewRepository(),
	}
}
Esempio n. 4
0
func setupAuthDependencies(request testnet.TestRequest) (*httptest.Server, *testnet.TestHandler, configuration.ReadWriter) {
	ts, handler := testnet.NewServer([]testnet.TestRequest{request})
	config := testconfig.NewRepository()
	config.SetAuthenticationEndpoint(ts.URL)

	return ts, handler, config
}
Esempio n. 5
0
func setupDependencies() (obj commandDependencies) {
	obj.ui = &testterm.FakeUI{}

	obj.config = testconfig.NewRepository()
	obj.reqFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true}
	obj.serviceRepo = new(testapi.FakeServiceRepo)
	return
}
Esempio n. 6
0
func setupAuthDependencies(request testnet.TestRequest) (deps authDependencies) {
	deps.ts, deps.handler = testnet.NewTLSServer([]testnet.TestRequest{request})

	deps.config = testconfig.NewRepository()
	deps.config.SetAuthorizationEndpoint(deps.ts.URL)

	deps.gateway = net.NewUAAGateway()
	return
}
Esempio n. 7
0
func setupEventTest(requests []testnet.TestRequest) (deps eventTestDependencies) {
	deps.server, deps.handler = testnet.NewServer(requests)

	configRepo := testconfig.NewRepository()
	configRepo.SetApiEndpoint(deps.server.URL)
	configRepo.SetAccessToken("BEARER my_access_token")

	deps.config = configRepo
	deps.gateway = net.NewCloudControllerGateway()

	return
}
Esempio n. 8
0
func createAuthenticationRepository(apiServer *httptest.Server, authServer *httptest.Server) (configuration.ReadWriter, api.AuthenticationRepository) {
	config := testconfig.NewRepository()
	config.SetAuthorizationEndpoint(authServer.URL)
	config.SetApiEndpoint(apiServer.URL)
	config.SetAccessToken("bearer initial-access-token")
	config.SetRefreshToken("initial-refresh-token")

	authGateway := NewUAAGateway()
	authenticator := api.NewUAAAuthenticationRepository(authGateway, config)

	return config, authenticator
}
Esempio n. 9
0
func createCommandFactory() command_factory.Factory {
	fakeUI := &testterm.FakeUI{}
	configRepo := testconfig.NewRepository()
	manifestRepo := manifest.NewManifestDiskRepository()
	apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(configRepo),
		"cloud-controller": net.NewCloudControllerGateway(configRepo),
		"uaa":              net.NewUAAGateway(configRepo),
	})

	return command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator)
}
Esempio n. 10
0
func findCommand(cmdName string) (cmd cli.Command) {
	fakeUI := &testterm.FakeUI{}
	configRepo := testconfig.NewRepository()
	manifestRepo := manifest.NewManifestDiskRepository()
	apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(configRepo),
		"cloud-controller": net.NewCloudControllerGateway(configRepo),
		"uaa":              net.NewUAAGateway(configRepo),
	})

	cmdFactory := command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator)
	requirementsFactory := &testreq.FakeReqFactory{}
	cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory)
	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
}
Esempio n. 11
0
	"path/filepath"
	"syscall"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testcmd "testhelpers/commands"
	testconfig "testhelpers/configuration"
	"testhelpers/maker"
	testmanifest "testhelpers/manifest"
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
)

var _ = Describe("Push Command", func() {
	It("TestPushingRequirements", func() {
		ui := new(testterm.FakeUI)
		configRepo := testconfig.NewRepository()
		deps := getPushDependencies()
		manifestRepo := deps.manifestRepo
		starter := deps.starter
		stopper := deps.stopper
		binder := deps.binder
		appRepo := deps.appRepo
		domainRepo := deps.domainRepo
		routeRepo := deps.routeRepo
		stackRepo := deps.stackRepo
		appBitsRepo := deps.appBitsRepo
		serviceRepo := deps.serviceRepo

		cmd := NewPush(ui, configRepo, manifestRepo, starter, stopper, binder, appRepo, domainRepo, routeRepo, stackRepo, serviceRepo, appBitsRepo)
		ctxt := testcmd.NewContext("push", []string{})
Esempio n. 12
0
		instance3 := models.AppInstanceFields{}
		instance3.State = models.InstanceRunning

		instance4 := models.AppInstanceFields{}
		instance4.State = models.InstanceStarting

		defaultInstanceReponses = [][]models.AppInstanceFields{
			[]models.AppInstanceFields{instance1, instance2},
			[]models.AppInstanceFields{instance1, instance2},
			[]models.AppInstanceFields{instance3, instance4},
		}
	})

	It("TestStartCommandDefaultTimeouts", func() {
		cmd := NewStart(new(testterm.FakeUI), testconfig.NewRepository(), &testcmd.FakeAppDisplayer{}, &testapi.FakeApplicationRepository{}, &testapi.FakeAppInstancesRepo{}, &testapi.FakeLogsRepository{})
		Expect(cmd.StagingTimeout).To(Equal(15 * time.Minute))
		Expect(cmd.StartupTimeout).To(Equal(5 * time.Minute))
	})

	It("TestStartCommandSetsTimeoutsFromEnv", func() {
		oldStaging := os.Getenv("CF_STAGING_TIMEOUT")
		oldStart := os.Getenv("CF_STARTUP_TIMEOUT")
		defer func() {
			os.Setenv("CF_STAGING_TIMEOUT", oldStaging)
			os.Setenv("CF_STARTUP_TIMEOUT", oldStart)
		}()

		os.Setenv("CF_STAGING_TIMEOUT", "6")
		os.Setenv("CF_STARTUP_TIMEOUT", "3")
		cmd := NewStart(new(testterm.FakeUI), testconfig.NewRepository(), &testcmd.FakeAppDisplayer{}, &testapi.FakeApplicationRepository{}, &testapi.FakeAppInstancesRepo{}, &testapi.FakeLogsRepository{})
Esempio n. 13
0
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
)

var _ = Describe("bind-service command", func() {
	var (
		requirementsFactory *testreq.FakeReqFactory
	)

	BeforeEach(func() {
		requirementsFactory = &testreq.FakeReqFactory{}
	})

	It("fails requirements when not logged in", func() {
		context := testcmd.NewContext("bind-service", []string{"service", "app"})
		cmd := NewBindService(&testterm.FakeUI{}, testconfig.NewRepository(), &testapi.FakeServiceBindingRepo{})
		testcmd.RunCommand(cmd, context, 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{}
Esempio n. 14
0
func createServiceRepo(reqs []testnet.TestRequest) (testServer *httptest.Server, handler *testnet.TestHandler, repo ServiceRepository) {
	config := testconfig.NewRepository()
	config.SetAccessToken("BEARER my_access_token")
	config.SetSpaceFields(models.SpaceFields{Guid: "my-space-guid"})
	return createServiceRepoWithConfig(reqs, config)
}
Esempio n. 15
0
func newCurlDependencies() (deps curlDependencies) {
	deps.config = testconfig.NewRepository()
	deps.config.SetAccessToken("BEARER my_access_token")
	deps.gateway = net.NewCloudControllerGateway(deps.config)
	return
}
Esempio n. 16
0
		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, testcmd.NewContext("unbind-service", []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"))
Esempio n. 17
0
	testterm "testhelpers/terminal"
)

var _ = Describe("stop command", func() {
	var (
		requirementsFactory *testreq.FakeReqFactory
	)

	BeforeEach(func() {
		requirementsFactory = &testreq.FakeReqFactory{}
	})

	It("fails requirements when not logged in", func() {
		requirementsFactory.LoginSuccess = false
		appRepo := &testapi.FakeApplicationRepository{}
		cmd := NewStop(new(testterm.FakeUI), testconfig.NewRepository(), appRepo)
		testcmd.RunCommand(cmd, testcmd.NewContext("stop", []string{"some-app-name"}), requirementsFactory)

		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	Context("when logged in", func() {
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true
		})

		It("fails with usage when the app name is not given", func() {
			app := models.Application{}
			app.Name = "my-app"
			app.Guid = "my-app-guid"
			appRepo := &testapi.FakeApplicationRepository{}
Esempio n. 18
0
	cmd := NewApi(ui, config, endpointRepo)
	ctxt := testcmd.NewContext("api", args)
	requirementsFactory := &testreq.FakeReqFactory{}
	testcmd.RunCommand(cmd, ctxt, requirementsFactory)
	return
}

var _ = Describe("api command", func() {
	var (
		config       configuration.ReadWriter
		endpointRepo *testapi.FakeEndpointRepo
	)

	BeforeEach(func() {
		config = testconfig.NewRepository()
		endpointRepo = &testapi.FakeEndpointRepo{}
	})

	Context("when the api endpoint's ssl certificate is invalid", func() {
		It("warns the user and prints out a tip", func() {
			endpointRepo.UpdateEndpointError = errors.NewInvalidSSLCert("https://buttontomatoes.org", "why? no. go away")
			ui := callApi([]string{"https://buttontomatoes.org"}, config, endpointRepo)

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"FAILED"},
				{"SSL cert", "https://buttontomatoes.org"},
				{"TIP", "--skip-ssl-validation"},
			})
		})
	})
Esempio n. 19
0
		})
		Expect(appRepo.UpdateAppGuid).To(Equal(""))
	})
	It("TestApplicationStopReturnsUpdatedApp", func() {

		appToStop := models.Application{}
		appToStop.Name = "my-app"
		appToStop.Guid = "my-app-guid"
		appToStop.State = "started"
		expectedStoppedApp := models.Application{}
		expectedStoppedApp.Name = "my-stopped-app"
		expectedStoppedApp.Guid = "my-stopped-app-guid"
		expectedStoppedApp.State = "stopped"

		appRepo := &testapi.FakeApplicationRepository{UpdateAppResult: expectedStoppedApp}
		config := testconfig.NewRepository()
		stopper := NewStop(new(testterm.FakeUI), config, appRepo)
		actualStoppedApp, err := stopper.ApplicationStop(appToStop)

		Expect(err).NotTo(HaveOccurred())
		Expect(expectedStoppedApp).To(Equal(actualStoppedApp))
	})
	It("TestApplicationStopReturnsUpdatedAppWhenAppIsAlreadyStopped", func() {

		appToStop := models.Application{}
		appToStop.Name = "my-app"
		appToStop.Guid = "my-app-guid"
		appToStop.State = "stopped"
		appRepo := &testapi.FakeApplicationRepository{}
		config := testconfig.NewRepository()
		stopper := NewStop(new(testterm.FakeUI), config, appRepo)
Esempio n. 20
0
var _ = Describe("delete-service command", func() {
	var (
		requirementsFactory *testreq.FakeReqFactory
		serviceRepo         *testapi.FakeServiceRepo
		serviceInstance     models.ServiceInstance
	)

	BeforeEach(func() {
		requirementsFactory = &testreq.FakeReqFactory{}
		serviceRepo = &testapi.FakeServiceRepo{}
	})

	Context("when not logged in", func() {
		It("does not pass requirements", func() {
			cmd := NewDeleteService(&testterm.FakeUI{}, testconfig.NewRepository(), serviceRepo)
			testcmd.RunCommand(cmd, testcmd.NewContext("delete-service", []string{"vestigal-service"}), requirementsFactory)
			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	Context("when logged in", func() {
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true
		})

		It("fails with usage when no arguments are given", func() {
			ui := callDeleteService("", []string{"-f"}, requirementsFactory, serviceRepo)
			Expect(ui.FailedWithUsage).To(BeTrue())
		})
func init() {
	Describe("migrating service instances from v1 to v2", func() {
		var (
			ui                  *testterm.FakeUI
			serviceRepo         *testapi.FakeServiceRepo
			cmd                 *MigrateServiceInstances
			requirementsFactory *testreq.FakeReqFactory
			context             *cli.Context
			args                []string
		)

		BeforeEach(func() {
			ui = &testterm.FakeUI{}
			config := testconfig.NewRepository()
			serviceRepo = &testapi.FakeServiceRepo{}
			cmd = NewMigrateServiceInstances(ui, config, serviceRepo)
			requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
			args = []string{}
		})

		Describe("requirements", func() {
			It("requires you to be logged in", func() {
				context = testcmd.NewContext("migrate-service-instances", args)
				testcmd.RunCommand(cmd, context, requirementsFactory)

				Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
			})

			It("requires five arguments to run", func() {
				requirementsFactory.LoginSuccess = true
				args = []string{"one", "two", "three"}
				context = testcmd.NewContext("migrate-service-instances", args)
				testcmd.RunCommand(cmd, context, requirementsFactory)

				Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
			})

			It("passes requirements if user is logged in and provided five args to run", func() {
				requirementsFactory.LoginSuccess = true
				args = []string{"one", "two", "three", "four", "five"}
				ui.Inputs = append(ui.Inputs, "no")

				context = testcmd.NewContext("migrate-service-instances", args)
				testcmd.RunCommand(cmd, context, requirementsFactory)

				Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
			})
		})

		Describe("migrating service instances", func() {
			BeforeEach(func() {
				requirementsFactory.LoginSuccess = true
				args = []string{"v1-service-name", "v1-provider-name", "v1-plan-name", "v2-service-name", "v2-plan-name"}
				context = testcmd.NewContext("migrate-service-instances", args)
				serviceRepo.ServiceInstanceCountForServicePlan = 1
			})

			It("displays the warning and the prompt including info about the instances and plan to migrate", func() {
				ui.Inputs = []string{""}
				testcmd.RunCommand(cmd, context, requirementsFactory)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"WARNING:", "this operation is to replace a service broker"},
				})
				testassert.SliceContains(ui.Prompts, testassert.Lines{
					{"Really migrate", "1 service instance",
						"from plan", "v1-service-name", "v1-provider-name", "v1-plan-name",
						"to", "v2-service-name", "v2-plan-name"},
				})
			})

			Context("when the user confirms", func() {
				BeforeEach(func() {
					ui.Inputs = []string{"yes"}
				})

				Context("when the v1 and v2 service instances exists", func() {
					BeforeEach(func() {
						serviceRepo.FindServicePlanByDescriptionResultGuids = []string{"v1-guid", "v2-guid"}
						serviceRepo.MigrateServicePlanFromV1ToV2ReturnedCount = 1
					})

					It("makes a request to migrate the v1 service instance", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						Expect(serviceRepo.V1GuidToMigrate).To(Equal("v1-guid"))
						Expect(serviceRepo.V2GuidToMigrate).To(Equal("v2-guid"))
					})

					It("finds the v1 service plan by its name, provider and service label", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						expectedV1 := api.ServicePlanDescription{
							ServicePlanName: "v1-plan-name",
							ServiceProvider: "v1-provider-name",
							ServiceName:     "v1-service-name",
						}
						Expect(serviceRepo.FindServicePlanByDescriptionArguments[0]).To(Equal(expectedV1))
					})

					It("finds the v2 service plan by its name and service label", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						expectedV2 := api.ServicePlanDescription{
							ServicePlanName: "v2-plan-name",
							ServiceName:     "v2-service-name",
						}
						Expect(serviceRepo.FindServicePlanByDescriptionArguments[1]).To(Equal(expectedV2))
					})

					It("notifies the user that the migration was successful", func() {
						serviceRepo.ServiceInstanceCountForServicePlan = 2
						testcmd.RunCommand(cmd, context, requirementsFactory)

						testassert.SliceContains(ui.Outputs, testassert.Lines{
							{"Attempting to migrate", "2", "service instances"},
							{"1", "service instance", "migrated"},
							{"OK"},
						})
					})
				})

				Context("when finding the v1 plan fails", func() {
					Context("because the plan does not exist", func() {
						BeforeEach(func() {
							serviceRepo.FindServicePlanByDescriptionResponses = []net.ApiResponse{net.NewNotFoundApiResponse("not used")}
						})

						It("notifies the user of the failure", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceContains(ui.Outputs, testassert.Lines{
								{"FAILED"},
								{"Plan", "v1-service-name", "v1-provider-name", "v1-plan-name", "cannot be found"},
							})
						})

						It("does not display the warning", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
								{"WARNING:", "this operation is to replace a service broker"},
							})
						})
					})

					Context("because there was an http error", func() {
						BeforeEach(func() {
							serviceRepo.FindServicePlanByDescriptionResponses = []net.ApiResponse{net.NewApiResponseWithMessage("uh oh")}
						})

						It("notifies the user of the failure", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceContains(ui.Outputs, testassert.Lines{
								{"FAILED"},
								{"uh oh"},
							})
						})

						It("does not display the warning", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
								{"WARNING:", "this operation is to replace a service broker"},
							})
						})
					})
				})

				Context("when finding the v2 plan fails", func() {
					Context("because the plan does not exist", func() {
						BeforeEach(func() {
							serviceRepo.FindServicePlanByDescriptionResponses = []net.ApiResponse{net.NewSuccessfulApiResponse(), net.NewNotFoundApiResponse("not used")}
						})

						It("notifies the user of the failure", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceContains(ui.Outputs, testassert.Lines{
								{"FAILED"},
								{"Plan", "v2-service-name", "v2-plan-name", "cannot be found"},
							})
						})

						It("does not display the warning", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
								{"WARNING:", "this operation is to replace a service broker"},
							})
						})
					})

					Context("because there was an http error", func() {
						BeforeEach(func() {
							serviceRepo.FindServicePlanByDescriptionResponses = []net.ApiResponse{net.NewSuccessfulApiResponse(), net.NewApiResponseWithMessage("uh oh")}
						})

						It("notifies the user of the failure", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceContains(ui.Outputs, testassert.Lines{
								{"FAILED"},
								{"uh oh"},
							})
						})

						It("does not display the warning", func() {
							testcmd.RunCommand(cmd, context, requirementsFactory)

							testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
								{"WARNING:", "this operation is to replace a service broker"},
							})
						})
					})
				})

				Context("when migrating the plans fails", func() {
					BeforeEach(func() {
						serviceRepo.MigrateServicePlanFromV1ToV2Response = net.NewApiResponseWithMessage("ruh roh")
					})

					It("notifies the user of the failure", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						testassert.SliceContains(ui.Outputs, testassert.Lines{
							{"FAILED"},
							{"ruh roh"},
						})
					})
				})

				Context("when there are no instances to migrate", func() {
					BeforeEach(func() {
						serviceRepo.FindServicePlanByDescriptionResultGuids = []string{"v1-guid", "v2-guid"}
						serviceRepo.ServiceInstanceCountForServicePlan = 0
					})

					It("returns a meaningful error", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						testassert.SliceContains(ui.Outputs, testassert.Lines{
							{"FAILED"},
							{"no service instances to migrate"},
						})
					})

					It("does not show the user the warning", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
							{"WARNING:", "this operation is to replace a service broker"},
						})
					})
				})

				Context("when it cannot fetch the number of instances", func() {
					BeforeEach(func() {
						serviceRepo.ServiceInstanceCountApiResponse = net.NewApiResponseWithMessage("service instance fetch is very bad")
					})

					It("notifies the user of the failure", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						testassert.SliceContains(ui.Outputs, testassert.Lines{
							{"FAILED"},
							{"service instance fetch is very bad"},
						})
					})
				})
			})

			Context("when the user does not confirm", func() {
				BeforeEach(func() {
					ui.Inputs = append(ui.Inputs, "no")
				})

				It("does not continue the migration", func() {
					testcmd.RunCommand(cmd, context, requirementsFactory)

					testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{{"Migrating"}})
					Expect(serviceRepo.MigrateServicePlanFromV1ToV2Called).To(BeFalse())
				})
			})
		})
	})
}
Esempio n. 22
0
			{"OK"},
		})
	})
	It("TestDeleteWithForceOption", func() {

		app := models.Application{}
		app.Name = "app-to-delete"
		app.Guid = "app-to-delete-guid"

		reqFactory := &testreq.FakeReqFactory{}
		appRepo := &testapi.FakeApplicationRepository{ReadApp: app}

		ui := &testterm.FakeUI{}
		ctxt := testcmd.NewContext("delete", []string{"-f", "app-to-delete"})

		cmd := NewDeleteApp(ui, testconfig.NewRepository(), appRepo)
		testcmd.RunCommand(cmd, ctxt, reqFactory)

		Expect(appRepo.ReadName).To(Equal("app-to-delete"))
		Expect(appRepo.DeletedAppGuid).To(Equal("app-to-delete-guid"))
		Expect(len(ui.Prompts)).To(Equal(0))
		Expect(len(ui.Outputs)).To(Equal(2))
		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Deleting", "app-to-delete"},
			{"OK"},
		})
	})
	It("TestDeleteAppThatDoesNotExist", func() {

		reqFactory := &testreq.FakeReqFactory{}
		appRepo := &testapi.FakeApplicationRepository{ReadNotFound: true}