本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/configuration.ReadWriter.SetOrganizationFields方法的典型用法代碼示例。如果您正苦於以下問題:Golang ReadWriter.SetOrganizationFields方法的具體用法?Golang ReadWriter.SetOrganizationFields怎麽用?Golang ReadWriter.SetOrganizationFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/configuration.ReadWriter
的用法示例。
在下文中一共展示了ReadWriter.SetOrganizationFields方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
It("fails when the organization is not found", func() {
orgRepo.FindByNameNotFound = true
callTarget([]string{"-o", "my-organization"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"my-organization", "not found"},
))
expectOrgToBeCleared()
expectSpaceToBeCleared()
})
It("fails to target a space if no organization is targeted", func() {
config.SetOrganizationFields(models.OrganizationFields{})
callTarget([]string{"-s", "my-space"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"An org must be targeted before targeting a space"},
))
expectSpaceToBeCleared()
})
It("fails when the user doesn't have access to the space", func() {
spaceRepo.FindByNameErr = true
callTarget([]string{"-s", "my-space"})
示例2:
testapi "github.com/cloudfoundry/cli/testhelpers/api"
testassert "github.com/cloudfoundry/cli/testhelpers/assert"
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Testing with ginkgo", func() {
var config configuration.ReadWriter
var ui *testterm.FakeUI
BeforeEach(func() {
ui = new(testterm.FakeUI)
config = testconfig.NewRepository()
config.SetOrganizationFields(models.OrganizationFields{Guid: "the-org-guid"})
})
It("succeeds when the domain is found", func() {
domain := models.DomainFields{Name: "example.com", Guid: "domain-guid"}
domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgDomain: domain}
domainReq := NewDomainRequirement("example.com", ui, config, domainRepo)
success := domainReq.Execute()
Expect(success).To(BeTrue())
Expect(domainRepo.FindByNameInOrgName).To(Equal("example.com"))
Expect(domainRepo.FindByNameInOrgGuid).To(Equal("the-org-guid"))
Expect(domainReq.GetDomain()).To(Equal(domain))
})
It("fails when the domain is not found", func() {
示例3:
})
Describe("updating the endpoints", func() {
Context("when the API request is successful", func() {
var (
org models.OrganizationFields
space models.SpaceFields
)
BeforeEach(func() {
org.Name = "my-org"
org.Guid = "my-org-guid"
space.Name = "my-space"
space.Guid = "my-space-guid"
config.SetOrganizationFields(org)
config.SetSpaceFields(space)
testServerFn = validApiInfoEndpoint
})
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())
})
示例4:
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("fails with usage if no arguments are given", func() {
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
})
Context("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
})
Context("when deleting the currently targeted org", func() {
It("untargets the deleted org", func() {
config.SetOrganizationFields(org.OrganizationFields)
runCommand("org-to-delete")
Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{}))
Expect(config.SpaceFields()).To(Equal(models.SpaceFields{}))
})
})
Context("when deleting an org that is not targeted", func() {
BeforeEach(func() {
otherOrgFields := models.OrganizationFields{}
otherOrgFields.Guid = "some-other-org-guid"
otherOrgFields.Name = "some-other-org"
config.SetOrganizationFields(otherOrgFields)
spaceFields := models.SpaceFields{}
示例5:
callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
})
It("renames an organization", func() {
targetedOrgName := configRepo.OrganizationFields().Name
callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Renaming org", "the-old-org-name", "the-new-org-name", "my-user"},
[]string{"OK"},
))
Expect(requirementsFactory.OrganizationName).To(Equal("the-old-org-name"))
Expect(orgRepo.RenameOrganizationGuid).To(Equal("the-old-org-guid"))
Expect(orgRepo.RenameNewName).To(Equal("the-new-org-name"))
Expect(configRepo.OrganizationFields().Name).To(Equal(targetedOrgName))
})
Describe("when the organization is currently targeted", func() {
It("updates the name of the org in the config", func() {
configRepo.SetOrganizationFields(models.OrganizationFields{
Guid: "the-old-org-guid",
Name: "the-old-org-name",
})
callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})
Expect(configRepo.OrganizationFields().Name).To(Equal("the-new-org-name"))
})
})
})
})
示例6:
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("fails with usage if no arguments are given", func() {
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
})
Context("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
})
Context("when deleting the currently targeted org", func() {
It("untargets the deleted org", func() {
config.SetOrganizationFields(orgRepo.Organizations[0].OrganizationFields)
runCommand("org-to-delete")
Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{}))
Expect(config.SpaceFields()).To(Equal(models.SpaceFields{}))
})
})
Context("when deleting an org that is not targeted", func() {
BeforeEach(func() {
otherOrgFields := models.OrganizationFields{}
otherOrgFields.Guid = "some-other-org-guid"
otherOrgFields.Name = "some-other-org"
config.SetOrganizationFields(otherOrgFields)
spaceFields := models.SpaceFields{}
示例7:
It("tells the user which api endpoint is set", func() {
Expect(output).To(ContainSubstrings([]string{"API endpoint:", "https://test.example.org"}))
})
It("tells the user the api version", func() {
Expect(output).To(ContainSubstrings([]string{"API version:", "☃☃☃"}))
})
It("tells the user which user is logged in", func() {
Expect(output).To(ContainSubstrings([]string{"User:", "my-user-email"}))
})
Context("when an org is targeted", func() {
BeforeEach(func() {
config.SetOrganizationFields(models.OrganizationFields{
Name: "org-name",
Guid: "org-guid",
})
})
It("tells the user which org is targeted", func() {
Expect(output).To(ContainSubstrings([]string{"Org:", "org-name"}))
})
})
Context("when a space is targeted", func() {
BeforeEach(func() {
config.SetSpaceFields(models.SpaceFields{
Name: "my-space",
Guid: "space-guid",
})
})