Exemplo n.º 1
0
	}

	BeforeEach(func() {
		ui = &testterm.FakeUI{}
		deps = commandregistry.NewDependency(os.Stdout, new(tracefakes.FakePrinter), "")
		requirementsFactory = new(requirementsfakes.FakeFactory)
		starter = new(applicationfakes.FakeStarter)
		stopper = new(applicationfakes.FakeStopper)
		config = testconfig.NewRepositoryWithDefaults()

		app = models.Application{}
		app.Name = "my-app"
		app.GUID = "my-app-guid"

		applicationReq = new(requirementsfakes.FakeApplicationRequirement)
		applicationReq.GetApplicationReturns(app)

		//save original command and restore later
		originalStart = commandregistry.Commands.FindCommand("start")
		originalStop = commandregistry.Commands.FindCommand("stop")

		//setup fakes to correctly interact with commandregistry
		starter.SetDependencyStub = func(_ commandregistry.Dependency, _ bool) commandregistry.Command {
			return starter
		}
		starter.MetaDataReturns(commandregistry.CommandMetadata{Name: "start"})

		stopper.SetDependencyStub = func(_ commandregistry.Dependency, _ bool) commandregistry.Command {
			return stopper
		}
		stopper.MetaDataReturns(commandregistry.CommandMetadata{Name: "stop"})
Exemplo n.º 2
0
		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
			)

			AfterEach(func() {
				testServer.Close()
			})

			Context("error when getting SSH info from /v2/info", func() {
				BeforeEach(func() {
Exemplo n.º 3
0
			})

			It("returns a ApplicationRequirement", func() {
				Expect(reqFactory.NewApplicationRequirementCallCount()).To(Equal(1))
				Expect(actualRequirements).To(ContainElement(applicationRequirement))
			})
		})
	})

	Describe("Execute", func() {
		var executeCmdErr error

		BeforeEach(func() {
			applicationRequirement.GetApplicationReturns(models.Application{
				ApplicationFields: models.ApplicationFields{
					Name: "my-app",
					GUID: "my-app-guid",
				},
			})

			err := flagContext.Parse("my-app")
			Expect(err).NotTo(HaveOccurred())
		})

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

		Context("when no events exist", func() {
			BeforeEach(func() {
				eventsRepo.RecentEventsReturns([]models.EventFields{}, nil)
Exemplo n.º 4
0
		cmd = &route.UnmapRoute{}
		cmd.SetDependency(deps, false)

		flagContext = flags.NewFlagContext(cmd.MetaData().Flags)

		factory = new(requirementsfakes.FakeFactory)

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

		applicationRequirement = new(requirementsfakes.FakeApplicationRequirement)
		factory.NewApplicationRequirementReturns(applicationRequirement)

		fakeApplication := models.Application{}
		fakeApplication.GUID = "fake-app-guid"
		applicationRequirement.GetApplicationReturns(fakeApplication)

		domainRequirement = new(requirementsfakes.FakeDomainRequirement)
		factory.NewDomainRequirementReturns(domainRequirement)

		fakeDomain = models.DomainFields{
			GUID: "fake-domain-guid",
			Name: "fake-domain-name",
		}
		domainRequirement.GetDomainReturns(fakeDomain)

		minAPIVersionRequirement = &passingRequirement{Name: "min-api-version-requirement"}
		factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement)
	})

	Describe("Help text", func() {
Exemplo n.º 5
0
					Details:   "fake-instance-details",
					Since:     time.Date(2015, time.November, 19, 1, 1, 17, 0, time.UTC),
					CPUUsage:  float64(0.25),
					DiskUsage: int64(1 * formatters.GIGABYTE),
					DiskQuota: int64(2 * formatters.GIGABYTE),
					MemUsage:  int64(24 * formatters.MEGABYTE),
					MemQuota:  int64(32 * formatters.MEGABYTE),
				},
			}

			appStackModel = models.Stack{
				GUID: "fake-stack-guid",
				Name: "fake-stack-name",
			}

			applicationRequirement.GetApplicationReturns(getApplicationModel)
			appSummaryRepo.GetSummaryReturns(getAppSummaryModel, getAppSummaryErr)
			appInstancesRepo.GetInstancesReturns(appInstanceFields, nil)
			stackRepo.FindByGUIDReturns(appStackModel, nil)
		})

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

		It("gets the application summary", func() {
			Expect(err).NotTo(HaveOccurred())
			Expect(appSummaryRepo.GetSummaryCallCount()).To(Equal(1))
		})

		It("gets the app instances", func() {
Exemplo n.º 6
0
		cmd.PingerThrottle = 10 * time.Millisecond
		commandregistry.Register(cmd)

		return testcmd.RunCLICommandWithoutDependency("start", args, requirementsFactory, ui)
	}

	startAppWithInstancesAndErrors := func(app models.Application, requirementsFactory *requirementsfakes.FakeFactory) (*testterm.FakeUI, *applicationsfakes.FakeRepository, *appinstancesfakes.FakeAppInstancesRepository) {
		appRepo.UpdateReturns(app, nil)
		appRepo.ReadReturns(app, nil)
		appRepo.GetAppReturns(app, nil)
		appInstancesRepo.GetInstancesStub = getInstance

		args := []string{"my-app"}

		applicationReq := new(requirementsfakes.FakeApplicationRequirement)
		applicationReq.GetApplicationReturns(app)
		requirementsFactory.NewApplicationRequirementReturns(applicationReq)
		callStart(args)
		return ui, appRepo, appInstancesRepo
	}

	It("fails requirements when not logged in", func() {
		requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})

		Expect(callStart([]string{"some-app-name"})).To(BeFalse())
	})

	It("fails requirements when a space is not targeted", func() {
		requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
		requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"})