コード例 #1
0
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())
				})
			})
		})
	})
}
コード例 #2
0
		})

		It("deletes the service auth token", func() {
			runCommand("a label", "a provider")
			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Deleting service auth token as", "my-user"},
				{"OK"},
			})

			Expect(authTokenRepo.FindByLabelAndProviderLabel).To(Equal("a label"))
			Expect(authTokenRepo.FindByLabelAndProviderProvider).To(Equal("a provider"))
			Expect(authTokenRepo.DeletedServiceAuthTokenFields.Guid).To(Equal("the-guid"))
		})

		It("does nothing when the user does not confirm", func() {
			ui.Inputs = []string{"nope"}
			runCommand("a label", "a provider")

			testassert.SliceContains(ui.Prompts, testassert.Lines{
				{"Really delete", "service auth token", "a label", "a provider"},
			})
			Expect(ui.Outputs).To(BeEmpty())
			Expect(authTokenRepo.DeletedServiceAuthTokenFields).To(Equal(models.ServiceAuthTokenFields{}))
		})

		It("does not prompt the user when the -f flag is given", func() {
			ui.Inputs = []string{}
			runCommand("-f", "a label", "a provider")

			Expect(ui.Prompts).To(BeEmpty())
			testassert.SliceContains(ui.Outputs, testassert.Lines{
コード例 #3
0
ファイル: delete_test.go プロジェクト: nota-ja/cli
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true
		})

		It("provides the user usage text when no app name is given", func() {
			runCommand()
			Expect(ui.FailedWithUsage).To(BeTrue())
		})

		Context("When provided an app that exists", func() {
			BeforeEach(func() {
				appRepo.ReadReturns.App = app
			})

			It("deletes an app when the user confirms", func() {
				ui.Inputs = []string{"y"}

				runCommand("app-to-delete")

				Expect(appRepo.ReadArgs.Name).To(Equal("app-to-delete"))
				Expect(appRepo.DeletedAppGuid).To(Equal("app-to-delete-guid"))

				testassert.SliceContains(ui.Prompts, testassert.Lines{
					{"Really delete the app app-to-delete"},
				})

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Deleting", "app-to-delete", "my-org", "my-space", "my-user"},
					{"OK"},
				})
			})
コード例 #4
0
ファイル: delete_org_test.go プロジェクト: nota-ja/cli
					{"OK"},
				})
				Expect(orgRepo.FindByNameName).To(Equal("org-to-delete"))
				Expect(orgRepo.DeletedOrganizationGuid).To(Equal("org-to-delete-guid"))
			})

			It("does not untarget the org and space", func() {
				runCommand("org-to-delete")

				Expect(config.OrganizationFields().Name).To(Equal("some-other-org"))
				Expect(config.SpaceFields().Name).To(Equal("some-other-space"))
			})
		})

		It("does not prompt when the -f flag is given", func() {
			ui.Inputs = []string{}
			runCommand("-f", "org-to-delete")

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Deleting", "org-to-delete"},
				{"OK"},
			})
			Expect(orgRepo.FindByNameName).To(Equal("org-to-delete"))
			Expect(orgRepo.DeletedOrganizationGuid).To(Equal("org-to-delete-guid"))
		})

		It("warns the user when the org does not exist", func() {
			orgRepo.FindByNameNotFound = true

			runCommand("org-to-delete")
コード例 #5
0
ファイル: login_test.go プロジェクト: juggernaut/cli
				space1 := models.Space{}
				space1.Guid = "my-space-guid"
				space1.Name = "my-space"

				space2 = models.Space{}
				space2.Guid = "some-space-guid"
				space2.Name = "some-space"

				orgRepo.Organizations = []models.Organization{org1, org2}
				spaceRepo.Spaces = []models.Space{space1, space2}
			})

			It("lets the user select an org and space by number", func() {
				OUT_OF_RANGE_CHOICE := "3"

				ui.Inputs = []string{"api.example.com", "*****@*****.**", "password", OUT_OF_RANGE_CHOICE, "2", OUT_OF_RANGE_CHOICE, "1"}

				l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
				testcmd.RunCommand(l, testcmd.NewContext("login", Flags), nil)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Select an org"},
					{"1. some-org"},
					{"2. my-new-org"},
					{"Select a space"},
					{"1. my-space"},
					{"2. some-space"},
				})

				Expect(Config.OrganizationFields().Guid).To(Equal("my-new-org-guid"))
				Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
コード例 #6
0
ファイル: delete_org_test.go プロジェクト: knolleary/cli
		orgFields := models.OrganizationFields{}
		orgFields.Name = "my-org"

		token := configuration.TokenInfo{Username: "******"}
		config = testconfig.NewRepositoryWithAccessToken(token)
		config.SetSpaceFields(spaceFields)
		config.SetOrganizationFields(orgFields)

		org := models.Organization{}
		org.Name = "org-to-delete"
		org.Guid = "org-to-delete-guid"
		orgRepo = &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
	})

	It("TestDeleteOrgConfirmingWithY", func() {
		ui.Inputs = []string{"y"}
		cmd := NewDeleteOrg(ui, config, orgRepo)
		testcmd.RunCommand(cmd, testcmd.NewContext("delete-org", []string{"org-to-delete"}), reqFactory)

		testassert.SliceContains(ui.Prompts, testassert.Lines{
			{"Really delete"},
		})

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Deleting", "org-to-delete"},
			{"OK"},
		})
		Expect(orgRepo.FindByNameName).To(Equal("org-to-delete"))
		Expect(orgRepo.DeletedOrganizationGuid).To(Equal("org-to-delete-guid"))
	})
コード例 #7
0
ファイル: delete_domain_test.go プロジェクト: nota-ja/cli
				runCommand("foo.com")

				Expect(domainRepo.DeleteDomainGuid).To(Equal("foo-guid"))

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Deleting domain", "foo.com"},
					{"FAILED"},
					{"foo.com"},
					{"failed badly"},
				})
			})
		})

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

			It("does nothing", func() {
				runCommand("foo.com")

				Expect(domainRepo.DeleteDomainGuid).To(Equal(""))

				testassert.SliceContains(ui.Prompts, testassert.Lines{
					{"delete", "foo.com"},
				})

				Expect(ui.Outputs).To(BeEmpty())
			})
		})
コード例 #8
0
ファイル: scale_test.go プロジェクト: knolleary/cli
					{"Showing", "my-app", "my-org", "my-space", "my-user"},
					{"OK"},
					{"memory", "256M"},
					{"disk", "1G"},
					{"instances", "42"},
				})

				testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
					{"Scaling", "my-app", "my-org", "my-space", "my-user"},
				})
			})
		})

		Context("when the user does not confirm 'yes'", func() {
			It("does not restart the app", func() {
				ui.Inputs = []string{"whatever"}
				testcmd.RunCommand(cmd, testcmd.NewContext("scale", []string{"-i", "5", "-m", "512M", "-k", "2G", "my-app"}), reqFactory)

				Expect(restarter.AppToRestart.Guid).To(Equal(""))
			})
		})

		Context("when the user provides the -f flag", func() {
			It("does not prompt the user", func() {
				testcmd.RunCommand(cmd, testcmd.NewContext("scale", []string{"-f", "-i", "5", "-m", "512M", "-k", "2G", "my-app"}), reqFactory)
				Expect(restarter.AppToRestart.Guid).To(Equal("my-app-guid"))
			})
		})

		Context("when the user confirms they want to restart", func() {
			BeforeEach(func() {
コード例 #9
0
			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	It("creates a new user provided service given just a name", func() {
		args := []string{"my-custom-service"}
		ctxt := testcmd.NewContext("create-user-provided-service", args)
		testcmd.RunCommand(cmd, ctxt, requirementsFactory)
		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating user provided service"},
			{"OK"},
		})
	})

	It("accepts service parameters interactively", func() {
		ui.Inputs = []string{"foo value", "bar value", "baz value"}
		ctxt := testcmd.NewContext("create-user-provided-service", []string{"-p", `"foo, bar, baz"`, "my-custom-service"})
		testcmd.RunCommand(cmd, ctxt, requirementsFactory)

		testassert.SliceContains(ui.Prompts, testassert.Lines{
			{"foo"},
			{"bar"},
			{"baz"},
		})

		Expect(repo.CreateName).To(Equal("my-custom-service"))
		Expect(repo.CreateParams).To(Equal(map[string]string{
			"foo": "foo value",
			"bar": "bar value",
			"baz": "baz value",
		}))
コード例 #10
0
ファイル: delete_route_test.go プロジェクト: julz/cli
		routeRepo  *testapi.FakeRouteRepository
		reqFactory *testreq.FakeReqFactory
		ui         *testterm.FakeUI
		cmd        *DeleteRoute
	)

	BeforeEach(func() {
		configRepo := testconfig.NewRepositoryWithDefaults()
		ui = &testterm.FakeUI{}
		routeRepo = &testapi.FakeRouteRepository{}
		reqFactory = &testreq.FakeReqFactory{}
		cmd = NewDeleteRoute(ui, configRepo, routeRepo)
	})

	var callDeleteRoute = func(confirmation string, args []string) {
		ui.Inputs = []string{confirmation}
		testcmd.RunCommand(cmd, testcmd.NewContext("delete-route", args), reqFactory)
	}

	It("fails requirements when not logged in", func() {
		callDeleteRoute("y", []string{"-n", "my-host", "example.com"})
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	Context("when logged in successfully", func() {
		BeforeEach(func() {
			reqFactory.LoginSuccess = true
			route := models.Route{}
			route.Guid = "route-guid"
			route.Host = "my-host"
			route.Domain = models.DomainFields{