Ejemplo n.º 1
0
func testDisplayingAppSummaryWithErrorCode(errorCode string) {
	reqApp := models.Application{}
	reqApp.Name = "my-app"
	reqApp.Guid = "my-app-guid"

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

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

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

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

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

	appSummary := models.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([]string{"my-app"}, reqFactory, appSummaryRepo, appInstancesRepo)

	Expect(appSummaryRepo.GetSummaryAppGuid).To(Equal("my-app-guid"))
	Expect(appInstancesRepo.GetInstancesAppGuid).To(Equal("my-app-guid"))

	testassert.SliceContains(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"},
	})
}
Ejemplo n.º 2
0
func deleteApp(confirmation string, args []string) (ui *testterm.FakeUI, reqFactory *testreq.FakeReqFactory, appRepo *testapi.FakeApplicationRepository) {

	app := models.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},
	}

	configRepo := testconfig.NewRepositoryWithDefaults()

	ctxt := testcmd.NewContext("delete", args)
	cmd := NewDeleteApp(ui, configRepo, appRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Ejemplo n.º 3
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
}
Ejemplo n.º 4
0
	. "cf/commands/application"
	"cf/models"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testcmd "testhelpers/commands"
	testconfig "testhelpers/configuration"
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
)

var _ = Describe("Testing with ginkgo", func() {
	It("TestStopCommandFailsWithUsage", func() {
		app := models.Application{}
		app.Name = "my-app"
		app.Guid = "my-app-guid"
		appRepo := &testapi.FakeApplicationRepository{ReadApp: app}
		reqFactory := &testreq.FakeReqFactory{Application: app}

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

		ui = callStop([]string{"my-app"}, reqFactory, appRepo)
		Expect(ui.FailedWithUsage).To(BeFalse())
	})
	It("TestStopApplication", func() {

		app := models.Application{}
		app.Name = "my-app"
		app.Guid = "my-app-guid"
Ejemplo n.º 5
0
		route2.Host = "app1"
		route2.Domain = domain2

		app1Routes := []models.RouteSummary{route1, route2}

		domain3 := models.DomainFields{}
		domain3.Name = "cfapps.io"

		route3 := models.RouteSummary{}
		route3.Host = "app2"
		route3.Domain = domain3

		app2Routes := []models.RouteSummary{route3}

		app := models.Application{}
		app.Name = "Application-1"
		app.State = "started"
		app.RunningInstances = 1
		app.InstanceCount = 1
		app.Memory = 512
		app.DiskQuota = 1024
		app.Routes = app1Routes

		app2 := models.Application{}
		app2.Name = "Application-2"
		app2.State = "started"
		app2.RunningInstances = 1
		app2.InstanceCount = 2
		app2.Memory = 256
		app2.DiskQuota = 1024
		app2.Routes = app2Routes
Ejemplo n.º 6
0
		appRepo.ReadNotFound = true

		callPush(
			"-t", "FooeyTimeout",
			"my-new-app",
		)

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

	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",
Ejemplo n.º 7
0
	. "cf/commands/application"
	"cf/models"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testcmd "testhelpers/commands"
	testconfig "testhelpers/configuration"
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
)

var _ = Describe("set-env command", func() {
	It("TestSetEnvRequirements", func() {
		app := models.Application{}
		app.Name = "my-app"
		app.Guid = "my-app-guid"
		appRepo := &testapi.FakeApplicationRepository{}
		args := []string{"my-app", "DATABASE_URL", "mysql://example.com/my-db"}

		reqFactory := &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: true}
		callSetEnv(args, reqFactory, appRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		reqFactory = &testreq.FakeReqFactory{Application: app, LoginSuccess: false, TargetedSpaceSuccess: true}
		callSetEnv(args, reqFactory, appRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		testcmd.CommandDidPassRequirements = true

		reqFactory = &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: false}
Ejemplo n.º 8
0
	})

	It("TestSshFailsWithUsage", func() {

		appFilesRepo := &testapi.FakeAppSshRepo{}
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: models.Application{}}
		ui := callSsh([]string{}, reqFactory, appFilesRepo)

		Expect(ui.FailedWithUsage).To(BeTrue())
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	It("TestGettingSshDetails", func() {

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

		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: app}

		var sshInfo models.SshConnectionDetails
		sshInfo.Ip = "10.0.0.1"
		sshInfo.Port = 1234
		sshInfo.User = "******"
		sshInfo.SshKey = "fakekey"

		appSshRepo := &testapi.FakeAppSshRepo{SshDetails: sshInfo}

		ui := callSsh([]string{"my-app"}, reqFactory, appSshRepo)

		testassert.SliceContains(ui.Outputs, testassert.Lines{
Ejemplo n.º 9
0
	testconfig "testhelpers/configuration"
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
	"time"
)

var _ = Describe("Testing with ginkgo", func() {
	var (
		defaultAppForStart        = models.Application{}
		defaultInstanceReponses   = [][]models.AppInstanceFields{}
		defaultInstanceErrorCodes = []string{"", ""}
		defaultStartTimeout       = 50 * time.Millisecond
	)

	BeforeEach(func() {
		defaultAppForStart.Name = "my-app"
		defaultAppForStart.Guid = "my-app-guid"
		defaultAppForStart.InstanceCount = 2

		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
Ejemplo n.º 10
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, testcmd.NewContext("delete", args), requirementsFactory)
	}
Ejemplo n.º 11
0
func getEnvDependencies() (reqFactory *testreq.FakeReqFactory) {
	app := models.Application{}
	app.Name = "my-app"
	reqFactory = &testreq.FakeReqFactory{LoginSuccess: true, Application: app}
	return
}
Ejemplo n.º 12
0
		Expect(reqFactory.ApplicationName).To(Equal("my-app"))
	})

	It("requires an app name", func() {
		appSummaryRepo := &testapi.FakeAppSummaryRepo{}
		appInstancesRepo := &testapi.FakeAppInstancesRepo{}
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: models.Application{}}
		ui := callApp([]string{}, reqFactory, appSummaryRepo, appInstancesRepo)

		Expect(ui.FailedWithUsage).To(BeTrue())
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	It("displays a summary of the app", func() {
		reqApp := models.Application{}
		reqApp.Name = "my-app"
		reqApp.Guid = "my-app-guid"

		route1 := models.RouteSummary{}
		route1.Host = "my-app"

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

		route2 := models.RouteSummary{}
		route2.Host = "foo"
		domain2 := models.DomainFields{}
		domain2.Name = "example.com"
		route2.Domain = domain2
Ejemplo n.º 13
0
		Expect(handler.AllRequestsCalled()).To(BeTrue())
		Expect(apiResponse.IsNotSuccessful()).To(BeFalse())
	})

	It("TestCreateApplication", func() {
		ts, handler, repo := createAppRepo([]testnet.TestRequest{createApplicationRequest})
		defer ts.Close()

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

		Expect(handler.AllRequestsCalled()).To(BeTrue())
		Expect(apiResponse.IsSuccessful()).To(BeTrue())

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

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

		ts, handler, repo := createAppRepo([]testnet.TestRequest{request})
		defer ts.Close()
Ejemplo n.º 14
0
			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Showing health and status", "my-app"},
				{"state", "started"},
				{"instances", "2/2"},
				{"usage", "256M x 2 instances"},
				{"urls", "my-app.example.com", "foo.example.com"},
				{"#0", "running", "2012-01-02 03:04:05 PM", "100.0%", "13 of 64M", "32M of 1G"},
				{"#1", "down", "2012-04-01 03:04:05 PM", "0%", "0 of 0", "0 of 0"},
			})
		})
	})

	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

			appSummaryRepo.GetSummarySummary = application
			requirementsFactory.Application = application
		})

		It("displays nice output when the app is stopped", func() {
			appSummaryRepo.GetSummaryErrorCode = errors.APP_STOPPED
			runCommand("my-app")

			Expect(appSummaryRepo.GetSummaryAppGuid).To(Equal("my-app-guid"))