Example #1
0
func TestPushingAppWhenItAlreadyExistsWithoutARouteCreatesADefaultDomain(t *testing.T) {
	deps := getPushDependencies()

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

	deps.routeRepo.FindByHostAndDomainErr = true
	deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{sharedDomain}
	deps.appRepo.ReadApp = maker.NewApp(maker.Overrides{"name": "existing-app", "guid": "existing-app-guid"})
	deps.appRepo.UpdateAppResult = deps.appRepo.ReadApp

	ui := callPush(t, []string{"-t", "111", "existing-app"}, deps)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating route", "existing-app.foo.cf-app.com"},
		{"OK"},
		{"Binding", "existing-app.foo.cf-app.com"},
		{"OK"},
		{"Uploading"},
		{"OK"},
	})

	assert.Equal(t, deps.routeRepo.FindByHostAndDomainDomain, "foo.cf-app.com")
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "existing-app")

	assert.Equal(t, deps.routeRepo.CreatedHost, "existing-app")
	assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "foo-domain-guid")

	assert.Equal(t, deps.routeRepo.BoundAppGuid, "existing-app-guid")
	assert.Equal(t, deps.routeRepo.BoundRouteGuid, "existing-app-route-guid")
}
Example #2
0
func TestPushingAppWhenItIsStopped(t *testing.T) {
	deps := getPushDependencies()
	stoppedApp := maker.NewApp(maker.Overrides{"state": "stopped", "name": "stopped-app"})

	deps.appRepo.ReadApp = stoppedApp
	deps.appRepo.UpdateAppResult = stoppedApp

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

	assert.Equal(t, deps.stopper.AppToStop.Guid, "")
}
Example #3
0
func TestPushingAppWhenItAlreadyExistsAndNothingIsSpecified(t *testing.T) {
	deps := getPushDependencies()
	existingApp := maker.NewApp(maker.Overrides{"name": "existing-app"})
	deps.appRepo.ReadApp = existingApp
	deps.appRepo.UpdateAppResult = existingApp

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

	assert.Equal(t, deps.stopper.AppToStop.Guid, existingApp.Guid)
	assert.Equal(t, deps.appBitsRepo.UploadedAppGuid, existingApp.Guid)
}
Example #4
0
func TestScaleOnlyMemory(t *testing.T) {
	app := maker.NewApp(maker.Overrides{"name": "my-app", "guid": "my-app-guid"})
	deps := getScaleDependencies()
	deps.reqFactory.Application = app
	deps.appRepo.UpdateAppResult = app

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

	assert.Equal(t, deps.restarter.AppToRestart.Guid, "my-app-guid")
	assert.Equal(t, deps.appRepo.UpdateAppGuid, "my-app-guid")
	assert.Equal(t, deps.appRepo.UpdateParams.Get("memory").(uint64), uint64(512))
	assert.False(t, deps.appRepo.UpdateParams.Has("disk_quota"))
	assert.False(t, deps.appRepo.UpdateParams.Has("instances"))
}
Example #5
0
func TestScaleAll(t *testing.T) {
	app := maker.NewApp(maker.Overrides{"name": "my-app", "guid": "my-app-guid"})
	deps := getScaleDependencies()
	deps.reqFactory.Application = app
	deps.appRepo.UpdateAppResult = app

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

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

	assert.Equal(t, deps.restarter.AppToRestart.Guid, "my-app-guid")
	assert.Equal(t, deps.appRepo.UpdateAppGuid, "my-app-guid")
	assert.Equal(t, deps.appRepo.UpdateParams.Get("memory"), uint64(512))
	assert.Equal(t, deps.appRepo.UpdateParams.Get("instances"), 5)
}
Example #6
0
	It("resets the app's command when the -c flag is provided as 'null'", func() {
		existingApp := models.Application{}
		existingApp.Name = "existing-app"
		existingApp.Guid = "existing-app-guid"
		existingApp.Command = "unicorn -c config/unicorn.rb -D"

		appRepo.ReadApp = existingApp

		callPush("-c", "null", "existing-app")

		Expect(*appRepo.UpdateParams.Command).To(Equal(""))
	})

	It("merges env vars from the manifest with those from the server", func() {
		existingApp := maker.NewApp(maker.Overrides{"name": "existing-app"})
		existingApp.EnvironmentVars = map[string]string{
			"crazy": "pants",
			"FOO":   "NotYoBaz",
			"foo":   "manchu",
		}
		appRepo.ReadApp = existingApp

		manifestRepo.ReadManifestReturns.Manifest = singleAppManifest()

		callPush("existing-app")

		updatedAppEnvVars := *appRepo.UpdateParams.EnvironmentVars
		Expect(updatedAppEnvVars["crazy"]).To(Equal("pants"))
		Expect(updatedAppEnvVars["FOO"]).To(Equal("baz"))
		Expect(updatedAppEnvVars["foo"]).To(Equal("manchu"))
Example #7
0
		deps.appRepo.ReadApp = existingApp

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

		Expect(*deps.appRepo.UpdateParams.Command).To(Equal(""))
	})

	It("TestPushingAppMergesManifestEnvVarsWithExistingEnvVars", func() {
		deps := getPushDependencies()

		existingApp := maker.NewApp(maker.Overrides{"name": "existing-app"})
		existingApp.EnvironmentVars = map[string]string{
			"crazy": "pants",
			"FOO":   "NotYoBaz",
			"foo":   "manchu",
		}
		deps.appRepo.ReadApp = existingApp

		deps.manifestRepo.ReadManifestReturns.Manifest = singleAppManifest()

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

		updatedAppEnvVars := *deps.appRepo.UpdateParams.EnvironmentVars
		Expect(updatedAppEnvVars["crazy"]).To(Equal("pants"))
		Expect(updatedAppEnvVars["FOO"]).To(Equal("baz"))
		Expect(updatedAppEnvVars["foo"]).To(Equal("manchu"))
Example #8
0
					{"OK"},
					{"Binding service", "global-service", "app1", "my-org", "my-space", "my-user"},
					{"OK"},
					{"Creating", "app2"},
					{"OK"},
					{"Binding service", "app2-service", "app2", "my-org", "my-space", "my-user"},
					{"OK"},
					{"Binding service", "global-service", "app2", "my-org", "my-space", "my-user"},
					{"OK"},
				})
			})
		})

		Context("when the app is already bound to the service", func() {
			BeforeEach(func() {
				appRepo.ReadReturns.App = maker.NewApp(maker.Overrides{})
				serviceBinder.BindApplicationReturns.Error = errors.NewHttpError(500, "90003", "it don't work")
			})

			It("gracefully continues", func() {
				callPush()
				Expect(len(serviceBinder.AppsToBind)).To(Equal(4))
				testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{{"FAILED"}})
			})
		})

		Context("when the service instance can't be found", func() {
			BeforeEach(func() {
				routeRepo.FindByHostAndDomainErr = true
				serviceRepo.FindInstanceByNameErr = true
				manifestRepo.ReadManifestReturns.Manifest = manifestWithServicesAndEnv()
Example #9
0
		Expect(ui.FailedWithUsage).To(BeTrue())
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})
	It("TestScaleFailsWithoutFlags", func() {

		args := []string{"my-app"}
		deps := getScaleDependencies()
		deps.reqFactory.LoginSuccess = true
		deps.reqFactory.TargetedSpaceSuccess = true

		callScale(args, deps)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})
	It("TestScaleAll", func() {

		app := maker.NewApp(maker.Overrides{"name": "my-app", "guid": "my-app-guid"})
		deps := getScaleDependencies()
		deps.reqFactory.Application = app
		deps.appRepo.UpdateAppResult = app

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

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

		Expect(deps.restarter.AppToRestart.Guid).To(Equal("my-app-guid"))
		Expect(deps.appRepo.UpdateAppGuid).To(Equal("my-app-guid"))
		Expect(*deps.appRepo.UpdateParams.Memory).To(Equal(uint64(512)))
		Expect(*deps.appRepo.UpdateParams.InstanceCount).To(Equal(5))