本文整理匯總了Golang中cf.Route類的典型用法代碼示例。如果您正苦於以下問題:Golang Route類的具體用法?Golang Route怎麽用?Golang Route使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Route類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestMapRouteWhenBinding
func TestMapRouteWhenBinding(t *testing.T) {
domain := cf.Domain{}
domain.Guid = "my-domain-guid"
domain.Name = "example.com"
route := cf.Route{}
route.Guid = "my-route-guid"
route.Host = "foo"
route.Domain = domain.DomainFields
app := cf.Application{}
app.Guid = "my-app-guid"
app.Name = "my-app"
routeRepo := &testapi.FakeRouteRepository{}
reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Application: app, Domain: domain}
routeCreator := &testcmd.FakeRouteCreator{ReservedRoute: route}
ui := callMapRoute(t, []string{"-n", "my-host", "my-app", "my-domain.com"}, reqFactory, routeRepo, routeCreator)
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Adding route", "foo.example.com", "my-app", "my-org", "my-space", "my-user"},
{"OK"},
})
assert.Equal(t, routeRepo.BoundRouteGuid, "my-route-guid")
assert.Equal(t, routeRepo.BoundAppGuid, "my-app-guid")
}
示例2: TestPushingAppWhenItDoesNotExistButRouteExists
func TestPushingAppWhenItDoesNotExistButRouteExists(t *testing.T) {
deps := getPushDependencies()
domain := cf.Domain{}
domain.Name = "foo.cf-app.com"
domain.Guid = "foo-domain-guid"
domain.Shared = true
route := cf.Route{}
route.Guid = "my-route-guid"
route.Host = "my-new-app"
route.Domain = domain.DomainFields
deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{domain}
deps.routeRepo.FindByHostAndDomainRoute = route
deps.appRepo.ReadNotFound = true
ui := callPush(t, []string{"my-new-app"}, deps)
assert.Empty(t, deps.routeRepo.CreatedHost)
assert.Empty(t, deps.routeRepo.CreatedDomainGuid)
assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "my-new-app")
assert.Equal(t, deps.routeRepo.BoundAppGuid, "my-new-app-guid")
assert.Equal(t, deps.routeRepo.BoundRouteGuid, "my-route-guid")
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Using", "my-new-app.foo.cf-app.com"},
{"Binding", "my-new-app.foo.cf-app.com"},
{"OK"},
})
}
示例3: TestPushingAppWhenItAlreadyExistsAndDomainIsSpecifiedIsAlreadyBound
func TestPushingAppWhenItAlreadyExistsAndDomainIsSpecifiedIsAlreadyBound(t *testing.T) {
deps := getPushDependencies()
domain := cf.DomainFields{}
domain.Name = "example.com"
domain.Guid = "domain-guid"
existingRoute := cf.RouteSummary{}
existingRoute.Host = "existing-app"
existingRoute.Domain = domain
existingApp := cf.Application{}
existingApp.Name = "existing-app"
existingApp.Guid = "existing-app-guid"
existingApp.Routes = []cf.RouteSummary{existingRoute}
foundRoute := cf.Route{}
foundRoute.RouteFields = existingRoute.RouteFields
foundRoute.Domain = existingRoute.Domain
deps.appRepo.ReadApp = existingApp
deps.appRepo.UpdateAppResult = existingApp
deps.routeRepo.FindByHostAndDomainRoute = foundRoute
ui := callPush(t, []string{"-d", "example.com", "existing-app"}, deps)
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Using route", "existing-app", "example.com"},
})
assert.Equal(t, deps.appBitsRepo.UploadedAppGuid, "existing-app-guid")
}
示例4: appFromResource
func (repo CloudControllerApplicationRepository) appFromResource(res ApplicationResource) (app cf.Application) {
app = cf.Application{
Guid: res.Metadata.Guid,
Name: res.Entity.Name,
EnvironmentVars: res.Entity.EnvironmentJson,
State: strings.ToLower(res.Entity.State),
Instances: res.Entity.Instances,
Memory: uint64(res.Entity.Memory),
}
for _, routeResource := range res.Entity.Routes {
domainResource := routeResource.Entity.Domain
route := cf.Route{
Guid: routeResource.Metadata.Guid,
Host: routeResource.Entity.Host,
}
route.Domain = cf.Domain{
Guid: domainResource.Metadata.Guid,
Name: domainResource.Entity.Name,
}
app.Routes = append(app.Routes, route)
}
return
}
示例5: CreateRoute
func (cmd *CreateRoute) CreateRoute(hostName string, domain cf.Domain, space cf.Space) (route cf.Route, apiResponse net.ApiResponse) {
routeToCreate := cf.Route{Host: hostName, Domain: domain}
cmd.ui.Say("Creating route %s for org %s / space %s as %s...",
terminal.EntityNameColor(routeToCreate.URL()),
terminal.EntityNameColor(cmd.config.Organization.Name),
terminal.EntityNameColor(space.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
route, apiResponse = cmd.routeRepo.CreateInSpace(routeToCreate, domain, space)
if apiResponse.IsNotSuccessful() {
var findApiResponse net.ApiResponse
route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain.Name)
if findApiResponse.IsNotSuccessful() ||
route.Space.Guid != space.Guid ||
route.Domain.Guid != domain.Guid ||
route.Host != hostName {
return
}
apiResponse = net.NewSuccessfulApiResponse()
cmd.ui.Ok()
cmd.ui.Warn("Route %s already exists", route.URL())
return
}
cmd.ui.Ok()
return
}
示例6: TestDeleteRouteWithConfirmation
func TestDeleteRouteWithConfirmation(t *testing.T) {
domain := cf.DomainFields{}
domain.Guid = "domain-guid"
domain.Name = "example.com"
reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
route := cf.Route{}
route.Guid = "route-guid"
route.Host = "my-host"
route.Domain = domain
routeRepo := &testapi.FakeRouteRepository{
FindByHostAndDomainRoute: route,
}
ui := callDeleteRoute(t, "y", []string{"-n", "my-host", "example.com"}, reqFactory, routeRepo)
testassert.SliceContains(t, ui.Prompts, testassert.Lines{
{"Really delete", "my-host"},
})
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Deleting route", "my-host.example.com"},
{"OK"},
})
assert.Equal(t, routeRepo.DeleteRouteGuid, "route-guid")
}
示例7: FindByName
func (repo CloudControllerApplicationRepository) FindByName(name string) (app cf.Application, apiErr *net.ApiError) {
path := fmt.Sprintf("%s/v2/spaces/%s/apps?q=name%s&inline-relations-depth=1", repo.config.Target, repo.config.Space.Guid, "%3A"+name)
request, apiErr := repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
if apiErr != nil {
return
}
findResponse := new(ApplicationsApiResponse)
apiErr = repo.gateway.PerformRequestForJSONResponse(request, findResponse)
if apiErr != nil {
return
}
if len(findResponse.Resources) == 0 {
apiErr = net.NewApiErrorWithMessage(fmt.Sprintf("Application %s not found", name))
return
}
res := findResponse.Resources[0]
path = fmt.Sprintf("%s/v2/apps/%s/summary", repo.config.Target, res.Metadata.Guid)
request, apiErr = repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
if apiErr != nil {
return
}
summaryResponse := new(ApplicationSummary)
apiErr = repo.gateway.PerformRequestForJSONResponse(request, summaryResponse)
if apiErr != nil {
return
}
urls := []string{}
// This is a little wonky but we made a concious effort
// to keep the domain very separate from the API repsonses
// to maintain flexibility.
domainRoute := cf.Route{}
for _, route := range summaryResponse.Routes {
domainRoute.Domain = cf.Domain{Name: route.Domain.Name}
domainRoute.Host = route.Host
urls = append(urls, domainRoute.URL())
}
app = cf.Application{
Name: summaryResponse.Name,
Guid: summaryResponse.Guid,
Instances: summaryResponse.Instances,
RunningInstances: summaryResponse.RunningInstances,
Memory: summaryResponse.Memory,
EnvironmentVars: res.Entity.EnvironmentJson,
Urls: urls,
State: strings.ToLower(summaryResponse.State),
}
return
}
示例8: FindByName
func (repo CloudControllerApplicationRepository) FindByName(name string) (app cf.Application, err error) {
path := fmt.Sprintf("%s/v2/spaces/%s/apps?q=name%s&inline-relations-depth=1", repo.config.Target, repo.config.Space.Guid, "%3A"+name)
request, err := NewRequest("GET", path, repo.config.AccessToken, nil)
if err != nil {
return
}
findResponse := new(ApplicationsApiResponse)
_, err = repo.apiClient.PerformRequestAndParseResponse(request, findResponse)
if err != nil {
return
}
if len(findResponse.Resources) == 0 {
err = errors.New(fmt.Sprintf("Application %s not found", name))
return
}
res := findResponse.Resources[0]
path = fmt.Sprintf("%s/v2/apps/%s/summary", repo.config.Target, res.Metadata.Guid)
request, err = NewRequest("GET", path, repo.config.AccessToken, nil)
if err != nil {
return
}
summaryResponse := new(ApplicationSummary)
_, err = repo.apiClient.PerformRequestAndParseResponse(request, summaryResponse)
if err != nil {
return
}
urls := []string{}
// This is a little wonky but we made a concious effort
// to keep the domain very separate from the API repsonses
// to maintain flexibility.
domainRoute := cf.Route{}
for _, route := range summaryResponse.Routes {
domainRoute.Domain = cf.Domain{Name: route.Domain.Name}
domainRoute.Host = route.Host
urls = append(urls, domainRoute.URL())
}
app = cf.Application{
Name: summaryResponse.Name,
Guid: summaryResponse.Guid,
Instances: summaryResponse.Instances,
Memory: summaryResponse.Memory,
Urls: urls,
}
return
}
示例9: createRoute
func (cmd Push) createRoute(hostName string, domain cf.Domain) (route cf.Route) {
newRoute := cf.Route{Host: hostName, Domain: domain}
cmd.ui.Say("Creating route %s...", terminal.EntityNameColor(newRoute.URL()))
route, apiResponse := cmd.routeRepo.Create(newRoute, domain)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
cmd.ui.Say("")
return
}
示例10: TestMapRouteWhenRouteNotReserved
func TestMapRouteWhenRouteNotReserved(t *testing.T) {
domain := cf.DomainFields{}
domain.Name = "my-domain.com"
route := cf.Route{}
route.Guid = "my-app-guid"
route.Host = "my-host"
route.Domain = domain
app := cf.Application{}
app.Guid = "my-app-guid"
app.Name = "my-app"
routeRepo := &testapi.FakeRouteRepository{}
reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Application: app}
routeCreator := &testcmd.FakeRouteCreator{ReservedRoute: route}
callMapRoute(t, []string{"-n", "my-host", "my-app", "my-domain.com"}, reqFactory, routeRepo, routeCreator)
assert.Equal(t, routeCreator.ReservedRoute, route)
}
示例11: TestRouteCreator
func TestRouteCreator(t *testing.T) {
space := cf.SpaceFields{}
space.Guid = "my-space-guid"
space.Name = "my-space"
domain := cf.DomainFields{}
domain.Guid = "domain-guid"
domain.Name = "example.com"
createdRoute := cf.Route{}
createdRoute.Host = "my-host"
createdRoute.Guid = "my-route-guid"
routeRepo := &testapi.FakeRouteRepository{
CreateInSpaceCreatedRoute: createdRoute,
}
ui := new(testterm.FakeUI)
token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
Username: "my-user",
})
assert.NoError(t, err)
org := cf.OrganizationFields{}
org.Name = "my-org"
config := &configuration.Configuration{
OrganizationFields: org,
AccessToken: token,
}
cmd := NewCreateRoute(ui, config, routeRepo)
route, apiResponse := cmd.CreateRoute("my-host", domain, space)
assert.Equal(t, route.Guid, createdRoute.Guid)
assert.True(t, apiResponse.IsSuccessful())
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Creating route", "my-host.example.com", "my-org", "my-space", "my-user"},
{"OK"},
})
assert.Equal(t, routeRepo.CreateInSpaceHost, "my-host")
assert.Equal(t, routeRepo.CreateInSpaceDomainGuid, "domain-guid")
assert.Equal(t, routeRepo.CreateInSpaceSpaceGuid, "my-space-guid")
}
示例12: TestCreateRouteIsIdempotent
func TestCreateRouteIsIdempotent(t *testing.T) {
space := cf.SpaceFields{}
space.Guid = "my-space-guid"
space.Name = "my-space"
domain := cf.DomainFields{}
domain.Guid = "domain-guid"
domain.Name = "example.com"
reqFactory := &testreq.FakeReqFactory{
LoginSuccess: true,
TargetedOrgSuccess: true,
Domain: cf.Domain{DomainFields: domain},
Space: cf.Space{SpaceFields: space},
}
route := cf.Route{}
route.Guid = "my-route-guid"
route.Host = "host"
route.Domain = domain
route.Space = space
routeRepo := &testapi.FakeRouteRepository{
CreateInSpaceErr: true,
FindByHostAndDomainRoute: route,
}
ui := callCreateRoute(t, []string{"-n", "host", "my-space", "example.com"}, reqFactory, routeRepo)
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Creating route"},
{"OK"},
{"host.example.com", "already exists"},
})
assert.Equal(t, routeRepo.CreateInSpaceHost, "host")
assert.Equal(t, routeRepo.CreateInSpaceDomainGuid, "domain-guid")
assert.Equal(t, routeRepo.CreateInSpaceSpaceGuid, "my-space-guid")
}
示例13: TestListingRoutes
func TestListingRoutes(t *testing.T) {
domain := cf.DomainFields{}
domain.Name = "example.com"
domain2 := cf.DomainFields{}
domain2.Name = "cfapps.com"
domain3 := cf.DomainFields{}
domain3.Name = "another-example.com"
app1 := cf.ApplicationFields{}
app1.Name = "dora"
app2 := cf.ApplicationFields{}
app2.Name = "dora2"
app3 := cf.ApplicationFields{}
app3.Name = "my-app"
app4 := cf.ApplicationFields{}
app4.Name = "my-app2"
app5 := cf.ApplicationFields{}
app5.Name = "july"
route := cf.Route{}
route.Host = "hostname-1"
route.Domain = domain
route.Apps = []cf.ApplicationFields{app1, app2}
route2 := cf.Route{}
route2.Host = "hostname-2"
route2.Domain = domain2
route2.Apps = []cf.ApplicationFields{app3, app4}
route3 := cf.Route{}
route3.Host = "hostname-3"
route3.Domain = domain3
route3.Apps = []cf.ApplicationFields{app5}
routes := []cf.Route{route, route2, route3}
routeRepo := &testapi.FakeRouteRepository{Routes: routes}
ui := callListRoutes(t, []string{}, &testreq.FakeReqFactory{}, routeRepo)
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"Getting routes", "my-user"},
{"host", "domain", "apps"},
{"hostname-1", "example.com", "dora", "dora2"},
{"hostname-2", "cfapps.com", "my-app", "my-app2"},
{"hostname-3", "another-example.com", "july"},
})
}