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


Golang ReadWriter.SetApiEndpoint方法代碼示例

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


在下文中一共展示了ReadWriter.SetApiEndpoint方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createServiceRepoWithConfig

func createServiceRepoWithConfig(reqs []testnet.TestRequest, config configuration.ReadWriter) (testServer *httptest.Server, handler *testnet.TestHandler, repo ServiceRepository) {
	testServer, handler = testnet.NewServer(reqs)
	config.SetApiEndpoint(testServer.URL)

	gateway := net.NewCloudControllerGateway(config)
	repo = NewCloudControllerServiceRepository(config, gateway)
	return
}
開發者ID:juggernaut,項目名稱:cli,代碼行數:8,代碼來源:services_test.go

示例2:

			Expect(ui.FailedWithUsage).To(BeTrue())
		})

		It("fails if the user has not set an api endpoint", func() {
			context := testcmd.NewContext("auth", []string{"username", "password"})
			testcmd.RunCommand(cmd, context, requirementsFactory)

			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	Context("when an api endpoint is targeted", func() {
		BeforeEach(func() {
			requirementsFactory.ApiEndpointSuccess = true
			config.SetApiEndpoint("foo.example.org/authenticate")
		})

		It("authenticates successfully", func() {
			requirementsFactory.ApiEndpointSuccess = true
			context := testcmd.NewContext("auth", []string{"[email protected]", "password"})
			testcmd.RunCommand(cmd, context, requirementsFactory)

			Expect(ui.FailedWithUsage).To(BeFalse())
			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"foo.example.org/authenticate"},
				{"OK"},
			})

			Expect(repo.AuthenticateArgs.Credentials).To(Equal([]map[string]string{
				{
開發者ID:nota-ja,項目名稱:cli,代碼行數:30,代碼來源:auth_test.go

示例3:

				{"SSL cert", "https://buttontomatoes.org"},
				{"TIP", "--skip-ssl-validation"},
			})
		})
	})

	Context("when the user does not provide an endpoint", func() {
		Context("when the endpoint is set in the config", func() {
			var (
				ui                  *testterm.FakeUI
				ctx                 *cli.Context
				requirementsFactory *testreq.FakeReqFactory
			)

			BeforeEach(func() {
				config.SetApiEndpoint("https://api.run.pivotal.io")
				config.SetApiVersion("2.0")
				config.SetSSLDisabled(true)

				ui = new(testterm.FakeUI)
				ctx = testcmd.NewContext("api", []string{})
				requirementsFactory = &testreq.FakeReqFactory{}
			})

			JustBeforeEach(func() {
				testcmd.RunCommand(NewApi(ui, config, endpointRepo), ctx, requirementsFactory)
			})

			It("prints out the api endpoint", func() {
				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"https://api.run.pivotal.io", "2.0"},
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:api_test.go

示例4:

				Expect(Config.AccessToken()).To(Equal("my_access_token"))
				Expect(Config.RefreshToken()).To(Equal("my_refresh_token"))

				Expect(endpointRepo.UpdateEndpointReceived).To(Equal("api.example.com"))
				Expect(authRepo.AuthenticateArgs.Credentials).To(Equal([]map[string]string{
					{
						"username": "[email protected]",
						"password": "password",
					},
				}))

				Expect(ui.ShowConfigurationCalled).To(BeTrue())
			})

			It("doesn't ask the user for the API url if they have it in their config", func() {
				Config.SetApiEndpoint("http://api.example.com")

				Flags = []string{"-o", "my-new-org", "-s", "my-space"}
				ui.Inputs = []string{"[email protected]", "password"}

				l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
				testcmd.RunCommand(l, testcmd.NewContext("login", Flags), nil)

				Expect(Config.ApiEndpoint()).To(Equal("http://api.example.com"))
				Expect(Config.OrganizationFields().Guid).To(Equal("my-new-org-guid"))
				Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
				Expect(Config.AccessToken()).To(Equal("my_access_token"))
				Expect(Config.RefreshToken()).To(Equal("my_refresh_token"))

				Expect(endpointRepo.UpdateEndpointReceived).To(Equal("http://api.example.com"))
				Expect(ui.ShowConfigurationCalled).To(BeTrue())
開發者ID:juggernaut,項目名稱:cli,代碼行數:31,代碼來源:login_test.go

示例5:

			})
		})

	})

	Context("when an api endpoint is set and the user logged in", func() {
		var config configuration.ReadWriter

		BeforeEach(func() {
			accessToken := configuration.TokenInfo{
				UserGuid: "my-user-guid",
				Username: "my-user",
				Email:    "my-user-email",
			}
			config = testconfig.NewRepositoryWithAccessToken(accessToken)
			config.SetApiEndpoint("https://test.example.org")
			config.SetApiVersion("☃☃☃")
		})

		Describe("tells the user what is set in the config", func() {
			var output []string

			JustBeforeEach(func() {
				output = captureOutput(func() {
					ui := NewUI(os.Stdin)
					ui.ShowConfiguration(config)
				})
			})

			It("tells the user which api endpoint is set", func() {
				testassert.SliceContains(output, testassert.Lines{
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:ui_test.go

示例6:

	testconfig "testhelpers/configuration"
	"testhelpers/maker"
	testnet "testhelpers/net"
)

var _ = Describe("Services Repo", func() {
	var (
		testServer  *httptest.Server
		testHandler *testnet.TestHandler
		configRepo  configuration.ReadWriter
		repo        ServiceRepository
	)

	setupTestServer := func(reqs ...testnet.TestRequest) {
		testServer, testHandler = testnet.NewServer(reqs)
		configRepo.SetApiEndpoint(testServer.URL)
	}

	BeforeEach(func() {
		configRepo = testconfig.NewRepositoryWithDefaults()
		configRepo.SetAccessToken("BEARER my_access_token")

		gateway := net.NewCloudControllerGateway(configRepo)
		repo = NewCloudControllerServiceRepository(configRepo, gateway)
	})

	AfterEach(func() {
		testServer.Close()
	})

	Describe("GetAllServiceOfferings", func() {
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:services_test.go

示例7:

				Expect(config.HasOrganization()).To(BeFalse())
				Expect(config.HasSpace()).To(BeFalse())
			})

			It("does not clear the session if the api endpoint does not change", func() {
				testServerFn = validApiInfoEndpoint

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

				space := models.SpaceFields{}
				space.Name = "my-space"
				space.Guid = "my-space-guid"

				config.SetApiEndpoint(testServer.URL)
				config.SetAccessToken("some access token")
				config.SetRefreshToken("some refresh token")
				config.SetOrganizationFields(org)
				config.SetSpaceFields(space)

				repo.UpdateEndpoint(testServer.URL)

				Expect(config.OrganizationFields()).To(Equal(org))
				Expect(config.SpaceFields()).To(Equal(space))
				Expect(config.AccessToken()).To(Equal("some access token"))
				Expect(config.RefreshToken()).To(Equal("some refresh token"))
			})
		})

		Context("when the API request fails", func() {
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:endpoints_test.go

示例8:

			Expect(config.HasOrganization()).To(BeFalse())
			Expect(config.HasSpace()).To(BeFalse())
		})

		It("TestUpdateEndpointWhenUrlIsAlreadyTargeted", func() {
			testServerFn = validApiInfoEndpoint

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

			space := models.SpaceFields{}
			space.Name = "my-space"
			space.Guid = "my-space-guid"

			config.SetApiEndpoint(testServer.URL)
			config.SetAccessToken("some access token")
			config.SetRefreshToken("some refresh token")
			config.SetOrganizationFields(org)
			config.SetSpaceFields(space)

			repo.UpdateEndpoint(testServer.URL)

			Expect(config.OrganizationFields()).To(Equal(org))
			Expect(config.SpaceFields()).To(Equal(space))
			Expect(config.AccessToken()).To(Equal("some access token"))
			Expect(config.RefreshToken()).To(Equal("some refresh token"))
		})

		It("returns a failure response when the API request fails", func() {
			testServerFn = func(w http.ResponseWriter, r *http.Request) {
開發者ID:nimbus-cloud,項目名稱:cli,代碼行數:31,代碼來源:endpoints_test.go

示例9:

			requestHandler.lastPath = request.URL.Path
			Expect(request.URL.RawQuery).To(Equal("app=my-app-guid"))
			Expect(request.Method).To(Equal("GET"))
			Expect(request.Header.Get("Authorization")).To(ContainSubstring("BEARER my_access_token"))

			for _, msg := range messagesToSend {
				conn.Write(msg)
			}
			time.Sleep(time.Duration(50) * time.Millisecond)
			conn.Close()
		}

		testServer = httptest.NewTLSServer(websocket.Handler(requestHandler.handlerFunc))

		configRepo = testconfig.NewRepositoryWithDefaults()
		configRepo.SetApiEndpoint("https://localhost")
		configRepo.SetLoggregatorEndpoint(strings.Replace(testServer.URL, "https", "wss", 1))

		repo := NewLoggregatorLogsRepository(configRepo)
		logsRepo = &repo
		logsRepo.AddTrustedCerts(testServer.TLS.Certificates)
	})

	AfterEach(func() {
		testServer.Close()
	})

	Describe("RecentLogsFor", func() {
		BeforeEach(func() {
			err := logsRepo.RecentLogsFor("my-app-guid", func() {}, logChan)
			Expect(err).NotTo(HaveOccurred())
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:logs_test.go

示例10:

		config.SetApiVersion("2.2.0")
	})

	JustBeforeEach(func() {
		strategy := strategy.NewEndpointStrategy(config.ApiVersion())
		gateway := net.NewCloudControllerGateway(config)
		repo = NewCloudControllerAppEventsRepository(config, gateway, strategy)
	})

	AfterEach(func() {
		server.Close()
	})

	setupTestServer := func(requests ...testnet.TestRequest) {
		server, handler = testnet.NewServer(requests)
		config.SetApiEndpoint(server.URL)
	}

	Describe("list recent events", func() {
		It("returns the most recent events", func() {
			setupTestServer(eventsRequest)

			list, err := repo.RecentEvents("my-app-guid", 2)
			Expect(err).ToNot(HaveOccurred())

			Expect(list).To(Equal([]models.EventFields{
				models.EventFields{
					Guid:        "event-1-guid",
					Name:        "audit.app.update",
					Timestamp:   testtime.MustParse(eventTimestampFormat, "2014-01-21T00:20:11+00:00"),
					Description: "instances: 1, memory: 256, command: PRIVATE DATA HIDDEN, environment_json: PRIVATE DATA HIDDEN",
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:app_events_test.go

示例11:

		uaaGateway := net.NewUAAGateway(config)
		repo = NewCloudControllerUserRepository(config, uaaGateway, ccGateway)
	})

	AfterEach(func() {
		if uaaServer != nil {
			uaaServer.Close()
		}
		if ccServer != nil {
			ccServer.Close()
		}
	})

	setupCCServer := func(requests ...testnet.TestRequest) {
		ccServer, ccHandler = testnet.NewServer(requests)
		config.SetApiEndpoint(ccServer.URL)
	}

	setupUAAServer := func(requests ...testnet.TestRequest) {
		uaaServer, uaaHandler = testnet.NewServer(requests)
		config.SetUaaEndpoint(uaaServer.URL)
	}

	Describe("listing the users with a given role", func() {
		It("lists the users in an organization with a given role", func() {
			ccReqs, uaaReqs := createUsersByRoleEndpoints("/v2/organizations/my-org-guid/managers")

			setupCCServer(ccReqs...)
			setupUAAServer(uaaReqs...)

			users, apiErr := repo.ListUsersInOrgForRole("my-org-guid", models.ORG_MANAGER)
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:users_test.go

示例12:

				Expect(Config.OrganizationFields().Guid).To(Equal("my-org-guid"))
				Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
				Expect(Config.AccessToken()).To(Equal("my_access_token"))
				Expect(Config.RefreshToken()).To(Equal("my_refresh_token"))

				Expect(endpointRepo.UpdateEndpointReceived).To(Equal("api.example.com"))
				Expect(authRepo.AuthenticateArgs.Credentials).To(Equal(map[string]string{
					"username": "[email protected]",
					"password": "password",
				}))

				Expect(ui.ShowConfigurationCalled).To(BeTrue())
			})

			It("doesn't ask the user for the API url if they have it in their config", func() {
				Config.SetApiEndpoint("http://api.example.com")

				Flags = []string{"-o", "my-org", "-s", "my-space"}
				ui.Inputs = []string{"[email protected]", "password"}

				l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
				testcmd.RunCommand(l, testcmd.NewContext("login", Flags), nil)

				Expect(Config.ApiEndpoint()).To(Equal("http://api.example.com"))
				Expect(Config.OrganizationFields().Guid).To(Equal("my-org-guid"))
				Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
				Expect(Config.AccessToken()).To(Equal("my_access_token"))
				Expect(Config.RefreshToken()).To(Equal("my_refresh_token"))

				Expect(endpointRepo.UpdateEndpointReceived).To(Equal("http://api.example.com"))
				Expect(authRepo.AuthenticateArgs.Credentials).To(Equal(map[string]string{
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:31,代碼來源:login_test.go

示例13:

		repo    BuildpackRepository
	)

	BeforeEach(func() {
		config = testconfig.NewRepositoryWithDefaults()
		gateway := net.NewCloudControllerGateway(config)
		repo = NewCloudControllerBuildpackRepository(config, gateway)
	})

	AfterEach(func() {
		ts.Close()
	})

	var setupTestServer = func(requests ...testnet.TestRequest) {
		ts, handler = testnet.NewServer(requests)
		config.SetApiEndpoint(ts.URL)
	}

	It("lists buildpacks", func() {
		setupTestServer(
			testapi.NewCloudControllerTestRequest(testnet.TestRequest{
				Method: "GET",
				Path:   "/v2/buildpacks",
				Response: testnet.TestResponse{
					Status: http.StatusOK,
					Body: `{
					  "next_url": "/v2/buildpacks?page=2",
					  "resources": [
						{
						  "metadata": {
							"guid": "buildpack1-guid"
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:buildpacks_test.go


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