当前位置: 首页>>代码示例>>Golang>>正文


Golang net.NewCloudControllerGateway函数代码示例

本文整理汇总了Golang中cf/net.NewCloudControllerGateway函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCloudControllerGateway函数的具体用法?Golang NewCloudControllerGateway怎么用?Golang NewCloudControllerGateway使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewCloudControllerGateway函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: testScore

func testScore(t *testing.T, scoreBody string, expectedScore string) {
	passwordScoreResponse := testhelpers.TestResponse{Status: http.StatusOK, Body: scoreBody}

	passwordScoreEndpoint := testhelpers.CreateEndpoint(
		"POST",
		"/password/score",
		func(req *http.Request) bool {
			bodyMatcher := testhelpers.RequestBodyMatcher("password=new-password")
			contentTypeMatches := req.Header.Get("Content-Type") == "application/x-www-form-urlencoded"

			return contentTypeMatches && bodyMatcher(req)
		},
		passwordScoreResponse,
	)

	scoreServer := httptest.NewTLSServer(http.HandlerFunc(passwordScoreEndpoint))
	defer scoreServer.Close()

	targetServer := createInfoServer(scoreServer.URL)
	defer targetServer.Close()

	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      targetServer.URL,
	}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerPasswordRepository(config, gateway)

	score, err := repo.GetScore("new-password")
	assert.NoError(t, err)
	assert.Equal(t, score, expectedScore)
}
开发者ID:jbayer,项目名称:cli,代码行数:32,代码来源:password_test.go

示例2: TestListEvents

func TestListEvents(t *testing.T) {

	listEventsServer := httptest.NewTLSServer(http.HandlerFunc(listEventsEndpoint))
	defer listEventsServer.Close()

	config := &configuration.Configuration{
		Target:      listEventsServer.URL,
		AccessToken: "BEARER my_access_token",
	}
	repo := NewCloudControllerAppEventsRepository(config, net.NewCloudControllerGateway())

	list, apiErr := repo.ListEvents(cf.Application{Guid: "my-app-guid"})

	firstExpectedTime, err := time.Parse(APP_EVENT_TIMESTAMP_FORMAT, "2013-10-07T16:51:07+00:00")
	secondExpectedTime, err := time.Parse(APP_EVENT_TIMESTAMP_FORMAT, "2013-10-07T17:51:07+00:00")
	expectedEvents := []cf.Event{
		{
			InstanceIndex:   1,
			ExitStatus:      1,
			ExitDescription: "app instance exited",
			Timestamp:       firstExpectedTime,
		},
		{
			InstanceIndex:   2,
			ExitStatus:      2,
			ExitDescription: "app instance was stopped",
			Timestamp:       secondExpectedTime,
		},
	}

	assert.NoError(t, err)
	assert.True(t, apiErr.IsSuccessful())
	assert.Equal(t, list, expectedEvents)
}
开发者ID:jalateras,项目名称:cli,代码行数:34,代码来源:app_events_test.go

示例3: TestGetServiceOfferings

func TestGetServiceOfferings(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(multipleOfferingsEndpoint))
	defer ts.Close()

	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      ts.URL,
	}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerServiceRepository(config, gateway)
	offerings, err := repo.GetServiceOfferings()

	assert.NoError(t, err)
	assert.Equal(t, 2, len(offerings))

	firstOffering := offerings[0]
	assert.Equal(t, firstOffering.Label, "Offering 1")
	assert.Equal(t, firstOffering.Version, "1.0")
	assert.Equal(t, firstOffering.Description, "Offering 1 description")
	assert.Equal(t, firstOffering.Provider, "Offering 1 provider")
	assert.Equal(t, firstOffering.Guid, "offering-1-guid")
	assert.Equal(t, len(firstOffering.Plans), 2)

	plan := firstOffering.Plans[0]
	assert.Equal(t, plan.Name, "Offering 1 Plan 1")
	assert.Equal(t, plan.Guid, "offering-1-plan-1-guid")

	secondOffering := offerings[1]
	assert.Equal(t, secondOffering.Label, "Offering 2")
	assert.Equal(t, secondOffering.Guid, "offering-2-guid")
	assert.Equal(t, len(secondOffering.Plans), 1)
}
开发者ID:jbayer,项目名称:cli,代码行数:32,代码来源:services_test.go

示例4: createInsecureEndpointRepoForUpdate

func createInsecureEndpointRepoForUpdate(config configuration.ReadWriter, endpoint func(w http.ResponseWriter, r *http.Request)) (ts *httptest.Server, repo EndpointRepository) {
	if endpoint != nil {
		ts = httptest.NewServer(http.HandlerFunc(endpoint))
	}
	gateway := net.NewCloudControllerGateway()
	return ts, NewEndpointRepository(config, gateway)
}
开发者ID:normalnorman,项目名称:cli,代码行数:7,代码来源:endpoints_test.go

示例5: testUploadApp

func testUploadApp(dir string, requests []testnet.TestRequest) (app models.Application, apiResponse net.ApiResponse) {
	ts, handler := testnet.NewTLSServer(requests)
	defer ts.Close()

	configRepo := testconfig.NewRepositoryWithDefaults()
	configRepo.SetApiEndpoint(ts.URL)
	gateway := net.NewCloudControllerGateway()
	gateway.PollingThrottle = time.Duration(0)
	zipper := cf.ApplicationZipper{}
	repo := NewCloudControllerApplicationBitsRepository(configRepo, gateway, zipper)

	var (
		reportedPath                          string
		reportedFileCount, reportedUploadSize uint64
	)
	apiResponse = repo.UploadApp("my-cool-app-guid", dir, func(path string, uploadSize, fileCount uint64) {
		reportedPath = path
		reportedUploadSize = uploadSize
		reportedFileCount = fileCount
	})

	Expect(reportedPath).To(Equal(dir))
	Expect(reportedFileCount).To(Equal(uint64(len(expectedApplicationContent))))
	Expect(reportedUploadSize).To(Equal(uint64(759)))
	Expect(handler.AllRequestsCalled()).To(BeTrue())

	return
}
开发者ID:normalnorman,项目名称:cli,代码行数:28,代码来源:application_bits_test.go

示例6: TestListEventsWithNoEvents

func TestListEventsWithNoEvents(t *testing.T) {
	emptyEventsRequest := testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/apps/my-app-guid/events",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body:   `{"resources": []}`},
	}

	listEventsServer, handler := testnet.NewTLSServer(t, []testnet.TestRequest{emptyEventsRequest})
	defer listEventsServer.Close()

	config := &configuration.Configuration{
		Target:      listEventsServer.URL,
		AccessToken: "BEARER my_access_token",
	}
	repo := NewCloudControllerAppEventsRepository(config, net.NewCloudControllerGateway())
	eventChan, apiErr := repo.ListEvents("my-app-guid")

	_, ok := <-eventChan
	_, open := <-apiErr

	assert.False(t, ok)
	assert.False(t, open)
	assert.True(t, handler.AllRequestsCalled())
}
开发者ID:nsnt,项目名称:cli,代码行数:26,代码来源:app_events_test.go

示例7: TestCreateApplication

func TestCreateApplication(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(createApplicationEndpoint))
	defer ts.Close()

	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      ts.URL,
		Space:       cf.Space{Guid: "my-space-guid"},
	}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerApplicationRepository(config, gateway)

	newApp := cf.Application{
		Name:         "my-cool-app",
		Instances:    3,
		Memory:       2048,
		BuildpackUrl: "buildpack-url",
		Stack:        cf.Stack{Guid: "some-stack-guid"},
	}

	createdApp, err := repo.Create(newApp)
	assert.NoError(t, err)

	assert.Equal(t, createdApp, cf.Application{Name: "my-cool-app", Guid: "my-cool-app-guid"})
}
开发者ID:jbayer,项目名称:cli,代码行数:25,代码来源:applications_test.go

示例8: TestFindByName

func TestFindByName(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(singleAppEndpoint))
	defer ts.Close()

	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      ts.URL,
		Space:       cf.Space{Name: "my-space", Guid: "my-space-guid"},
	}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerApplicationRepository(config, gateway)

	app, err := repo.FindByName("App1")
	assert.NoError(t, err)
	assert.Equal(t, app.Name, "App1")
	assert.Equal(t, app.Guid, "app1-guid")
	assert.Equal(t, app.Memory, 128)
	assert.Equal(t, app.Instances, 1)
	assert.Equal(t, app.EnvironmentVars, map[string]string{"foo": "bar", "baz": "boom"})

	assert.Equal(t, len(app.Urls), 1)
	assert.Equal(t, app.Urls[0], "app1.cfapps.io")

	app, err = repo.FindByName("app that does not exist")
	assert.Error(t, err)
}
开发者ID:jbayer,项目名称:cli,代码行数:26,代码来源:applications_test.go

示例9: TestRoutesFindAll

func TestRoutesFindAll(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(findAllEndpoint))
	defer ts.Close()

	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      ts.URL,
	}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerRouteRepository(config, gateway)

	routes, err := repo.FindAll()
	assert.NoError(t, err)

	assert.Equal(t, len(routes), 2)

	route := routes[0]
	assert.Equal(t, route.Host, "route-1-host")
	assert.Equal(t, route.Guid, "route-1-guid")
	assert.Equal(t, route.Domain.Name, "cfapps.io")
	assert.Equal(t, route.Domain.Guid, "domain-1-guid")

	route = routes[1]
	assert.Equal(t, route.Guid, "route-2-guid")
}
开发者ID:jbayer,项目名称:cli,代码行数:25,代码来源:routes_test.go

示例10: TestSpacesFindAllWithIncorrectToken

func TestSpacesFindAllWithIncorrectToken(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(multipleSpacesEndpoint))
	defer ts.Close()

	config := &configuration.Configuration{
		AccessToken:  "BEARER incorrect_access_token",
		Target:       ts.URL,
		Organization: cf.Organization{Guid: "some-org-guid"},
	}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerSpaceRepository(config, gateway)

	var (
		spaces []cf.Space
		err    error
	)

	// Capture output so debugging info does not show up in test
	// output
	testhelpers.CaptureOutput(func() {
		spaces, err = repo.FindAll()
	})

	assert.Error(t, err)
	assert.Equal(t, 0, len(spaces))
}
开发者ID:jbayer,项目名称:cli,代码行数:26,代码来源:spaces_test.go

示例11: main

func main() {
	fileutils.SetTmpPathPrefix("cf")

	if os.Getenv("CF_COLOR") == "" {
		os.Setenv("CF_COLOR", "true")
	}

	termUI := terminal.NewUI()
	assignTemplates()
	configRepo := configuration.NewConfigurationDiskRepository()
	config := loadConfig(termUI, configRepo)

	repoLocator := api.NewRepositoryLocator(config, configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(),
		"cloud-controller": net.NewCloudControllerGateway(),
		"uaa":              net.NewUAAGateway(),
	})

	cmdFactory := commands.NewFactory(termUI, config, configRepo, repoLocator)
	reqFactory := requirements.NewFactory(termUI, config, repoLocator)
	cmdRunner := commands.NewRunner(cmdFactory, reqFactory)

	app, err := app.NewApp(cmdRunner)
	if err != nil {
		return
	}
	app.Run(os.Args)
}
开发者ID:jalateras,项目名称:cli,代码行数:28,代码来源:cf.go

示例12: createUsersRepo

func createUsersRepo(t *testing.T, ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) (cc *httptest.Server,
	ccHandler *testnet.TestHandler, uaa *httptest.Server, uaaHandler *testnet.TestHandler, repo UserRepository) {

	ccTarget := ""
	uaaTarget := ""

	if len(ccReqs) > 0 {
		cc, ccHandler = testnet.NewTLSServer(t, ccReqs)
		ccTarget = cc.URL
	}
	if len(uaaReqs) > 0 {
		uaa, uaaHandler = testnet.NewTLSServer(t, uaaReqs)
		uaaTarget = uaa.URL
	}

	config := &configuration.Configuration{
		AccessToken:  "BEARER my_access_token",
		Target:       ccTarget,
		Organization: cf.Organization{Guid: "some-org-guid"},
	}
	ccGateway := net.NewCloudControllerGateway()
	uaaGateway := net.NewUAAGateway()
	endpointRepo := &testapi.FakeEndpointRepo{GetEndpointEndpoints: map[cf.EndpointType]string{
		cf.UaaEndpointKey: uaaTarget,
	}}
	repo = NewCloudControllerUserRepository(config, uaaGateway, ccGateway, endpointRepo)
	return
}
开发者ID:jalateras,项目名称:cli,代码行数:28,代码来源:users_test.go

示例13: setupDependencies

func setupDependencies() (deps *cliDependencies) {
	if os.Getenv("CF_COLOR") == "" {
		os.Setenv("CF_COLOR", "true")
	}

	deps = new(cliDependencies)

	deps.termUI = terminal.NewUI(os.Stdin)

	deps.manifestRepo = manifest.NewManifestDiskRepository()

	deps.configRepo = configuration.NewRepositoryFromFilepath(configuration.DefaultFilePath(), func(err error) {
		if err != nil {
			deps.termUI.Failed(fmt.Sprintf("Config error: %s", err))
		}
	})

	deps.apiRepoLocator = api.NewRepositoryLocator(deps.configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(deps.configRepo),
		"cloud-controller": net.NewCloudControllerGateway(deps.configRepo),
		"uaa":              net.NewUAAGateway(deps.configRepo),
	})

	return
}
开发者ID:juggernaut,项目名称:cli,代码行数:25,代码来源:cf.go

示例14: createUsersRepo

func createUsersRepo(t *testing.T, ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) (cc *httptest.Server,
	ccHandler *testnet.TestHandler, uaa *httptest.Server, uaaHandler *testnet.TestHandler, repo UserRepository) {

	ccTarget := ""
	uaaTarget := ""

	if len(ccReqs) > 0 {
		cc, ccHandler = testnet.NewTLSServer(t, ccReqs)
		ccTarget = cc.URL
	}
	if len(uaaReqs) > 0 {
		uaa, uaaHandler = testnet.NewTLSServer(t, uaaReqs)
		uaaTarget = uaa.URL
	}
	org := cf.OrganizationFields{}
	org.Guid = "some-org-guid"
	config := &configuration.Configuration{
		AccessToken:        "BEARER my_access_token",
		Target:             ccTarget,
		OrganizationFields: org,
	}
	ccGateway := net.NewCloudControllerGateway()
	uaaGateway := net.NewUAAGateway()
	endpointRepo := &testapi.FakeEndpointRepo{}
	endpointRepo.UAAEndpointReturns.Endpoint = uaaTarget
	repo = NewCloudControllerUserRepository(config, uaaGateway, ccGateway, endpointRepo)
	return
}
开发者ID:nsnt,项目名称:cli,代码行数:28,代码来源:users_test.go

示例15: testUploadApp

func testUploadApp(t *testing.T, dir string, requests []testnet.TestRequest) (app cf.Application, apiResponse net.ApiResponse) {
	ts, handler := testnet.NewTLSServer(t, requests)
	defer ts.Close()

	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      ts.URL,
	}
	gateway := net.NewCloudControllerGateway()
	gateway.PollingThrottle = time.Duration(0)
	zipper := cf.ApplicationZipper{}
	repo := NewCloudControllerApplicationBitsRepository(config, gateway, zipper)

	var reportedFileCount, reportedUploadSize uint64
	apiResponse = repo.UploadApp("my-cool-app-guid", dir, func(uploadSize, fileCount uint64) {
		reportedUploadSize = uploadSize
		reportedFileCount = fileCount
	})

	assert.Equal(t, reportedFileCount, uint64(len(expectedApplicationContent)))
	assert.Equal(t, reportedUploadSize, uint64(759))
	assert.True(t, handler.AllRequestsCalled())

	return
}
开发者ID:pmuellr,项目名称:cli,代码行数:25,代码来源:application_bits_test.go


注:本文中的cf/net.NewCloudControllerGateway函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。