當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。