Esempio n. 1
0
func TestUpdateRejectsInproperNames(t *testing.T) {
	baseRequest := testnet.TestRequest{
		Method:   "PUT",
		Path:     "/v2/apps/my-app-guid",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: "{}"},
	}

	requests := []testnet.TestRequest{
		baseRequest,
		baseRequest,
	}

	ts, _, repo := createAppRepo(t, requests)
	defer ts.Close()

	app := cf.Application{}
	app.Guid = "my-app-guid"
	app.Name = "name with space"

	createdApp, apiResponse := repo.Update(app.Guid, app.ToParams())
	assert.Equal(t, createdApp, cf.Application{})
	assert.Contains(t, apiResponse.Message, "App name is invalid")

	app.Name = "name-with-inv@lid-chars!"
	_, apiResponse = repo.Update(app.Guid, app.ToParams())
	assert.True(t, apiResponse.IsNotSuccessful())

	app.Name = "Valid-Name"
	_, apiResponse = repo.Update(app.Guid, app.ToParams())
	assert.True(t, apiResponse.IsSuccessful())

	app.Name = "name_with_numbers_2"
	_, apiResponse = repo.Update(app.Guid, app.ToParams())
	assert.True(t, apiResponse.IsSuccessful())
}
Esempio n. 2
0
func deleteApp(t *testing.T, confirmation string, args []string) (ui *testterm.FakeUI, reqFactory *testreq.FakeReqFactory, appRepo *testapi.FakeApplicationRepository) {

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

	reqFactory = &testreq.FakeReqFactory{}
	appRepo = &testapi.FakeApplicationRepository{ReadApp: app}
	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}

	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,
	}

	ctxt := testcmd.NewContext("delete", args)
	cmd := NewDeleteApp(ui, config, appRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Esempio n. 3
0
func TestEventsSuccess(t *testing.T) {
	timestamp, err := time.Parse(TIMESTAMP_FORMAT, "2000-01-01T00:01:11.00-0000")
	assert.NoError(t, err)

	reqFactory, eventsRepo := getEventsDependencies()
	app := cf.Application{}
	app.Name = "my-app"
	reqFactory.Application = app

	eventsRepo.Events = []cf.EventFields{
		{
			InstanceIndex:   98,
			Timestamp:       timestamp,
			ExitDescription: "app instance exited",
			ExitStatus:      78,
		},
		{
			InstanceIndex:   99,
			Timestamp:       timestamp,
			ExitDescription: "app instance was stopped",
			ExitStatus:      77,
		},
	}

	ui := callEvents(t, []string{"my-app"}, reqFactory, eventsRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting events for app", "my-app", "my-org", "my-space", "my-user"},
		{"time", "instance", "description", "exit status"},
		{timestamp.Local().Format(TIMESTAMP_FORMAT), "98", "app instance exited", "78"},
		{timestamp.Local().Format(TIMESTAMP_FORMAT), "99", "app instance was stopped", "77"},
	})
}
Esempio n. 4
0
func TestPushingAppWithNoFlagsWhenAppIsAlreadyBoundToDomain(t *testing.T) {
	deps := getPushDependencies()

	domain := cf.DomainFields{}
	domain.Name = "example.com"

	existingRoute := cf.RouteSummary{}
	existingRoute.Host = "foo"
	existingRoute.Domain = domain

	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

	_ = callPush(t, []string{"existing-app"}, deps)

	assert.Equal(t, deps.appBitsRepo.UploadedAppGuid, "existing-app-guid")
	assert.Equal(t, deps.domainRepo.FindByNameInCurrentSpaceName, "")
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainDomain, "")
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "")
	assert.Equal(t, deps.routeRepo.CreatedHost, "")
	assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "")
}
Esempio n. 5
0
func TestPushingAppWhenItAlreadyExistsAndDomainIsSpecifiedIsAlreadyBound(t *testing.T) {
	deps := getPushDependencies()

	domain := cf.DomainFields{}
	domain.Name = "example.com"
	domain.Guid = "domain-guid"

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

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

	foundRoute := cf.Route{}
	foundRoute.RouteFields = existingRoute.RouteFields
	foundRoute.Domain = existingRoute.Domain

	deps.appRepo.ReadApp = existingApp
	deps.appRepo.UpdateAppResult = existingApp
	deps.routeRepo.FindByHostAndDomainRoute = foundRoute

	ui := callPush(t, []string{"-d", "example.com", "existing-app"}, deps)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Using route", "existing-app", "example.com"},
	})
	assert.Equal(t, deps.appBitsRepo.UploadedAppGuid, "existing-app-guid")
}
Esempio n. 6
0
func TestBindCommand(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service"
	serviceInstance.Guid = "my-service-guid"
	reqFactory := &testreq.FakeReqFactory{
		Application:     app,
		ServiceInstance: serviceInstance,
	}
	serviceBindingRepo := &testapi.FakeServiceBindingRepo{}
	ui := callBindService(t, []string{"my-app", "my-service"}, reqFactory, serviceBindingRepo)

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, reqFactory.ServiceInstanceName, "my-service")

	assert.Equal(t, len(ui.Outputs), 3)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Binding service", "my-service", "my-app", "my-org", "my-space", "my-user"},
		{"OK"},
		{"TIP"},
	})
	assert.Equal(t, serviceBindingRepo.CreateServiceInstanceGuid, "my-service-guid")
	assert.Equal(t, serviceBindingRepo.CreateApplicationGuid, "my-app-guid")
}
Esempio n. 7
0
func TestPushingAppWhenItAlreadyExistsAndHostIsSpecified(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{"-n", "new-host", "existing-app"}, deps)

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

	assert.Equal(t, deps.routeRepo.FindByHostAndDomainDomain, "example.com")
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "new-host")
	assert.Equal(t, deps.routeRepo.CreatedHost, "new-host")
	assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "domain-guid")
}
Esempio n. 8
0
func TestUnbindCommandWhenBindingIsNonExistent(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service"
	serviceInstance.Guid = "my-service-guid"
	reqFactory := &testreq.FakeReqFactory{
		Application:     app,
		ServiceInstance: serviceInstance,
	}
	serviceBindingRepo := &testapi.FakeServiceBindingRepo{DeleteBindingNotFound: true}
	ui := callUnbindService(t, []string{"my-app", "my-service"}, reqFactory, serviceBindingRepo)

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, reqFactory.ServiceInstanceName, "my-service")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Unbinding app", "my-service", "my-app"},
		{"OK"},
		{"my-service", "my-app", "did not exist"},
	})
	assert.Equal(t, serviceBindingRepo.DeleteServiceInstance, serviceInstance)
	assert.Equal(t, serviceBindingRepo.DeleteApplicationGuid, "my-app-guid")
}
Esempio n. 9
0
func TestSetEnvWhenItAlreadyExists(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	app.EnvironmentVars = map[string]string{"DATABASE_URL": "mysql://example.com/my-db"}
	reqFactory := &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: true}
	appRepo := &testapi.FakeApplicationRepository{}

	args := []string{"my-app", "DATABASE_URL", "mysql://example2.com/my-db"}
	ui := callSetEnv(t, args, reqFactory, appRepo)

	assert.Equal(t, len(ui.Outputs), 3)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{
			"Setting env variable",
			"DATABASE_URL",
			"mysql://example2.com/my-db",
			"my-app",
			"my-org",
			"my-space",
			"my-user",
		},
		{"OK"},
		{"TIP"},
	})

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, appRepo.UpdateAppGuid, app.Guid)

	envParams := appRepo.UpdateParams.Get("env").(generic.Map)
	assert.Equal(t, envParams.Get("DATABASE_URL").(string), "mysql://example2.com/my-db")
}
Esempio n. 10
0
func TestMapRouteWhenBinding(t *testing.T) {

	domain := cf.Domain{}
	domain.Guid = "my-domain-guid"
	domain.Name = "example.com"
	route := cf.Route{}
	route.Guid = "my-route-guid"
	route.Host = "foo"
	route.Domain = domain.DomainFields

	app := cf.Application{}
	app.Guid = "my-app-guid"
	app.Name = "my-app"

	routeRepo := &testapi.FakeRouteRepository{}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Application: app, Domain: domain}
	routeCreator := &testcmd.FakeRouteCreator{ReservedRoute: route}

	ui := callMapRoute(t, []string{"-n", "my-host", "my-app", "my-domain.com"}, reqFactory, routeRepo, routeCreator)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Adding route", "foo.example.com", "my-app", "my-org", "my-space", "my-user"},
		{"OK"},
	})

	assert.Equal(t, routeRepo.BoundRouteGuid, "my-route-guid")
	assert.Equal(t, routeRepo.BoundAppGuid, "my-app-guid")
}
Esempio n. 11
0
func TestPushingAppWhenItAlreadyExistsAndChangingOptions(t *testing.T) {
	deps := getPushDependencies()

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

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

	deps.appRepo.ReadApp = existingApp

	stack := cf.Stack{}
	stack.Name = "differentStack"
	stack.Guid = "differentStack-guid"
	deps.stackRepo.FindByNameStack = stack

	args := []string{
		"-c", "different start command",
		"-i", "10",
		"-m", "1G",
		"-b", "https://github.com/heroku/heroku-buildpack-different.git",
		"-s", "differentStack",
		"existing-app",
	}
	_ = callPush(t, args, deps)

	assert.Equal(t, deps.appRepo.UpdateParams.Get("command"), "different start command")
	assert.Equal(t, deps.appRepo.UpdateParams.Get("instances"), 10)
	assert.Equal(t, deps.appRepo.UpdateParams.Get("memory"), uint64(1024))
	assert.Equal(t, deps.appRepo.UpdateParams.Get("buildpack"), "https://github.com/heroku/heroku-buildpack-different.git")
	assert.Equal(t, deps.appRepo.UpdateParams.Get("stack_guid"), "differentStack-guid")
}
Esempio n. 12
0
func TestLogsOutputsRecentLogs(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"

	currentTime := time.Now()

	recentLogs := []*logmessage.Message{
		NewLogMessage("Log Line 1", app.Guid, "DEA", currentTime),
		NewLogMessage("Log Line 2", app.Guid, "DEA", currentTime),
	}

	reqFactory, logsRepo := getLogsDependencies()
	reqFactory.Application = app
	logsRepo.RecentLogs = recentLogs

	ui := callLogs(t, []string{"--recent", "my-app"}, reqFactory, logsRepo)

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, app.Guid, logsRepo.AppLoggedGuid)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Connected, dumping recent logs for app", "my-app", "my-org", "my-space", "my-user"},
		{"Log Line 1"},
		{"Log Line 2"},
	})
}
Esempio n. 13
0
func TestApplicationStopReturnsUpdatedApp(t *testing.T) {
	appToStop := cf.Application{}
	appToStop.Name = "my-app"
	appToStop.Guid = "my-app-guid"
	appToStop.State = "started"
	expectedStoppedApp := cf.Application{}
	expectedStoppedApp.Name = "my-stopped-app"
	expectedStoppedApp.Guid = "my-stopped-app-guid"
	expectedStoppedApp.State = "stopped"

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

	assert.NoError(t, err)
	assert.Equal(t, expectedStoppedApp, actualStoppedApp)
}
Esempio n. 14
0
func TestRestartApplication(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	reqFactory := &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: true}
	starter := &testcmd.FakeAppStarter{}
	stopper := &testcmd.FakeAppStopper{}
	callRestart([]string{"my-app"}, reqFactory, starter, stopper)

	assert.Equal(t, stopper.AppToStop, app)
	assert.Equal(t, starter.AppToStart, app)
}
Esempio n. 15
0
func TestStopCommandFailsWithUsage(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	appRepo := &testapi.FakeApplicationRepository{ReadApp: app}
	reqFactory := &testreq.FakeReqFactory{Application: app}

	ui := callStop(t, []string{}, reqFactory, appRepo)
	assert.True(t, ui.FailedWithUsage)

	ui = callStop(t, []string{"my-app"}, reqFactory, appRepo)
	assert.False(t, ui.FailedWithUsage)
}
Esempio n. 16
0
func TestApplicationStopReturnsUpdatedAppWhenAppIsAlreadyStopped(t *testing.T) {
	appToStop := cf.Application{}
	appToStop.Name = "my-app"
	appToStop.Guid = "my-app-guid"
	appToStop.State = "stopped"
	appRepo := &testapi.FakeApplicationRepository{}
	config := &configuration.Configuration{}
	stopper := NewStop(new(testterm.FakeUI), config, appRepo)
	updatedApp, err := stopper.ApplicationStop(appToStop)

	assert.NoError(t, err)
	assert.Equal(t, appToStop, updatedApp)
}
Esempio n. 17
0
func TestEventsWhenNoEventsAvailable(t *testing.T) {
	reqFactory, eventsRepo := getEventsDependencies()
	app := cf.Application{}
	app.Name = "my-app"
	reqFactory.Application = app

	ui := callEvents(t, []string{"my-app"}, reqFactory, eventsRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"events", "my-app"},
		{"No events", "my-app"},
	})
}
Esempio n. 18
0
func testDisplayingAppSummaryWithErrorCode(t *testing.T, errorCode string) {
	reqApp := cf.Application{}
	reqApp.Name = "my-app"
	reqApp.Guid = "my-app-guid"

	domain3 := cf.DomainFields{}
	domain3.Name = "example.com"
	domain4 := cf.DomainFields{}
	domain4.Name = "example.com"

	route1 := cf.RouteSummary{}
	route1.Host = "my-app"
	route1.Domain = domain3

	route2 := cf.RouteSummary{}
	route2.Host = "foo"
	route2.Domain = domain4

	routes := []cf.RouteSummary{
		route1,
		route2,
	}

	app := cf.ApplicationFields{}
	app.State = "stopped"
	app.InstanceCount = 2
	app.RunningInstances = 0
	app.Memory = 256

	appSummary := cf.AppSummary{}
	appSummary.ApplicationFields = app
	appSummary.RouteSummaries = routes

	appSummaryRepo := &testapi.FakeAppSummaryRepo{GetSummarySummary: appSummary, GetSummaryErrorCode: errorCode}
	appInstancesRepo := &testapi.FakeAppInstancesRepo{}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: reqApp}
	ui := callApp(t, []string{"my-app"}, reqFactory, appSummaryRepo, appInstancesRepo)

	assert.Equal(t, appSummaryRepo.GetSummaryAppGuid, "my-app-guid")
	assert.Equal(t, appInstancesRepo.GetInstancesAppGuid, "my-app-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Showing health and status", "my-app", "my-org", "my-space", "my-user"},
		{"state", "stopped"},
		{"instances", "0/2"},
		{"usage", "256M x 2 instances"},
		{"urls", "my-app.example.com, foo.example.com"},
		{"no running instances"},
	})
}
Esempio n. 19
0
func TestListingFilesWithTemplateTokens(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-found-app"
	app.Guid = "my-app-guid"

	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: app}
	appFilesRepo := &testapi.FakeAppFilesRepo{FileList: "%s %d %i"}

	ui := callFiles(t, []string{"my-app", "/foo"}, reqFactory, appFilesRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"%s %d %i"},
	})
}
Esempio n. 20
0
func TestApplicationReqExecute(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	appRepo := &testapi.FakeApplicationRepository{ReadApp: app}
	ui := new(testterm.FakeUI)

	appReq := newApplicationRequirement("foo", ui, appRepo)
	success := appReq.Execute()

	assert.True(t, success)
	assert.Equal(t, appRepo.ReadName, "foo")
	assert.Equal(t, appReq.GetApplication(), app)
}
Esempio n. 21
0
func TestScaleOnlyMemory(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	reqFactory, restarter, appRepo := getScaleDependencies()
	reqFactory.Application = app

	callScale(t, []string{"-m", "512M", "my-app"}, reqFactory, restarter, appRepo)

	assert.Equal(t, appRepo.UpdateAppGuid, "my-app-guid")
	assert.Equal(t, appRepo.UpdateParams.Get("memory").(uint64), uint64(512))

	assert.False(t, appRepo.UpdateParams.Has("disk_quota"))
	assert.False(t, appRepo.UpdateParams.Has("instances"))
}
Esempio n. 22
0
func TestCreateApplication(t *testing.T) {
	ts, handler, repo := createAppRepo(t, []testnet.TestRequest{createApplicationRequest})
	defer ts.Close()

	params := defaultAppParams()
	createdApp, apiResponse := repo.Create(params)

	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())

	app := cf.Application{}
	app.Name = "my-cool-app"
	app.Guid = "my-cool-app-guid"
	assert.Equal(t, createdApp, app)
}
Esempio n. 23
0
func TestStopApplicationIsAlreadyStopped(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	app.State = "stopped"
	appRepo := &testapi.FakeApplicationRepository{ReadApp: app}
	args := []string{"my-app"}
	reqFactory := &testreq.FakeReqFactory{Application: app}
	ui := callStop(t, args, reqFactory, appRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"my-app", "is already stopped"},
	})
	assert.Equal(t, appRepo.UpdateAppGuid, "")
}
Esempio n. 24
0
func TestRenameRun(t *testing.T) {
	appRepo := &testapi.FakeApplicationRepository{}
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Application: app}
	ui := callRename(t, []string{"my-app", "my-new-app"}, reqFactory, appRepo)

	assert.Equal(t, appRepo.UpdateAppGuid, app.Guid)
	assert.Equal(t, appRepo.UpdateParams.Get("name"), "my-new-app")
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Renaming app", "my-app", "my-new-app", "my-org", "my-space", "my-user"},
		{"OK"},
	})
}
Esempio n. 25
0
func TestStopApplicationWhenStopFails(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	appRepo := &testapi.FakeApplicationRepository{ReadApp: app, UpdateErr: true}
	args := []string{"my-app"}
	reqFactory := &testreq.FakeReqFactory{Application: app}
	ui := callStop(t, args, reqFactory, appRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Stopping", "my-app"},
		{"FAILED"},
		{"Error updating app."},
	})
	assert.Equal(t, appRepo.UpdateAppGuid, "my-app-guid")
}
Esempio n. 26
0
func TestStopApplication(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	appRepo := &testapi.FakeApplicationRepository{ReadApp: app}
	args := []string{"my-app"}
	reqFactory := &testreq.FakeReqFactory{Application: app}
	ui := callStop(t, args, reqFactory, appRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Stopping app", "my-app", "my-org", "my-space", "my-user"},
		{"OK"},
	})

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, appRepo.UpdateAppGuid, "my-app-guid")
}
Esempio n. 27
0
func TestUnsetEnvWhenEnvVarDoesNotExist(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	reqFactory := &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: true}
	appRepo := &testapi.FakeApplicationRepository{}

	args := []string{"my-app", "DATABASE_URL"}
	ui := callUnsetEnv(t, args, reqFactory, appRepo)

	assert.Equal(t, len(ui.Outputs), 3)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Removing env variable"},
		{"OK"},
		{"DATABASE_URL", "was not set."},
	})
}
Esempio n. 28
0
func TestScaleAll(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	reqFactory, restarter, appRepo := getScaleDependencies()
	reqFactory.Application = app

	ui := callScale(t, []string{"-i", "5", "-m", "512M", "my-app"}, reqFactory, restarter, appRepo)

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

	assert.Equal(t, appRepo.UpdateAppGuid, "my-app-guid")
	assert.Equal(t, appRepo.UpdateParams.Get("memory"), uint64(512))
	assert.Equal(t, appRepo.UpdateParams.Get("instances"), 5)
}
Esempio n. 29
0
func TestPushingAppToResetStartCommand(t *testing.T) {
	deps := getPushDependencies()

	existingApp := cf.Application{}
	existingApp.Name = "existing-app"
	existingApp.Guid = "existing-app-guid"
	existingApp.Command = "unicorn -c config/unicorn.rb -D"

	deps.appRepo.ReadApp = existingApp

	args := []string{
		"-c", "null",
		"existing-app",
	}
	_ = callPush(t, args, deps)

	assert.Equal(t, deps.appRepo.UpdateParams.Get("command"), "")
}
Esempio n. 30
0
func TestMapRouteWhenRouteNotReserved(t *testing.T) {
	domain := cf.DomainFields{}
	domain.Name = "my-domain.com"
	route := cf.Route{}
	route.Guid = "my-app-guid"
	route.Host = "my-host"
	route.Domain = domain
	app := cf.Application{}
	app.Guid = "my-app-guid"
	app.Name = "my-app"

	routeRepo := &testapi.FakeRouteRepository{}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Application: app}
	routeCreator := &testcmd.FakeRouteCreator{ReservedRoute: route}

	callMapRoute(t, []string{"-n", "my-host", "my-app", "my-domain.com"}, reqFactory, routeRepo, routeCreator)

	assert.Equal(t, routeCreator.ReservedRoute, route)
}