當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Route.Host方法代碼示例

本文整理匯總了Golang中cf.Route.Host方法的典型用法代碼示例。如果您正苦於以下問題:Golang Route.Host方法的具體用法?Golang Route.Host怎麽用?Golang Route.Host使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cf.Route的用法示例。


在下文中一共展示了Route.Host方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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")
}
開發者ID:nsnt,項目名稱:cli,代碼行數:28,代碼來源:map_route_test.go

示例2: 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")
}
開發者ID:nsnt,項目名稱:cli,代碼行數:25,代碼來源:delete_route_test.go

示例3: 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"},
	})
}
開發者ID:nsnt,項目名稱:cli,代碼行數:32,代碼來源:push_test.go

示例4: 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"},
	})
}
開發者ID:nsnt,項目名稱:cli,代碼行數:47,代碼來源:list_routes_test.go

示例5: 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
}
開發者ID:jbayer,項目名稱:cli,代碼行數:55,代碼來源:applications.go

示例6: 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
}
開發者ID:KaiYoung,項目名稱:cli,代碼行數:52,代碼來源:applications.go

示例7: 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)
}
開發者ID:nsnt,項目名稱:cli,代碼行數:19,代碼來源:map_route_test.go

示例8: 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")
}
開發者ID:nsnt,項目名稱:cli,代碼行數:43,代碼來源:create_route_test.go

示例9: 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")
}
開發者ID:nsnt,項目名稱:cli,代碼行數:36,代碼來源:create_route_test.go


注:本文中的cf.Route.Host方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。