Exemple #1
0
func (cmd *CreateRoute) CreateRoute(hostName string, domain models.DomainFields, space models.SpaceFields) (route models.Route, apiErr cferrors.Error) {
	cmd.ui.Say("Creating route %s for org %s / space %s as %s...",
		terminal.EntityNameColor(domain.UrlForHost(hostName)),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	route, apiErr = cmd.routeRepo.CreateInSpace(hostName, domain.Guid, space.Guid)
	if apiErr != nil {
		var findApiResponse cferrors.Error
		route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain.Name)

		if findApiResponse != nil ||
			route.Space.Guid != space.Guid ||
			route.Domain.Guid != domain.Guid {
			return
		}

		apiErr = nil
		cmd.ui.Ok()
		cmd.ui.Warn("Route %s already exists", route.URL())
		return
	}

	cmd.ui.Ok()
	return
}
func fakeDomainRepo() *testapi.FakeDomainRepository {
	domain := models.DomainFields{}
	domain.Name = "foo.com"
	domain.Guid = "foo-guid"
	domain.Shared = true

	return &testapi.FakeDomainRepository{
		FindByNameInOrgDomain: domain,
	}
}
Exemple #3
0
func (resource RouteSummary) ToModel() (route models.RouteSummary) {
	domain := models.DomainFields{}
	domain.Guid = resource.Domain.Guid
	domain.Name = resource.Domain.Name
	domain.Shared = resource.Domain.OwningOrganizationGuid != ""

	route.Guid = resource.Guid
	route.Host = resource.Host
	route.Domain = domain
	return
}
Exemple #4
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"},
	})
}
Exemple #5
0
func (cmd *Push) route(hostName string, domain models.DomainFields) (route models.Route) {
	route, apiErr := cmd.routeRepo.FindByHostAndDomain(hostName, domain.Name)
	if apiErr != nil {
		cmd.ui.Say("Creating route %s...", terminal.EntityNameColor(domain.UrlForHost(hostName)))

		route, apiErr = cmd.routeRepo.Create(hostName, domain.Guid)
		if apiErr != nil {
			cmd.ui.Failed(apiErr.Error())
			return
		}

		cmd.ui.Ok()
		cmd.ui.Say("")
	} else {
		cmd.ui.Say("Using route %s", terminal.EntityNameColor(route.URL()))
	}

	return
}
Exemple #6
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
}
Exemple #7
0
func (cmd *Push) route(hostName string, domain models.DomainFields) (route models.Route) {
	route, apiResponse := cmd.routeRepo.FindByHostAndDomain(hostName, domain.Name)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Say("Creating route %s...", terminal.EntityNameColor(domain.UrlForHost(hostName)))

		route, apiResponse = cmd.routeRepo.Create(hostName, domain.Guid)
		if apiResponse.IsNotSuccessful() {
			cmd.ui.Failed(apiResponse.Message)
			return
		}

		cmd.ui.Ok()
		cmd.ui.Say("")
	} else {
		cmd.ui.Say("Using route %s", terminal.EntityNameColor(route.URL()))
	}

	return
}
Exemple #8
0
	It("TestListDomainsFailsWithUsage", func() {
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}
		domainRepo := &testapi.FakeDomainRepository{}

		ui := callListDomains([]string{"foo"}, reqFactory, domainRepo)
		Expect(ui.FailedWithUsage).To(BeTrue())
	})

	It("TestListDomains", func() {
		orgFields := models.OrganizationFields{}
		orgFields.Name = "my-org"
		orgFields.Guid = "my-org-guid"

		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, OrganizationFields: orgFields}
		domain1 := models.DomainFields{}
		domain1.Shared = true
		domain1.Name = "Domain1"

		domain2 := models.DomainFields{}
		domain2.Shared = false
		domain2.Name = "Domain2"

		domain3 := models.DomainFields{}
		domain3.Shared = false
		domain3.Name = "Domain3"

		domainRepo := &testapi.FakeDomainRepository{
			ListSharedDomainsDomains: []models.DomainFields{domain1},
			ListDomainsForOrgDomains: []models.DomainFields{domain2, domain3},
		}
Exemple #9
0
		args := []string{"my-org"}
		ui := callShowOrg(args, reqFactory)
		Expect(ui.FailedWithUsage).To(BeFalse())

		args = []string{}
		ui = callShowOrg(args, reqFactory)
		Expect(ui.FailedWithUsage).To(BeTrue())
	})
	It("TestRunWhenOrganizationExists", func() {

		developmentSpaceFields := models.SpaceFields{}
		developmentSpaceFields.Name = "development"
		stagingSpaceFields := models.SpaceFields{}
		stagingSpaceFields.Name = "staging"
		domainFields := models.DomainFields{}
		domainFields.Name = "cfapps.io"
		cfAppDomainFields := models.DomainFields{}
		cfAppDomainFields.Name = "cf-app.com"
		org := models.Organization{}
		org.Name = "my-org"
		org.Guid = "my-org-guid"
		org.QuotaDefinition = models.NewQuotaFields("cantina-quota", 512)
		org.Spaces = []models.SpaceFields{developmentSpaceFields, stagingSpaceFields}
		org.Domains = []models.DomainFields{domainFields, cfAppDomainFields}

		reqFactory := &testreq.FakeReqFactory{Organization: org, LoginSuccess: true}

		args := []string{"my-org"}
		ui := callShowOrg(args, reqFactory)
Exemple #10
0
import (
	. "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("list-apps command", func() {
	It("TestApps", func() {
		domain := models.DomainFields{}
		domain.Name = "cfapps.io"
		domain2 := models.DomainFields{}
		domain2.Name = "example.com"

		route1 := models.RouteSummary{}
		route1.Host = "app1"
		route1.Domain = domain

		route2 := models.RouteSummary{}
		route2.Host = "app1"
		route2.Domain = domain2

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

		domain3 := models.DomainFields{}
Exemple #11
0
		}
		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"))
		Expect(updatedAppEnvVars["PATH"]).To(Equal("/u/apps/my-app/bin"))
	})

	It("pushes an app when provided a manifest with one app defined", func() {
		domain := models.DomainFields{}
		domain.Name = "manifest-example.com"
		domain.Guid = "bar-domain-guid"
		domainRepo.FindByNameInOrgDomain = domain
		routeRepo.FindByHostAndDomainErr = true
		appRepo.ReadNotFound = true

		manifestRepo.ReadManifestReturns.Manifest = singleAppManifest()

		callPush()
		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating route", "manifest-host.manifest-example.com"},
			{"OK"},
			{"Binding", "manifest-host.manifest-example.com"},
			{"manifest-app-name"},
		})
Exemple #12
0
		reqFactory = &testreq.FakeReqFactory{LoginSuccess: false, TargetedSpaceSuccess: true}
		testcmd.RunCommand(cmd, ctxt, reqFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		testcmd.CommandDidPassRequirements = true

		reqFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: false}
		testcmd.RunCommand(cmd, ctxt, reqFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

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

		privateDomain := models.DomainFields{}
		privateDomain.Shared = false
		privateDomain.Name = "private.cf-app.com"
		privateDomain.Guid = "private-domain-guid"

		sharedDomain := models.DomainFields{}
		sharedDomain.Name = "shared.cf-app.com"
		sharedDomain.Shared = true
		sharedDomain.Guid = "shared-domain-guid"

		deps.domainRepo.ListSharedDomainsApiResponse = net.NewNotFoundApiResponse("whoopsie")
		deps.domainRepo.ListDomainsDomains = []models.DomainFields{privateDomain, sharedDomain}
		deps.routeRepo.FindByHostAndDomainErr = true
		deps.appRepo.ReadNotFound = true

		ui := callPush([]string{"-t", "111", "my-new-app"}, deps)
Exemple #13
0
)

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

		instance2 := models.AppInstanceFields{}
		instance2.State = models.InstanceStarting

		instance3 := models.AppInstanceFields{}
Exemple #14
0
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}

		callDeleteDomain([]string{"foo.com"}, []string{"y"}, reqFactory, domainRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		reqFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: false}
		callDeleteDomain([]string{"foo.com"}, []string{"y"}, reqFactory, domainRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		reqFactory = &testreq.FakeReqFactory{LoginSuccess: false, TargetedOrgSuccess: true}
		callDeleteDomain([]string{"foo.com"}, []string{"y"}, reqFactory, domainRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})
	It("TestDeleteDomainSuccess", func() {

		domain := models.DomainFields{}
		domain.Name = "foo.com"
		domain.Guid = "foo-guid"
		domainRepo := &testapi.FakeDomainRepository{
			FindByNameInOrgDomain: domain,
		}
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}

		ui := callDeleteDomain([]string{"foo.com"}, []string{"y"}, reqFactory, domainRepo)

		Expect(domainRepo.DeleteDomainGuid).To(Equal("foo-guid"))

		testassert.SliceContains(ui.Prompts, testassert.Lines{
			{"delete", "foo.com"},
		})
Exemple #15
0
		Expect(handler).To(testnet.HaveAllRequestsCalled())
		Expect(apiErr).NotTo(BeNil())
	})

	It("finds a route by host and domain", func() {
		request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:   "GET",
			Path:     "/v2/routes?q=host%3Amy-cool-app%3Bdomain_guid%3Amy-domain-guid",
			Response: findRouteByHostResponse,
		})

		ts, handler, repo, domainRepo := createRoutesRepo(request)
		defer ts.Close()

		domain := models.DomainFields{}
		domain.Guid = "my-domain-guid"
		domainRepo.FindByNameDomain = domain

		route, apiErr := repo.FindByHostAndDomain("my-cool-app", "my-domain.com")

		Expect(apiErr).NotTo(HaveOccurred())
		Expect(handler).To(testnet.HaveAllRequestsCalled())
		Expect(domainRepo.FindByNameName).To(Equal("my-domain.com"))
		Expect(route.Host).To(Equal("my-cool-app"))
		Expect(route.Guid).To(Equal("my-route-guid"))
		Expect(route.Domain.Guid).To(Equal(domain.Guid))
	})

	It("returns 'not found' response when there is no route w/ the given domain and host", func() {
		request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Exemple #16
0
		reqFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}
		callShowSpace(args, reqFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
	})
	It("TestShowSpaceInfoSuccess", func() {

		org := models.OrganizationFields{}
		org.Name = "my-org"

		app := models.ApplicationFields{}
		app.Name = "app1"
		app.Guid = "app1-guid"
		apps := []models.ApplicationFields{app}

		domain := models.DomainFields{}
		domain.Name = "domain1"
		domain.Guid = "domain1-guid"
		domains := []models.DomainFields{domain}

		serviceInstance := models.ServiceInstanceFields{}
		serviceInstance.Name = "service1"
		serviceInstance.Guid = "service1-guid"
		services := []models.ServiceInstanceFields{serviceInstance}

		space := models.Space{}
		space.Name = "space1"
		space.Organization = org
		space.Applications = apps
		space.Domains = domains
		space.ServiceInstances = services
Exemple #17
0
		ui = callMapRoute([]string{"foo", "bar"}, requirementsFactory, routeRepo, &testcmd.FakeRouteCreator{})
		Expect(ui.FailedWithUsage).To(BeFalse())
	})
	It("TestMapRouteRequirements", func() {

		routeRepo := &testapi.FakeRouteRepository{}
		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true}

		callMapRoute([]string{"-n", "my-host", "my-app", "my-domain.com"}, requirementsFactory, routeRepo, &testcmd.FakeRouteCreator{})
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
		Expect(requirementsFactory.ApplicationName).To(Equal("my-app"))
		Expect(requirementsFactory.DomainName).To(Equal("my-domain.com"))
	})
	It("TestMapRouteWhenBinding", func() {

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

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

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