本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/configuration.ReadWriter.SetApiEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Golang ReadWriter.SetApiEndpoint方法的具体用法?Golang ReadWriter.SetApiEndpoint怎么用?Golang ReadWriter.SetApiEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/cli/cf/configuration.ReadWriter
的用法示例。
在下文中一共展示了ReadWriter.SetApiEndpoint方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
repo BuildpackRepository
)
BeforeEach(func() {
config = testconfig.NewRepositoryWithDefaults()
gateway := net.NewCloudControllerGateway((config), time.Now)
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"
示例2:
"net/http"
"net/http/httptest"
"time"
)
var _ = Describe("Testing with ginkgo", func() {
var (
testServer *httptest.Server
testHandler *testnet.TestHandler
configRepo configuration.ReadWriter
repo CloudControllerServiceBindingRepository
)
setupTestServer := func(reqs ...testnet.TestRequest) {
testServer, testHandler = testnet.NewServer(reqs)
configRepo.SetApiEndpoint(testServer.URL)
}
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
gateway := net.NewCloudControllerGateway((configRepo), time.Now)
repo = NewCloudControllerServiceBindingRepository(configRepo, gateway)
})
AfterEach(func() {
testServer.Close()
})
Describe("Create", func() {
Context("when the service binding can be created", func() {
示例3:
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() {
Context("when there are no users in the given org", func() {
It("lists the users in a org with a given role", func() {
ccReqs := []testnet.TestRequest{
testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations/my-org-guid/managers",
Response: testnet.TestResponse{
示例4:
[]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() {
var (
ui *testterm.FakeUI
requirementsFactory *testreq.FakeReqFactory
)
BeforeEach(func() {
config.SetApiEndpoint("https://api.run.pivotal.io")
config.SetApiVersion("2.0")
config.SetSSLDisabled(true)
ui = new(testterm.FakeUI)
requirementsFactory = &testreq.FakeReqFactory{}
})
JustBeforeEach(func() {
testcmd.RunCommand(NewApi(ui, config, endpointRepo), []string{}, requirementsFactory)
})
It("prints out the api endpoint", func() {
Expect(ui.Outputs).To(ContainSubstrings([]string{"https://api.run.pivotal.io", "2.0"}))
})
示例5:
config.SetApiVersion("2.2.0")
})
JustBeforeEach(func() {
strategy := strategy.NewEndpointStrategy(config.ApiVersion())
gateway := net.NewCloudControllerGateway(config, time.Now)
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(ConsistOf([]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",
示例6:
It("stores the data from the /info api in the config", func() {
repo.UpdateEndpoint(testServer.URL)
Expect(config.AccessToken()).To(Equal(""))
Expect(config.AuthenticationEndpoint()).To(Equal("https://login.example.com"))
Expect(config.LoggregatorEndpoint()).To(Equal("wss://loggregator.foo.example.org:4443"))
Expect(config.ApiEndpoint()).To(Equal(testServer.URL))
Expect(config.ApiVersion()).To(Equal("42.0.0"))
Expect(config.HasOrganization()).To(BeFalse())
Expect(config.HasSpace()).To(BeFalse())
})
Context("when the api endpoint does not change", func() {
BeforeEach(func() {
config.SetApiEndpoint(testServer.URL)
config.SetAccessToken("some access token")
config.SetRefreshToken("some refresh token")
})
It("does not clear the session if the api endpoint does not change", func() {
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"))
})
})
})
示例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"}
l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
testcmd.RunCommand(l, 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())
示例8:
Expect(output).ToNot(ContainSubstrings([]string{"API endpoint:"}))
Expect(output).To(ContainSubstrings([]string{"Not logged in", "Use", "log in"}))
})
})
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 = io_helpers.CaptureOutput(func() {
ui := NewUI(os.Stdin)
ui.ShowConfiguration(config)
})
})
It("tells the user which api endpoint is set", func() {
Expect(output).To(ContainSubstrings([]string{"API endpoint:", "https://test.example.org"}))
示例9:
It("fails with usage when given too few arguments", func() {
testcmd.RunCommand(cmd, []string{}, requirementsFactory)
Expect(ui.FailedWithUsage).To(BeTrue())
})
It("fails if the user has not set an api endpoint", func() {
testcmd.RunCommand(cmd, []string{"username", "password"}, 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
testcmd.RunCommand(cmd, []string{"[email protected]", "password"}, requirementsFactory)
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]",