Пример #1
0
func makeAppWithOptions(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"
	application.Command = "run main.go"
	application.BuildpackUrl = "go-buildpack"

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

	route := models.RouteSummary{Host: "foo", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}
	packgeUpdatedAt, _ := time.Parse("2006-01-02T15:04:05Z07:00", "2012-10-24T19:54:00Z")

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.HealthCheckTimeout = 100
	application.Routes = []models.RouteSummary{route, secondRoute}
	application.PackageUpdatedAt = &packgeUpdatedAt

	envMap := make(map[string]interface{})
	envMap["foo"] = "bar"
	application.EnvironmentVars = envMap

	application.Services = append(application.Services, models.ServicePlanSummary{
		Guid: "",
		Name: "server1",
	})

	return application
}
Пример #2
0
func makeAppWithRoute(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"

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

	route := models.RouteSummary{Host: "foo", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}
	packgeUpdatedAt, _ := time.Parse("2006-01-02T15:04:05Z07:00", "2012-10-24T19:54:00Z")

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.Stack = &models.Stack{
		Name: "fake_stack",
		Guid: "123-123-123",
	}
	application.Routes = []models.RouteSummary{route, secondRoute}
	application.PackageUpdatedAt = &packgeUpdatedAt

	return application
}
Пример #3
0
func makeAppWithoutOptions(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"
	packgeUpdatedAt, _ := time.Parse("2006-01-02T15:04:05Z07:00", "2012-10-24T19:54:00Z")

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.PackageUpdatedAt = &packgeUpdatedAt

	return application
}
Пример #4
0
func makeAppWithRoute(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"
	application.BuildpackUrl = "http://123.com"
	application.Command = "command1"
	application.Diego = false
	application.DetectedStartCommand = "detected_command"
	application.DiskQuota = 100
	application.EnvironmentVars = map[string]interface{}{"test": 123}
	application.RunningInstances = 2
	application.HealthCheckTimeout = 100
	application.SpaceGuid = "guids_in_spaaace"
	application.PackageState = "STAGED"
	application.StagingFailedReason = "no reason"
	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256

	t := time.Date(2009, time.November, 10, 15, 0, 0, 0, time.UTC)
	application.PackageUpdatedAt = &t

	services := models.ServicePlanSummary{
		Guid: "s1-guid",
		Name: "s1-service",
	}

	application.Services = []models.ServicePlanSummary{services}

	domain := models.DomainFields{Guid: "domain1-guid", Name: "example.com", OwningOrganizationGuid: "org-123", Shared: true}

	route := models.RouteSummary{Host: "foo", Guid: "foo-guid", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}

	application.Stack = &models.Stack{
		Name: "fake_stack",
		Guid: "123-123-123",
	}
	application.Routes = []models.RouteSummary{route, secondRoute}

	return application
}
Пример #5
0
func makeAppWithRoute(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"

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

	route := models.RouteSummary{Host: "foo", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.Routes = []models.RouteSummary{route, secondRoute}

	return application
}
Пример #6
0
func makeAppWithMultipleEnvVars(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"
	packgeUpdatedAt, _ := time.Parse("2006-01-02T15:04:05Z07:00", "2012-10-24T19:54:00Z")

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.PackageUpdatedAt = &packgeUpdatedAt

	envMap := make(map[string]interface{})
	envMap["foo"] = bool(true)
	envMap["abc"] = "abc"
	envMap["xyz"] = bool(false)
	envMap["bar"] = float64(10)
	application.EnvironmentVars = envMap

	return application
}
Пример #7
0
)

var _ = Describe("delete app command", func() {
	var (
		cmd                 *DeleteApp
		ui                  *testterm.FakeUI
		app                 models.Application
		configRepo          configuration.ReadWriter
		appRepo             *testapi.FakeApplicationRepository
		routeRepo           *testapi.FakeRouteRepository
		requirementsFactory *testreq.FakeReqFactory
	)

	BeforeEach(func() {
		app = models.Application{}
		app.Name = "app-to-delete"
		app.Guid = "app-to-delete-guid"

		ui = &testterm.FakeUI{}
		appRepo = &testapi.FakeApplicationRepository{}
		routeRepo = &testapi.FakeRouteRepository{}
		requirementsFactory = &testreq.FakeReqFactory{}

		configRepo = testconfig.NewRepositoryWithDefaults()
		cmd = NewDeleteApp(ui, configRepo, appRepo, routeRepo)
	})

	runCommand := func(args ...string) {
		testcmd.RunCommand(cmd, args, requirementsFactory)
	}
Пример #8
0
				updateCommandDependency(false)
			})

			It("should output whatever greg sez", func() {
				runCommand("my-app")
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"last uploaded", "unknown"},
				))
			})
		})
	})

	Describe("when the app is not running", func() {
		BeforeEach(func() {
			application := models.Application{}
			application.Name = "my-app"
			application.Guid = "my-app-guid"
			application.State = "stopped"
			application.InstanceCount = 2
			application.RunningInstances = 0
			application.Memory = 256
			now := time.Now()
			application.PackageUpdatedAt = &now

			appSummaryRepo.GetSummarySummary = application
			requirementsFactory.Application = application

			updateCommandDependency(false)
		})

		It("displays nice output when the app is stopped", func() {
Пример #9
0
	It("fails with usage when called without an app name", func() {
		passed := runCommand()
		Expect(ui.FailedWithUsage).To(BeTrue())
		Expect(passed).To(BeFalse())
	})

	It("lists events given an app name", func() {
		earlierTimestamp, err := time.Parse(TIMESTAMP_FORMAT, "1999-12-31T23:59:11.00-0000")
		Expect(err).NotTo(HaveOccurred())

		timestamp, err := time.Parse(TIMESTAMP_FORMAT, "2000-01-01T00:01:11.00-0000")
		Expect(err).NotTo(HaveOccurred())

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

		eventsRepo.RecentEventsReturns([]models.EventFields{
			{
				Guid:        "event-guid-1",
				Name:        "app crashed",
				Timestamp:   earlierTimestamp,
				Description: "reason: app instance exited, exit_status: 78",
				ActorName:   "George Clooney",
			},
			{
				Guid:        "event-guid-2",
				Name:        "app crashed",
				Timestamp:   timestamp,
Пример #10
0
				})
			})
		})

	})

	Describe("ssh", func() {
		var (
			currentApp models.Application
		)

		BeforeEach(func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
			requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{})
			currentApp = models.Application{}
			currentApp.Name = "my-app"
			currentApp.State = "started"
			currentApp.GUID = "my-app-guid"
			currentApp.EnableSSH = true
			currentApp.Diego = true

			applicationReq := new(requirementsfakes.FakeApplicationRequirement)
			applicationReq.GetApplicationReturns(currentApp)
			requirementsFactory.NewApplicationRequirementReturns(applicationReq)
		})

		Describe("Error getting required info to run ssh", func() {
			var (
				testServer *httptest.Server
				handler    *testnet.TestHandler
			)
Пример #11
0
		})
	})

	Describe("creating applications", func() {
		It("makes the right request", func() {
			ts, handler, repo := createAppRepo([]testnet.TestRequest{createApplicationRequest})
			defer ts.Close()

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

			Expect(handler).To(HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())

			app := models.Application{}
			app.Name = "my-cool-app"
			app.Guid = "my-cool-app-guid"
			Expect(createdApp).To(Equal(app))
		})

		It("omits fields that are not set", func() {
			request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
				Method:   "POST",
				Path:     "/v2/apps",
				Matcher:  testnet.RequestBodyMatcher(`{"name":"my-cool-app","instances":3,"memory":2048,"disk_quota":512,"space_guid":"some-space-guid"}`),
				Response: testnet.TestResponse{Status: http.StatusCreated, Body: createApplicationResponse},
			})

			ts, handler, repo := createAppRepo([]testnet.TestRequest{request})
			defer ts.Close()
Пример #12
0
		requirementsFactory = &testreq.FakeReqFactory{}

		configRepo = testconfig.NewRepository()

		appInstancesRepo = &testAppInstanaces.FakeAppInstancesRepository{}
		appRepo = &testApplication.FakeApplicationRepository{}

		displayApp = &appCmdFakes.FakeAppDisplayer{}

		//save original command dependency and restore later
		OriginalAppCommand = command_registry.Commands.FindCommand("app")

		defaultInstanceErrorCodes = []string{"", ""}

		defaultAppForStart = models.Application{}
		defaultAppForStart.Name = "my-app"
		defaultAppForStart.Guid = "my-app-guid"
		defaultAppForStart.InstanceCount = 2
		defaultAppForStart.PackageState = "STAGED"

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

		route := models.RouteSummary{}
		route.Host = "my-app"
		route.Domain = domain

		defaultAppForStart.Routes = []models.RouteSummary{route}

		instance1 := models.AppInstanceFields{}
		instance1.State = models.InstanceStarting
Пример #13
0
			},
			{
				Host: "app1",
				Domain: models.DomainFields{
					Name: "example.com",
				},
			}}

		app2Routes := []models.RouteSummary{
			{
				Host:   "app2",
				Domain: models.DomainFields{Name: "cfapps.io"},
			}}

		app := models.Application{}
		app.Name = "Application-1"
		app.GUID = "Application-1-guid"
		app.State = "started"
		app.RunningInstances = 1
		app.InstanceCount = 1
		app.Memory = 512
		app.DiskQuota = 1024
		app.Routes = app1Routes
		app.AppPorts = []int{8080, 9090}

		app2 := models.Application{}
		app2.Name = "Application-2"
		app2.GUID = "Application-2-guid"
		app2.State = "started"
		app2.RunningInstances = 1
		app2.InstanceCount = 2
Пример #14
0
		})
	})

	Describe("Execute", func() {
		var (
			application models.Application
			runCLIErr   error
		)

		BeforeEach(func() {
			err := flagContext.Parse("app-name")
			Expect(err).NotTo(HaveOccurred())
			cmd.Requirements(factory, flagContext)

			application = models.Application{}
			application.Name = "app-name"
		})

		JustBeforeEach(func() {
			runCLIErr = cmd.Execute(flagContext)
		})

		AfterEach(func() {
			os.Remove("app-name_manifest.yml")
		})

		Context("when there is an app summary", func() {
			BeforeEach(func() {
				appSummaryRepo.GetSummaryReturns(application, nil)
			})
Пример #15
0
				It("fails when given the name of an app that is not in the manifest", func() {
					callPush("non-existant-app")

					Expect(ui.Outputs).To(ContainSubstrings([]string{"FAILED"}))
					Expect(len(appRepo.CreateAppParams)).To(Equal(0))
				})
			})
		})
	})

	Describe("re-pushing an existing app", func() {
		var existingApp models.Application

		BeforeEach(func() {
			existingApp = models.Application{}
			existingApp.Name = "existing-app"
			existingApp.Guid = "existing-app-guid"
			existingApp.Command = "unicorn -c config/unicorn.rb -D"
			existingApp.EnvironmentVars = map[string]string{
				"crazy": "pants",
				"FOO":   "NotYoBaz",
				"foo":   "manchu",
			}

			appRepo.ReadReturns.App = existingApp
			appRepo.UpdateAppResult = existingApp
		})

		It("resets the app's buildpack when the -b flag is provided as 'default'", func() {
			callPush("-b", "default", "existing-app")
			Expect(*appRepo.UpdateParams.BuildpackUrl).To(Equal(""))
Пример #16
0
		// yes, we're aware that the args here should probably be provided in a different order
		// erg: app-name -p some/path some-extra-arg
		// but the test infrastructure for parsing args and flags is sorely lacking
		It("fails when provided too many args", func() {
			Expect(callPush("-p", "path", "too-much", "app-name")).To(BeFalse())
		})
	})

	Describe("when pushing a new app", func() {
		BeforeEach(func() {
			appRepo.ReadReturns(models.Application{}, errors.NewModelNotFoundError("App", "the-app"))
			appRepo.CreateStub = func(params models.AppParams) (models.Application, error) {
				a := models.Application{}
				a.Guid = *params.Name + "-guid"
				a.Name = *params.Name
				a.State = "stopped"

				return a, nil
			}

			zipper.ZipReturns(nil)
			zipper.GetZipSizeReturns(9001, nil)
			actor.GatherFilesReturns(nil, true, nil)
			actor.UploadAppReturns(nil)
		})

		Context("when the default route for the app already exists", func() {
			BeforeEach(func() {
				route := models.Route{}
				route.Guid = "my-route-guid"
Пример #17
0
		flagContext = flags.NewFlagContext(cmd.MetaData().Flags)

		factory = new(requirementsfakes.FakeFactory)

		loginRequirement = &passingRequirement{Name: "login-requirement"}
		factory.NewLoginRequirementReturns(loginRequirement)

		targetedSpaceRequirement = &passingRequirement{}
		factory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement)

		deaApplicationRequirement = new(requirementsfakes.FakeDEAApplicationRequirement)
		factory.NewDEAApplicationRequirementReturns(deaApplicationRequirement)
		app := models.Application{}
		app.InstanceCount = 1
		app.GUID = "app-guid"
		app.Name = "app-name"
		deaApplicationRequirement.GetApplicationReturns(app)
	})

	Describe("Requirements", func() {
		Context("when not provided one or two args", func() {
			BeforeEach(func() {
				flagContext.Parse("app-name", "the-path", "extra-arg")
			})

			It("fails with usage", func() {
				Expect(func() { cmd.Requirements(factory, flagContext) }).To(Panic())
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"FAILED"},
					[]string{"Incorrect Usage. Requires an argument"},
				))
Пример #18
0
		requirementsFactory.LoginSuccess = false
		appRepo := &testapi.FakeApplicationRepository{}
		cmd := NewStop(new(testterm.FakeUI), testconfig.NewRepository(), appRepo)
		testcmd.RunCommand(cmd, []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{}
			appRepo.ReadReturns.App = app

			ui := callStop([]string{}, requirementsFactory, appRepo)
			Expect(ui.FailedWithUsage).To(BeTrue())
		})

		It("stops the app with the given name", func() {
			app := models.Application{}
			app.Name = "my-app"
			app.Guid = "my-app-guid"
			appRepo := &testapi.FakeApplicationRepository{}
			appRepo.ReadReturns.App = app
			args := []string{"my-app"}
Пример #19
0
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
		Expect(requirementsFactory.ApplicationName).To(Equal("my-app"))
	})
	It("TestFilesFailsWithUsage", func() {

		appFilesRepo := &testapi.FakeAppFilesRepo{}
		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: models.Application{}}
		ui := callFiles([]string{}, requirementsFactory, appFilesRepo)

		Expect(ui.FailedWithUsage).To(BeTrue())
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})
	It("TestListingDirectoryEntries", func() {

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

		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: app}
		appFilesRepo := &testapi.FakeAppFilesRepo{FileList: "file 1\nfile 2"}

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

		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"Getting files for app", "my-found-app", "my-org", "my-space", "my-user"},
			[]string{"OK"},
			[]string{"file 1"},
			[]string{"file 2"},
		))

		Expect(appFilesRepo.AppGuid).To(Equal("my-app-guid"))