本文整理匯總了Golang中cf/models.Organization.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang Organization.Name方法的具體用法?Golang Organization.Name怎麽用?Golang Organization.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cf/models.Organization
的用法示例。
在下文中一共展示了Organization.Name方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setUpLoginTestContext
func setUpLoginTestContext() (c *LoginTestContext) {
c = new(LoginTestContext)
c.Config = testconfig.NewRepository()
c.ui = &testterm.FakeUI{}
c.authRepo = &testapi.FakeAuthenticationRepository{
AccessToken: "my_access_token",
RefreshToken: "my_refresh_token",
Config: c.Config,
}
c.endpointRepo = &testapi.FakeEndpointRepo{Config: c.Config}
org := models.Organization{}
org.Name = "my-org"
org.Guid = "my-org-guid"
c.orgRepo = &testapi.FakeOrgRepository{
Organizations: []models.Organization{org},
}
space := models.Space{}
space.Name = "my-space"
space.Guid = "my-space-guid"
c.spaceRepo = &testapi.FakeSpaceRepository{
Spaces: []models.Space{space},
}
return
}
示例2:
})
Context("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
})
It("passes requirements when provided two args", func() {
runCommand("my-org", "my-quota")
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
Expect(requirementsFactory.OrganizationName).To(Equal("my-org"))
})
It("assigns a quota to an org", func() {
org := models.Organization{}
org.Name = "my-org"
org.Guid = "my-org-guid"
quota := models.QuotaFields{Name: "my-quota", Guid: "my-quota-guid"}
quotaRepo.FindByNameReturns.Quota = quota
requirementsFactory.Organization = org
runCommand("my-org", "my-quota")
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Setting quota", "my-quota", "my-org", "my-user"},
{"OK"},
})
Expect(quotaRepo.FindByNameCalledWith.Name).To(Equal("my-quota"))
示例3:
import (
"cf/models"
. "cf/requirements"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
testapi "testhelpers/api"
testassert "testhelpers/assert"
testterm "testhelpers/terminal"
)
var _ = Describe("Testing with ginkgo", func() {
It("TestOrgReqExecute", func() {
org := models.Organization{}
org.Name = "my-org-name"
org.Guid = "my-org-guid"
orgRepo := &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
ui := new(testterm.FakeUI)
orgReq := NewOrganizationRequirement("my-org-name", ui, orgRepo)
success := orgReq.Execute()
Expect(success).To(BeTrue())
Expect(orgRepo.FindByNameName).To(Equal("my-org-name"))
Expect(orgReq.GetOrganization()).To(Equal(org))
})
It("TestOrgReqWhenOrgDoesNotExist", func() {
orgRepo := &testapi.FakeOrgRepository{FindByNameNotFound: true}
示例4: callCreateDomain
requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true}
domainRepo := &testapi.FakeDomainRepository{}
ui := callCreateDomain([]string{""}, requirementsFactory, domainRepo)
Expect(ui.FailedWithUsage).To(BeTrue())
ui = callCreateDomain([]string{"org1"}, requirementsFactory, domainRepo)
Expect(ui.FailedWithUsage).To(BeTrue())
ui = callCreateDomain([]string{"org1", "example.com"}, requirementsFactory, domainRepo)
Expect(ui.FailedWithUsage).To(BeFalse())
})
It("TestCreateDomain", func() {
org := models.Organization{}
org.Name = "myOrg"
org.Guid = "myOrg-guid"
requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, Organization: org}
domainRepo := &testapi.FakeDomainRepository{}
ui := callCreateDomain([]string{"myOrg", "example.com"}, requirementsFactory, domainRepo)
Expect(domainRepo.CreateDomainName).To(Equal("example.com"))
Expect(domainRepo.CreateDomainOwningOrgGuid).To(Equal("myOrg-guid"))
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Creating domain", "example.com", "myOrg", "my-user"},
{"OK"},
})
})
})
func callCreateDomain(args []string, requirementsFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (fakeUI *testterm.FakeUI) {
示例5:
"metadata": { "guid": "space1-guid" },
"entity": { "name": "Space1" }
}],
"domains": [{
"metadata": { "guid": "domain1-guid" },
"entity": { "name": "cfapps.io" }
}]
}
}]}`},
})
ts, handler, repo := createOrganizationRepo(req)
defer ts.Close()
existingOrg := models.Organization{}
existingOrg.Guid = "org1-guid"
existingOrg.Name = "Org1"
org, apiErr := repo.FindByName("Org1")
Expect(handler).To(testnet.HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
Expect(org.Name).To(Equal(existingOrg.Name))
Expect(org.Guid).To(Equal(existingOrg.Guid))
Expect(org.QuotaDefinition.Name).To(Equal("not-your-average-quota"))
Expect(org.QuotaDefinition.MemoryLimit).To(Equal(uint64(128)))
Expect(len(org.Spaces)).To(Equal(1))
Expect(org.Spaces[0].Name).To(Equal("Space1"))
Expect(org.Spaces[0].Guid).To(Equal("space1-guid"))
Expect(len(org.Domains)).To(Equal(1))
Expect(org.Domains[0].Name).To(Equal("cfapps.io"))
Expect(org.Domains[0].Guid).To(Equal("domain1-guid"))
示例6:
Context("when the user logs in successfully", func() {
BeforeEach(func() {
reqFactory.LoginSuccess = true
})
It("passes requirements when targeting a space or org", func() {
callTarget([]string{"-s", "i-love-space"}, reqFactory, config, orgRepo, spaceRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
callTarget([]string{"-o", "orgs-are-delightful"}, reqFactory, config, orgRepo, spaceRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
})
It("TestTargetOrganizationWhenUserHasAccess", func() {
org := models.Organization{}
org.Name = "my-organization"
org.Guid = "my-organization-guid"
orgRepo.Organizations = []models.Organization{org}
orgRepo.FindByNameOrganization = org
ui := callTarget([]string{"-o", "my-organization"}, reqFactory, config, orgRepo, spaceRepo)
Expect(orgRepo.FindByNameName).To(Equal("my-organization"))
Expect(ui.ShowConfigurationCalled).To(BeTrue())
Expect(config.OrganizationFields().Guid).To(Equal("my-organization-guid"))
})
It("TestTargetOrganizationWhenUserDoesNotHaveAccess", func() {
orgs := []models.Organization{}
示例7:
spaceRepo *testapi.FakeSpaceRepository
)
BeforeEach(func() {
Flags = []string{}
Config = testconfig.NewRepository()
ui = &testterm.FakeUI{}
authRepo = &testapi.FakeAuthenticationRepository{
AccessToken: "my_access_token",
RefreshToken: "my_refresh_token",
Config: Config,
}
endpointRepo = &testapi.FakeEndpointRepo{}
org := models.Organization{}
org.Name = "my-new-org"
org.Guid = "my-new-org-guid"
orgRepo = &testapi.FakeOrgRepository{
Organizations: []models.Organization{org},
FindByNameOrganization: models.Organization{},
}
space := models.Space{}
space.Guid = "my-space-guid"
space.Name = "my-space"
spaceRepo = &testapi.FakeSpaceRepository{
Spaces: []models.Space{space},
}
示例8:
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
requirementsFactory.LoginSuccess = true
callUnsetSpaceRole(args, spaceRepo, userRepo, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
Expect(requirementsFactory.UserUsername).To(Equal("username"))
Expect(requirementsFactory.OrganizationName).To(Equal("org"))
})
It("TestUnsetSpaceRole", func() {
user := models.UserFields{}
user.Username = "some-user"
user.Guid = "some-user-guid"
org := models.Organization{}
org.Name = "some-org"
org.Guid = "some-org-guid"
requirementsFactory, spaceRepo, userRepo := getUnsetSpaceRoleDeps()
requirementsFactory.LoginSuccess = true
requirementsFactory.UserFields = user
requirementsFactory.Organization = org
spaceRepo.FindByNameInOrgSpace = models.Space{}
spaceRepo.FindByNameInOrgSpace.Name = "some-space"
spaceRepo.FindByNameInOrgSpace.Guid = "some-space-guid"
args := []string{"my-username", "my-org", "my-space", "SpaceManager"}
ui := callUnsetSpaceRole(args, spaceRepo, userRepo, requirementsFactory)
Expect(spaceRepo.FindByNameInOrgName).To(Equal("my-space"))
示例9:
orgRepo = &testapi.FakeOrgRepository{}
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
})
Describe("requirements", func() {
It("fails when not logged in", func() {
requirementsFactory.LoginSuccess = false
runCommand()
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
})
Context("when there are orgs to be listed", func() {
BeforeEach(func() {
org1 := models.Organization{}
org1.Name = "Organization-1"
org2 := models.Organization{}
org2.Name = "Organization-2"
org3 := models.Organization{}
org3.Name = "Organization-3"
orgRepo.Organizations = []models.Organization{org1, org2, org3}
})
It("lists orgs", func() {
runCommand()
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Getting orgs as my-user"},
示例10:
var (
config configuration.ReadWriter
ui *testterm.FakeUI
requirementsFactory *testreq.FakeReqFactory
orgRepo *testapi.FakeOrgRepository
)
BeforeEach(func() {
ui = &testterm.FakeUI{
Inputs: []string{"y"},
}
config = testconfig.NewRepositoryWithDefaults()
requirementsFactory = &testreq.FakeReqFactory{}
org := models.Organization{}
org.Name = "org-to-delete"
org.Guid = "org-to-delete-guid"
orgRepo = &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
})
runCommand := func(args ...string) {
cmd := NewDeleteOrg(ui, config, orgRepo)
testcmd.RunCommand(cmd, testcmd.NewContext("delete-org", args), requirementsFactory)
}
It("fails requirements when not logged in", func() {
runCommand("some-org-name")
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
示例11:
callRenameOrg([]string{})
Expect(ui.FailedWithUsage).To(BeTrue())
callRenameOrg([]string{"foo"})
Expect(ui.FailedWithUsage).To(BeTrue())
})
It("fails requirements when not logged in", func() {
callRenameOrg([]string{"my-org", "my-new-org"})
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
Context("when logged in and given an org to rename", func() {
BeforeEach(func() {
org := models.Organization{}
org.Name = "the-old-org-name"
org.Guid = "the-old-org-guid"
requirementsFactory.Organization = org
requirementsFactory.LoginSuccess = true
})
It("passes requirements", func() {
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"})
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Renaming org", "the-old-org-name", "the-new-org-name", "my-user"},
示例12:
args := []string{"Org1"}
requirementsFactory.LoginSuccess = false
callOrgUsers(args, requirementsFactory, userRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
requirementsFactory.LoginSuccess = true
callOrgUsers(args, requirementsFactory, userRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
Expect("Org1").To(Equal(requirementsFactory.OrganizationName))
})
It("TestOrgUsers", func() {
org := models.Organization{}
org.Name = "Found Org"
org.Guid = "found-org-guid"
userRepo := &testapi.FakeUserRepository{}
user := models.UserFields{}
user.Username = "user1"
user2 := models.UserFields{}
user2.Username = "user2"
user3 := models.UserFields{}
user3.Username = "user3"
user4 := models.UserFields{}
user4.Username = "user4"
userRepo.ListUsersByRole = map[string][]models.UserFields{
models.ORG_MANAGER: []models.UserFields{user, user2},
models.BILLING_MANAGER: []models.UserFields{user4},
models.ORG_AUDITOR: []models.UserFields{user3},
示例13:
args := []string{"my-org", "my-space"}
requirementsFactory.LoginSuccess = false
callSpaceUsers(args, requirementsFactory, spaceRepo, userRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
requirementsFactory.LoginSuccess = true
callSpaceUsers(args, requirementsFactory, spaceRepo, userRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
Expect("my-org").To(Equal(requirementsFactory.OrganizationName))
})
It("TestSpaceUsers", func() {
org := models.Organization{}
org.Name = "Org1"
org.Guid = "org1-guid"
space := models.Space{}
space.Name = "Space1"
space.Guid = "space1-guid"
requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, Organization: org}
spaceRepo := &testapi.FakeSpaceRepository{FindByNameInOrgSpace: space}
userRepo := &testapi.FakeUserRepository{}
user := models.UserFields{}
user.Username = "user1"
user2 := models.UserFields{}
user2.Username = "user2"
user3 := models.UserFields{}
user3.Username = "user3"