Пример #1
1
func TestLoggingInWithTooManyOrgsDoesNotShowOrgList(t *testing.T) {
	c := LoginTestContext{
		Inputs: []string{"api.example.com", "*****@*****.**", "password", "my-org-1", "my-space"},
	}

	callLogin(t, &c, func(c *LoginTestContext) {
		for i := 0; i < 60; i++ {
			id := strconv.Itoa(i)
			org := cf.Organization{}
			org.Guid = "my-org-guid-" + id
			org.Name = "my-org-" + id
			c.orgRepo.Organizations = append(c.orgRepo.Organizations, org)
		}

		c.orgRepo.FindByNameOrganization = c.orgRepo.Organizations[1]

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

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

		c.spaceRepo.Spaces = []cf.Space{space1, space2}
	})

	savedConfig := testconfig.SavedConfiguration

	testassert.SliceDoesNotContain(t, c.ui.Outputs, testassert.Lines{
		{"my-org-2"},
	})
	assert.Equal(t, c.orgRepo.FindByNameName, "my-org-1")
	assert.Equal(t, savedConfig.OrganizationFields.Guid, "my-org-guid-1")
}
Пример #2
0
func TestEmptyServicesList(t *testing.T) {
	serviceInstances := []cf.ServiceInstance{}
	serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{
		GetSummariesInCurrentSpaceInstances: serviceInstances,
	}
	ui := &testterm.FakeUI{}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	space := cf.SpaceFields{}
	space.Name = "my-space"
	config := &configuration.Configuration{
		SpaceFields:        space,
		OrganizationFields: org,
		AccessToken:        token,
	}

	cmd := NewListServices(ui, config, serviceSummaryRepo)
	cmd.Run(testcmd.NewContext("services", []string{}))

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting services in org", "my-org", "my-space", "my-user"},
		{"OK"},
		{"No services found"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"name", "service", "plan", "bound apps"},
	})
}
Пример #3
0
func TestGetRequestWithMultipleHeaderFlags(t *testing.T) {
	deps := newCurlDependencies()

	runCurlWithInputs(deps, []string{"-H", "Content-Type:cat", "-H", "Content-Length:12", "/foo"})

	assert.Equal(t, deps.curlRepo.Header, "Content-Type:cat\nContent-Length:12")
	testassert.SliceDoesNotContain(t, deps.ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #4
0
func TestRequestWithMethodFlag(t *testing.T) {
	deps := newCurlDependencies()

	runCurlWithInputs(deps, []string{"-X", "post", "/foo"})

	assert.Equal(t, deps.curlRepo.Method, "post")
	testassert.SliceDoesNotContain(t, deps.ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #5
0
func TestGetRequestWithDataFlag(t *testing.T) {
	deps := newCurlDependencies()

	runCurlWithInputs(deps, []string{"-d", "body content to upload", "/foo"})

	assert.Equal(t, deps.curlRepo.Body, "body content to upload")
	testassert.SliceDoesNotContain(t, deps.ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #6
0
func TestPushingWithDefaultManifestNotFound(t *testing.T) {
	deps := getPushDependencies()
	deps.appRepo.ReadNotFound = true
	deps.manifestRepo.ReadManifestManifest = singleAppManifest()
	deps.manifestRepo.ReadManifestErrors = manifest.ManifestErrors{syscall.ENOENT}

	ui := callPush(t, []string{"--no-route", "app-name"}, deps)

	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #7
0
func TestPushingWithNoManifestFlag(t *testing.T) {
	deps := getPushDependencies()
	deps.appRepo.ReadNotFound = true

	ui := callPush(t, []string{"--no-route", "--no-manifest", "app-name"}, deps)

	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
		{"hacker-manifesto"},
	})

	assert.Equal(t, deps.manifestRepo.ReadManifestPath, "")
	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("name").(string), "app-name")
}
Пример #8
0
func TestCreateBuildpackWithPosition(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	repo, bitsRepo := getRepositories()
	ui := callCreateBuildpack([]string{"my-buildpack", "my.war", "5"}, reqFactory, repo, bitsRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating buildpack", "my-buildpack"},
		{"OK"},
		{"Uploading buildpack", "my-buildpack"},
		{"OK"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #9
0
func TestGetRequestWithIncludeFlag(t *testing.T) {
	deps := newCurlDependencies()

	deps.curlRepo.ResponseHeader = "Content-Size:1024"
	deps.curlRepo.ResponseBody = "response for get"
	runCurlWithInputs(deps, []string{"-i", "/foo"})

	testassert.SliceContains(t, deps.ui.Outputs, testassert.Lines{
		{"Content-Size:1024"},
		{"response for get"},
	})
	testassert.SliceDoesNotContain(t, deps.ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #10
0
func TestCreateBuildpackWhenItAlreadyExists(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	repo, bitsRepo := getRepositories()

	repo.CreateBuildpackExists = true
	ui := callCreateBuildpack([]string{"my-buildpack", "my.war", "5"}, reqFactory, repo, bitsRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating buildpack", "my-buildpack"},
		{"OK"},
		{"my-buildpack", "already exists"},
		{"tip", "update-buildpack"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #11
0
func TestRequestWithNoFlags(t *testing.T) {
	deps := newCurlDependencies()

	deps.curlRepo.ResponseHeader = "Content-Size:1024"
	deps.curlRepo.ResponseBody = "response for get"
	runCurlWithInputs(deps, []string{"/foo"})

	assert.Equal(t, deps.curlRepo.Method, "GET")
	assert.Equal(t, deps.curlRepo.Path, "/foo")
	testassert.SliceContains(t, deps.ui.Outputs, testassert.Lines{
		{"response for get"},
	})
	testassert.SliceDoesNotContain(t, deps.ui.Outputs, testassert.Lines{
		{"FAILED"},
		{"Content-Size:1024"},
	})
}
Пример #12
0
func TestMarketplaceServicesWhenNotLoggedIn(t *testing.T) {
	serviceOfferings := []cf.ServiceOffering{}
	serviceRepo := &testapi.FakeServiceRepo{ServiceOfferings: serviceOfferings}

	config := &configuration.Configuration{}

	ui := callMarketplaceServices(t, config, serviceRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting services from marketplace..."},
		{"OK"},
		{"No service offerings found"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"service", "plans", "description"},
	})
}
Пример #13
0
func TestCreateBuildpackEnabled(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	repo, bitsRepo := getRepositories()
	ui := callCreateBuildpack([]string{"--enable", "my-buildpack", "my.war", "5"}, reqFactory, repo, bitsRepo)

	assert.NotNil(t, repo.CreateBuildpack.Enabled)
	assert.Equal(t, *repo.CreateBuildpack.Enabled, true)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"creating buildpack", "my-buildpack"},
		{"OK"},
		{"uploading buildpack", "my-buildpack"},
		{"OK"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
	})
}
Пример #14
0
func TestCreateSpaceWhenItAlreadyExists(t *testing.T) {
	resetSpaceDefaults()
	defaultSpaceRepo.CreateSpaceExists = true
	ui := callCreateSpace(t, []string{"my-space"}, defaultReqFactory, defaultSpaceRepo, defaultOrgRepo, defaultUserRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating space", "my-space"},
		{"OK"},
		{"my-space", "already exists"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"Assigning", "my-user", "my-space", cf.SpaceRoleToUserInput[cf.SPACE_MANAGER]},
	})

	assert.Equal(t, defaultSpaceRepo.CreateSpaceName, "")
	assert.Equal(t, defaultSpaceRepo.CreateSpaceOrgGuid, "")
	assert.Equal(t, defaultUserRepo.SetSpaceRoleUserGuid, "")
	assert.Equal(t, defaultUserRepo.SetSpaceRoleSpaceGuid, "")
}
Пример #15
0
func TestPushingAppWhenItAlreadyExistsAndNoHostFlagIsPresent(t *testing.T) {
	deps := getPushDependencies()

	domain := cf.Domain{}
	domain.Name = "example.com"
	domain.Guid = "domain-guid"
	domain.Shared = true

	existingRoute := cf.RouteSummary{}
	existingRoute.Host = "existing-app"
	existingRoute.Domain = domain.DomainFields

	existingApp := cf.Application{}
	existingApp.Name = "existing-app"
	existingApp.Guid = "existing-app-guid"
	existingApp.Routes = []cf.RouteSummary{existingRoute}

	deps.appRepo.ReadApp = existingApp
	deps.appRepo.UpdateAppResult = existingApp
	deps.routeRepo.FindByHostAndDomainNotFound = true
	deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{domain}

	ui := callPush(t, []string{"--no-hostname", "existing-app"}, deps)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating route", "example.com"},
		{"OK"},
		{"Binding", "example.com"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"existing-app.example.com"},
	})

	assert.Equal(t, deps.routeRepo.FindByHostAndDomainDomain, "example.com")
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "")
	assert.Equal(t, deps.routeRepo.CreatedHost, "")
	assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "domain-guid")
}
Пример #16
0
func TestStartApplicationOnlyShowsCurrentStagingLogs(t *testing.T) {
	t.Parallel()

	displayApp := &testcmd.FakeAppDisplayer{}
	reqFactory := &testreq.FakeReqFactory{Application: defaultAppForStart}
	appRepo := &testapi.FakeApplicationRepository{
		ReadApp:         defaultAppForStart,
		UpdateAppResult: defaultAppForStart,
	}
	appInstancesRepo := &testapi.FakeAppInstancesRepo{
		GetInstancesResponses:  defaultInstanceReponses,
		GetInstancesErrorCodes: defaultInstanceErrorCodes,
	}

	currentTime := time.Now()
	wrongSourceName := "DEA"
	correctSourceName := "STG"

	logRepo := &testapi.FakeLogsRepository{
		TailLogMessages: []*logmessage.Message{
			NewLogMessage("Log Line 1", defaultAppForStart.Guid, wrongSourceName, currentTime),
			NewLogMessage("Log Line 2", defaultAppForStart.Guid, correctSourceName, currentTime),
			NewLogMessage("Log Line 3", defaultAppForStart.Guid, correctSourceName, currentTime),
			NewLogMessage("Log Line 4", defaultAppForStart.Guid, wrongSourceName, currentTime),
		},
	}

	ui := callStart([]string{"my-app"}, &configuration.Configuration{}, reqFactory, displayApp, appRepo, appInstancesRepo, logRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Log Line 2"},
		{"Log Line 3"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"Log Line 1"},
		{"Log Line 4"},
	})
}
Пример #17
0
func TestStartApplicationWhenStartTimesOut(t *testing.T) {
	t.Parallel()

	displayApp := &testcmd.FakeAppDisplayer{}
	appInstance := cf.AppInstanceFields{}
	appInstance.State = cf.InstanceStarting
	appInstance2 := cf.AppInstanceFields{}
	appInstance2.State = cf.InstanceStarting
	appInstance3 := cf.AppInstanceFields{}
	appInstance3.State = cf.InstanceStarting
	appInstance4 := cf.AppInstanceFields{}
	appInstance4.State = cf.InstanceDown
	appInstance5 := cf.AppInstanceFields{}
	appInstance5.State = cf.InstanceDown
	appInstance6 := cf.AppInstanceFields{}
	appInstance6.State = cf.InstanceDown
	instances := [][]cf.AppInstanceFields{
		[]cf.AppInstanceFields{appInstance, appInstance2},
		[]cf.AppInstanceFields{appInstance3, appInstance4},
		[]cf.AppInstanceFields{appInstance5, appInstance6},
	}

	errorCodes := []string{"500", "500", "500"}

	ui, _, _, _ := startAppWithInstancesAndErrors(t, displayApp, defaultAppForStart, instances, errorCodes, 0)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Starting", "my-app"},
		{"OK"},
		{"FAILED"},
		{"Start app timeout"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"instances running"},
	})
}
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())
				})
			})
		})
	})
}
Пример #19
0
		ui := callCreateSpace([]string{"-o", "cool-organization", "my-space"}, defaultReqFactory, defaultSpaceRepo, defaultOrgRepo, defaultUserRepo)

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

		Expect(defaultSpaceRepo.CreateSpaceName).To(Equal(""))
	})
	It("TestCreateSpaceWhenItAlreadyExists", func() {

		resetSpaceDefaults()
		defaultSpaceRepo.CreateSpaceExists = true
		ui := callCreateSpace([]string{"my-space"}, defaultReqFactory, defaultSpaceRepo, defaultOrgRepo, defaultUserRepo)

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating space", "my-space"},
			{"OK"},
			{"my-space", "already exists"},
		})
		testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
			{"Assigning", "my-user", "my-space", models.SpaceRoleToUserInput[models.SPACE_MANAGER]},
		})

		Expect(defaultSpaceRepo.CreateSpaceName).To(Equal(""))
		Expect(defaultSpaceRepo.CreateSpaceOrgGuid).To(Equal(""))
		Expect(defaultUserRepo.SetSpaceRoleUserGuid).To(Equal(""))
		Expect(defaultUserRepo.SetSpaceRoleSpaceGuid).To(Equal(""))
	})
})
Пример #20
0
	It("indicates when a service doesn't exist", func() {
		deps := setupDependencies()

		deps.serviceRepo.FindServiceOfferingByLabelAndProviderApiResponse = cferrors.NewModelNotFoundError("Service Offering", "")

		deps.ui.Inputs = []string{"yes"}

		testcmd.RunCommand(
			NewPurgeServiceOffering(deps.ui, deps.config, deps.serviceRepo),
			testcmd.NewContext("purge-service-offering", []string{"-p", "the-provider", "the-service-name"}),
			deps.reqFactory,
		)

		testassert.SliceContains(deps.ui.Outputs, testassert.Lines{{"Service offering", "does not exist"}})
		testassert.SliceDoesNotContain(deps.ui.Outputs, testassert.Lines{{"Warning"}})
		testassert.SliceDoesNotContain(deps.ui.Outputs, testassert.Lines{{"Ok"}})

		Expect(deps.serviceRepo.PurgeServiceOfferingCalled).To(Equal(false))
	})
})

type commandDependencies struct {
	ui          *testterm.FakeUI
	config      configuration.ReadWriter
	serviceRepo *testapi.FakeServiceRepo
	reqFactory  *testreq.FakeReqFactory
}

func setupDependencies() (obj commandDependencies) {
	obj.ui = &testterm.FakeUI{}
Пример #21
0
	It("creates and uploads buildpacks", func() {
		context := testcmd.NewContext("create-buildpack", []string{"my-buildpack", "my.war", "5"})
		testcmd.RunCommand(cmd, context, requirementsFactory)

		Expect(repo.CreateBuildpack.Enabled).To(BeNil())
		Expect(ui.FailedWithUsage).To(BeFalse())

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating buildpack", "my-buildpack"},
			{"OK"},
			{"Uploading buildpack", "my-buildpack"},
			{"OK"},
		})
		testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
			{"FAILED"},
		})
	})

	It("warns the user when the buildpack already exists", func() {
		repo.CreateBuildpackExists = true
		context := testcmd.NewContext("create-buildpack", []string{"my-buildpack", "my.war", "5"})
		testcmd.RunCommand(cmd, context, requirementsFactory)

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating buildpack", "my-buildpack"},
			{"OK"},
			{"my-buildpack", "already exists"},
			{"tip", "update-buildpack"},
		})
		testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
Пример #22
0
			TailLogMessages: []*logmessage.Message{
				NewLogMessage("Log Line 1", defaultAppForStart.Guid, wrongSourceName, currentTime),
				NewLogMessage("Log Line 2", defaultAppForStart.Guid, correctSourceName, currentTime),
				NewLogMessage("Log Line 3", defaultAppForStart.Guid, correctSourceName, currentTime),
				NewLogMessage("Log Line 4", defaultAppForStart.Guid, wrongSourceName, currentTime),
			},
		}

		ui := callStart([]string{"my-app"}, testconfig.NewRepository(), reqFactory, displayApp, appRepo, appInstancesRepo, logRepo)

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Log Line 2"},
			{"Log Line 3"},
		})
		testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
			{"Log Line 1"},
			{"Log Line 4"},
		})
	})

	It("TestStartApplicationWhenAppHasNoURL", func() {
		displayApp := &testcmd.FakeAppDisplayer{}
		app := defaultAppForStart
		app.Routes = []models.RouteSummary{}
		appInstance := models.AppInstanceFields{}
		appInstance.State = models.InstanceRunning
		instances := [][]models.AppInstanceFields{
			[]models.AppInstanceFields{appInstance},
			[]models.AppInstanceFields{appInstance},
		}

		errorCodes := []string{""}
Пример #23
0
	It("strips special characters when creating a default route", func() {
		routeRepo.FindByHostAndDomainErr = true
		appRepo.ReadNotFound = true

		callPush("-t", "111", "Tim's 1st-Crazy__app!")
		Expect(*appRepo.CreatedAppParams().Name).To(Equal("Tim's 1st-Crazy__app!"))

		Expect(routeRepo.FindByHostAndDomainHost).To(Equal("tims-1st-crazy-app"))
		Expect(routeRepo.CreatedHost).To(Equal("tims-1st-crazy-app"))

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating", "tims-1st-crazy-app.foo.cf-app.com"},
			{"Binding", "tims-1st-crazy-app.foo.cf-app.com"},
		})
		testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
			{"FAILED"},
		})
	})

	It("binds to existing routes when pushing an app", func() {
		route := models.Route{}
		route.Guid = "my-route-guid"
		route.Host = "my-new-app"
		route.Domain = domainRepo.ListSharedDomainsDomains[0]

		routeRepo.FindByHostAndDomainRoute = route
		appRepo.ReadNotFound = true

		callPush("my-new-app")

		Expect(routeRepo.CreatedHost).To(BeEmpty())
Пример #24
0
				space2 := models.Space{}
				space2.Guid = "some-space-guid"
				space2.Name = "some-space"

				spaceRepo.Spaces = []models.Space{space1, space2}
			})

			It("doesn't display a list of orgs (the user must type the name)", func() {
				ui.Inputs = []string{"api.example.com", "*****@*****.**", "password", "my-org-1", "my-space"}

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

				testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
					{"my-org-2"},
				})
				Expect(orgRepo.FindByNameName).To(Equal("my-org-1"))
				Expect(Config.OrganizationFields().Guid).To(Equal("my-org-guid-1"))
			})
		})

		Describe("when there is only a single org and space", func() {
			It("does not ask the user to select an org/space", func() {
				ui.Inputs = []string{"http://api.example.com", "*****@*****.**", "password"}

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

				Expect(Config.OrganizationFields().Guid).To(Equal("my-new-org-guid"))
				Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
Пример #25
0
		testcmd.RunCommand(cmd, testcmd.NewContext("services", []string{}), reqFactory)

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Getting services in org", "my-org", "my-space", "my-user"},
			{"OK"},
			{"my-service-1", "cleardb", "spark", "cli1, cli2"},
			{"my-service-2", "cleardb", "spark-2", "cli1"},
			{"my-service-provided-by-user", "user-provided"},
		})
	})

	It("lists no services when none are found", func() {
		serviceInstances := []models.ServiceInstance{}
		serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{
			GetSummariesInCurrentSpaceInstances: serviceInstances,
		}

		cmd := NewListServices(ui, configRepo, serviceSummaryRepo)
		testcmd.RunCommand(cmd, testcmd.NewContext("services", []string{}), reqFactory)

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Getting services in org", "my-org", "my-space", "my-user"},
			{"OK"},
			{"No services found"},
		})
		testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
			{"name", "service", "plan", "bound apps"},
		})
	})
})
Пример #26
0
			runCurlWithInputs(deps, []string{"/foo"})
			Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
		})

		It("makes a get request given an endpoint", func() {
			deps.curlRepo.ResponseHeader = "Content-Size:1024"
			deps.curlRepo.ResponseBody = "response for get"
			runCurlWithInputs(deps, []string{"/foo"})

			Expect(deps.curlRepo.Method).To(Equal("GET"))
			Expect(deps.curlRepo.Path).To(Equal("/foo"))
			testassert.SliceContains(deps.ui.Outputs, testassert.Lines{
				{"response for get"},
			})
			testassert.SliceDoesNotContain(deps.ui.Outputs, testassert.Lines{
				{"FAILED"},
				{"Content-Size:1024"},
			})
		})

		It("makes a post request given -X", func() {
			runCurlWithInputs(deps, []string{"-X", "post", "/foo"})

			Expect(deps.curlRepo.Method).To(Equal("post"))
			testassert.SliceDoesNotContain(deps.ui.Outputs, testassert.Lines{
				{"FAILED"},
			})
		})

		It("sends headers given -H", func() {
			runCurlWithInputs(deps, []string{"-H", "Content-Type:cat", "/foo"})
Пример #27
0
	Context("when user is not logged in", func() {
		var config configuration.Reader

		BeforeEach(func() {
			config = testconfig.NewRepository()
		})

		It("prompts the user to login", func() {
			output := captureOutput(func() {
				ui := NewUI((os.Stdin))
				ui.ShowConfiguration(config)
			})

			testassert.SliceDoesNotContain(output, testassert.Lines{
				{"API endpoint:"},
			})

			testassert.SliceContains(output, testassert.Lines{
				{"Not logged in", "Use", "log in"},
			})
		})

	})

	Context("when an api endpoint is set and the user logged in", func() {
		var config configuration.ReadWriter

		BeforeEach(func() {
			accessToken := configuration.TokenInfo{
				UserGuid: "my-user-guid",
Пример #28
0
		c.orgRepo.FindByNameOrganization = c.orgRepo.Organizations[1]

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

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

		c.spaceRepo.Spaces = []models.Space{space1, space2}

		callLogin(c)

		testassert.SliceDoesNotContain(c.ui.Outputs, testassert.Lines{
			{"my-org-2"},
		})
		Expect(c.orgRepo.FindByNameName).To(Equal("my-org-1"))
		Expect(c.Config.OrganizationFields().Guid).To(Equal("my-org-guid-1"))
	})

	It("TestSuccessfullyLoggingInWithFlags", func() {
		c := setUpLoginTestContext()

		c.Flags = []string{"-a", "api.example.com", "-u", "*****@*****.**", "-p", "password", "-o", "my-org", "-s", "my-space"}

		callLogin(c)

		Expect(c.Config.ApiEndpoint()).To(Equal("api.example.com"))
		Expect(c.Config.OrganizationFields().Guid).To(Equal("my-org-guid"))
		Expect(c.Config.SpaceFields().Guid).To(Equal("my-space-guid"))
Пример #29
0
			serviceRepo.GetAllServiceOfferingsReturns.ServiceOfferings = fakeServiceOfferings

			cmd := NewMarketplaceServices(ui, config, serviceRepo)
			testcmd.RunCommand(cmd, testcmd.NewContext("marketplace", []string{}), reqFactory)

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Getting all services from marketplace"},
				{"OK"},
				{"service", "plans", "description"},
				{"aaa-my-service-offering", "service offering 2 description", "service-plan-c", "service-plan-d"},
				{"zzz-my-service-offering", "service offering 1 description", "service-plan-a", "service-plan-b"},
			})
		})

		It("does not display a table if no service offerings exist", func() {
			serviceRepo := &testapi.FakeServiceRepo{}
			serviceRepo.GetAllServiceOfferingsReturns.ServiceOfferings = []models.ServiceOffering{}

			cmd := NewMarketplaceServices(ui, config, serviceRepo)
			testcmd.RunCommand(cmd, testcmd.NewContext("marketplace", []string{}), reqFactory)

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"No service offerings found"},
			})
			testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
				{"service", "plans", "description"},
			})
		})
	})
})
Пример #30
0
		})

		Context("when no flags are specified", func() {
			It("prints a description of the app's limits", func() {
				testcmd.RunCommand(cmd, testcmd.NewContext("scale", []string{"my-app"}), reqFactory)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"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() {