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


Golang Repository.SetApiEndpoint方法代碼示例

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


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

示例1:

					Expect(result).To(Equal("doppler-endpoint-sample"))
				})
			})

			Context(".ApiEndpoint, .ApiVersion and .HasAPIEndpoint", func() {
				BeforeEach(func() {
					rpcService, err = NewRpcService(nil, nil, nil, config)
					err := rpcService.Start()
					Expect(err).ToNot(HaveOccurred())

					pingCli(rpcService.Port())
				})

				It("returns the ApiEndpoint(), ApiVersion() and HasAPIEndpoint() setting in config", func() {
					config.SetApiVersion("v1.1.1")
					config.SetApiEndpoint("www.fake-domain.com")

					client, err = rpc.Dial("tcp", "127.0.0.1:"+rpcService.Port())
					Expect(err).ToNot(HaveOccurred())

					var result string
					err = client.Call("CliRpcCmd.ApiEndpoint", "", &result)
					Expect(err).ToNot(HaveOccurred())
					Expect(result).To(Equal("www.fake-domain.com"))

					err = client.Call("CliRpcCmd.ApiVersion", "", &result)
					Expect(err).ToNot(HaveOccurred())
					Expect(result).To(Equal("v1.1.1"))

					var exists bool
					err = client.Call("CliRpcCmd.HasAPIEndpoint", "", &exists)
開發者ID:swisscom,項目名稱:cf-statistics-plugin,代碼行數:31,代碼來源:cli_rpc_server_test.go

示例2:

				testServer.Close()
			})

			Context("error when getting SSH info from /v2/info", func() {
				BeforeEach(func() {
					getRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
						Method: "GET",
						Path:   "/v2/info",
						Response: testnet.TestResponse{
							Status: http.StatusNotFound,
							Body:   `{}`,
						},
					})

					testServer, handler = testnet.NewServer([]testnet.TestRequest{getRequest})
					configRepo.SetApiEndpoint(testServer.URL)
					ccGateway = net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
					deps.Gateways["cloud-controller"] = ccGateway
				})

				It("notifies users", func() {
					runCommand("my-app")

					Expect(handler).To(HaveAllRequestsCalled())
					Ω(ui.Outputs).To(ContainSubstrings(
						[]string{"Error getting SSH info", "404"},
					))
				})
			})

			Context("error when getting oauth token", func() {
開發者ID:vframbach,項目名稱:cli,代碼行數:31,代碼來源:ssh_test.go

示例3:

	It("is threadsafe", func() {
		performSaveCh := make(chan struct{})
		beginSaveCh := make(chan struct{})
		finishSaveCh := make(chan struct{})
		finishReadCh := make(chan struct{})

		persistor.SaveStub = func(configuration.DataInterface) error {
			close(beginSaveCh)
			<-performSaveCh
			close(finishSaveCh)

			return nil
		}

		go func() {
			config.SetApiEndpoint("foo")
		}()

		<-beginSaveCh

		go func() {
			config.ApiEndpoint()
			close(finishReadCh)
		}()

		Consistently(finishSaveCh).ShouldNot(BeClosed())
		Consistently(finishReadCh).ShouldNot(BeClosed())

		performSaveCh <- struct{}{}

		Eventually(finishReadCh).Should(BeClosed())
開發者ID:vframbach,項目名稱:cli,代碼行數:31,代碼來源:config_repository_test.go

示例4:

			testcmd.RunCliCommand("auth", []string{}, requirementsFactory, updateCommandDependency, false)

			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Incorrect Usage", "Requires", "arguments"},
			))
		})

		It("fails if the user has not set an api endpoint", func() {
			Expect(testcmd.RunCliCommand("auth", []string{"username", "password"}, requirementsFactory, updateCommandDependency, false)).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
			testcmd.RunCliCommand("auth", []string{"[email protected]", "password"}, requirementsFactory, updateCommandDependency, false)

			Expect(ui.FailedWithUsage).To(BeFalse())
			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"foo.example.org/authenticate"},
				[]string{"OK"},
			))

			Expect(repo.AuthenticateArgs.Credentials).To(Equal([]map[string]string{
				{
					"username": "[email protected]",
開發者ID:vframbach,項目名稱:cli,代碼行數:31,代碼來源:auth_test.go

示例5:

		It("fails if the user has not set an api endpoint", func() {
			requirementsFactory.ApiEndpointSuccess = false

			Ω(runCommand()).To(BeFalse())
		})
	})

	Describe("ssh-code", func() {
		BeforeEach(func() {
			requirementsFactory.ApiEndpointSuccess = true
		})

		Context("calling endpoint repository to update 'app_ssh_oauth_client'", func() {
			It("passes the repo the targeted API endpoint", func() {
				configRepo.SetApiEndpoint("test.endpoint.com")

				runCommand()
				Ω(endpointRepo.CallCount).To(Equal(1))
				Ω(endpointRepo.UpdateEndpointReceived).To(Equal(configRepo.ApiEndpoint()))
			})

			It("reports any error to user", func() {
				configRepo.SetApiEndpoint("test.endpoint.com")
				endpointRepo.UpdateEndpointError = errors.New("endpoint error")

				runCommand()
				Ω(endpointRepo.CallCount).To(Equal(1))
				Ω(ui.Outputs).To(ContainSubstrings(
					[]string{"Error getting info", "endpoint error"},
				))
開發者ID:vframbach,項目名稱:cli,代碼行數:30,代碼來源:ssh_code_test.go

示例6:

	. "github.com/cloudfoundry/cli/testhelpers/matchers"
)

var _ = Describe("ApiEndpointRequirement", func() {
	var (
		ui     *testterm.FakeUI
		config core_config.Repository
	)

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
		config = testconfig.NewRepository()
	})

	It("succeeds when given a config with an API endpoint", func() {
		config.SetApiEndpoint("api.example.com")
		req := NewApiEndpointRequirement(ui, config)
		success := req.Execute()
		Expect(success).To(BeTrue())
	})

	It("fails when given a config without an API endpoint", func() {
		req := NewApiEndpointRequirement(ui, config)
		success := req.Execute()
		Expect(success).To(BeFalse())

		Expect(ui.Outputs).To(ContainSubstrings([]string{"No API endpoint"}))
	})
})
開發者ID:vframbach,項目名稱:cli,代碼行數:29,代碼來源:api_endpoint_test.go

示例7:

				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() {
				orgRepo.FindByNameReturns(org, nil)
				Config.SetApiEndpoint("http://api.example.com")

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

				testcmd.RunCliCommand("login", Flags, nil, updateCommandDependency, false)

				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:vframbach,項目名稱:cli,代碼行數:31,代碼來源:login_test.go

示例8:

		It("warns the user and prints out a tip", func() {
			endpointRepo.UpdateEndpointError = errors.NewInvalidSSLCert("https://buttontomatoes.org", "why? no. go away")
			callApi([]string{"https://buttontomatoes.org"}, config, endpointRepo)

			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"FAILED"},
				[]string{"SSL Cert", "https://buttontomatoes.org"},
				[]string{"TIP", "--skip-ssl-validation"},
			))
		})
	})

	Context("when the user does not provide an endpoint", func() {
		Context("when the endpoint is set in the config", func() {
			BeforeEach(func() {
				config.SetApiEndpoint("https://api.run.pivotal.io")
				config.SetApiVersion("2.0")
				config.SetSSLDisabled(true)
			})

			It("prints out the api endpoint and appropriately sets the config", func() {
				callApi([]string{}, config, endpointRepo)

				Expect(ui.Outputs).To(ContainSubstrings([]string{"https://api.run.pivotal.io", "2.0"}))
				Expect(config.IsSSLDisabled()).To(BeTrue())
			})

			Context("when the --unset flag is passed", func() {
				It("unsets the ApiEndpoint", func() {
					callApi([]string{"--unset"}, config, endpointRepo)
開發者ID:vframbach,項目名稱:cli,代碼行數:30,代碼來源:api_test.go

示例9:

	Describe("List routes", func() {
		It("lists routes in the current space", func() {
			ts, handler = testnet.NewServer([]testnet.TestRequest{
				testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
					Path:     "/v2/spaces/the-space-guid/routes?inline-relations-depth=1",
					Response: firstPageRoutesResponse,
				}),
				testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
					Path:     "/v2/spaces/the-space-guid/routes?inline-relations-depth=1&page=2",
					Response: secondPageRoutesResponse,
				}),
			})
			configRepo.SetApiEndpoint(ts.URL)

			routes := []models.Route{}
			apiErr := repo.ListRoutes(func(route models.Route) bool {
				routes = append(routes, route)
				return true
			})

			Expect(len(routes)).To(Equal(2))
			Expect(routes[0].Guid).To(Equal("route-1-guid"))
			Expect(routes[1].Guid).To(Equal("route-2-guid"))
			Expect(handler).To(HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())
		})

		It("lists routes from all the spaces of current org", func() {
開發者ID:Doebe,項目名稱:workplace,代碼行數:30,代碼來源:routes_test.go

示例10:

	Describe("List routes", func() {
		It("lists routes in the current space", func() {
			ts, handler = testnet.NewServer([]testnet.TestRequest{
				testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
					Path:     "/v2/spaces/the-space-guid/routes?inline-relations-depth=1",
					Response: firstPageRoutesResponse,
				}),
				testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
					Path:     "/v2/spaces/the-space-guid/routes?inline-relations-depth=1&page=2",
					Response: secondPageRoutesResponse,
				}),
			})
			configRepo.SetApiEndpoint(ts.URL)

			routes := []models.Route{}
			apiErr := repo.ListRoutes(func(route models.Route) bool {
				routes = append(routes, route)
				return true
			})

			Expect(len(routes)).To(Equal(2))
			Expect(routes[0].Guid).To(Equal("route-1-guid"))
			Expect(routes[0].Path).To(Equal(""))
			Expect(routes[0].ServiceInstance.Guid).To(Equal("service-guid"))
			Expect(routes[0].ServiceInstance.Name).To(Equal("test-service"))
			Expect(routes[1].Guid).To(Equal("route-2-guid"))
			Expect(routes[1].Path).To(Equal("/path-2"))
			Expect(handler).To(HaveAllRequestsCalled())
開發者ID:plamenai,項目名稱:cli,代碼行數:30,代碼來源:routes_test.go

示例11:

		authRepo     *authenticationfakes.FakeAuthenticationRepository
		endpointRepo *testapi.FakeEndpointRepository

		cmd         command_registry.Command
		deps        command_registry.Dependency
		factory     *fakerequirements.FakeFactory
		flagContext flags.FlagContext

		endpointRequirement requirements.Requirement
	)

	BeforeEach(func() {
		ui = &testterm.FakeUI{}

		configRepo = testconfig.NewRepositoryWithDefaults()
		configRepo.SetApiEndpoint("fake-api-endpoint")
		endpointRepo = &testapi.FakeEndpointRepository{}
		repoLocator := deps.RepoLocator.SetEndpointRepository(endpointRepo)
		authRepo = &authenticationfakes.FakeAuthenticationRepository{}
		repoLocator = repoLocator.SetAuthenticationRepository(authRepo)

		deps = command_registry.Dependency{
			Ui:          ui,
			Config:      configRepo,
			RepoLocator: repoLocator,
		}

		cmd = &commands.OneTimeSSHCode{}
		cmd.SetDependency(deps, false)

		flagContext = flags.NewFlagContext(cmd.MetaData().Flags)
開發者ID:chavdarch,項目名稱:cli,代碼行數:31,代碼來源:ssh_code_test.go


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