本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/api/organizations/fakes.FakeOrganizationRepository.FindByNameReturns方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeOrganizationRepository.FindByNameReturns方法的具體用法?Golang FakeOrganizationRepository.FindByNameReturns怎麽用?Golang FakeOrganizationRepository.FindByNameReturns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/api/organizations/fakes.FakeOrganizationRepository
的用法示例。
在下文中一共展示了FakeOrganizationRepository.FindByNameReturns方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
)
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 = &test_org.FakeOrganizationRepository{}
orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
orgRepo.FindByNameReturns(org, nil)
})
runCommand := func(args ...string) bool {
cmd := NewDeleteOrg(ui, config, orgRepo)
return testcmd.RunCommand(cmd, args, requirementsFactory)
}
It("fails requirements when not logged in", func() {
Expect(runCommand("some-org-name")).To(BeFalse())
})
It("fails with usage if no arguments are given", func() {
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
})
示例2:
quotaRepo *fakes.FakeSpaceQuotaRepository
orgRepo *test_org.FakeOrganizationRepository
requirementsFactory *testreq.FakeReqFactory
)
BeforeEach(func() {
ui = &testterm.FakeUI{}
quotaRepo = &fakes.FakeSpaceQuotaRepository{}
orgRepo = &test_org.FakeOrganizationRepository{}
requirementsFactory = &testreq.FakeReqFactory{}
org := models.Organization{}
org.Name = "my-org"
org.Guid = "my-org-guid"
orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
orgRepo.FindByNameReturns(org, nil)
})
runCommand := func(args ...string) {
cmd := NewCreateSpaceQuota(ui, configuration.NewRepositoryWithDefaults(), quotaRepo, orgRepo)
testcmd.RunCommand(cmd, args, requirementsFactory)
}
Context("requirements", func() {
It("requires the user to be logged in", func() {
requirementsFactory.LoginSuccess = false
runCommand("my-quota", "-m", "50G")
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
示例3:
var expectOrgToBeCleared = func() {
Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{}))
}
var expectSpaceToBeCleared = func() {
Expect(config.SpaceFields()).To(Equal(models.SpaceFields{}))
}
Context("there are no errors", func() {
BeforeEach(func() {
org := models.Organization{}
org.Name = "my-organization"
org.Guid = "my-organization-guid"
orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
orgRepo.FindByNameReturns(org, nil)
})
It("it updates the organization in the config", func() {
callTarget([]string{"-o", "my-organization"})
Expect(orgRepo.FindByNameArgsForCall(0)).To(Equal("my-organization"))
Expect(ui.ShowConfigurationCalled).To(BeTrue())
Expect(config.OrganizationFields().Guid).To(Equal("my-organization-guid"))
})
It("updates the space in the config", func() {
space := models.Space{}
space.Name = "my-space"
space.Guid = "my-space-guid"
示例4:
servicePlanVisibilityRepo = &testapi.FakeServicePlanVisibilityRepository{}
orgRepo = &fake_orgs.FakeOrganizationRepository{}
planBuilder = &fake_plan_builder.FakePlanBuilder{}
serviceBuilder = &fake_service_builder.FakeServiceBuilder{}
actor = actors.NewServicePlanHandler(servicePlanRepo, servicePlanVisibilityRepo, orgRepo, planBuilder, serviceBuilder)
org1 = models.Organization{}
org1.Name = "org-1"
org1.Guid = "org-1-guid"
org2 = models.Organization{}
org2.Name = "org-2"
org2.Guid = "org-2-guid"
orgRepo.FindByNameReturns(org1, nil)
publicServicePlanVisibilityFields = models.ServicePlanVisibilityFields{
Guid: "public-service-plan-visibility-guid",
ServicePlanGuid: "public-service-plan-guid",
}
privateServicePlanVisibilityFields = models.ServicePlanVisibilityFields{
Guid: "private-service-plan-visibility-guid",
ServicePlanGuid: "private-service-plan-guid",
}
limitedServicePlanVisibilityFields = models.ServicePlanVisibilityFields{
Guid: "limited-service-plan-visibility-guid",
ServicePlanGuid: "limited-service-plan-guid",
OrganizationGuid: "org-1-guid",
示例5:
))
Expect(spaceRepo.CreateSpaceName).To(Equal(""))
Expect(spaceRepo.CreateSpaceOrgGuid).To(Equal(""))
Expect(userRepo.SetSpaceRoleUserGuid).To(Equal(""))
Expect(userRepo.SetSpaceRoleSpaceGuid).To(Equal(""))
})
Context("when the -o flag is provided", func() {
It("creates a space within that org", func() {
org := models.Organization{
OrganizationFields: models.OrganizationFields{
Name: "other-org",
Guid: "org-guid-1",
}}
orgRepo.FindByNameReturns(org, nil)
runCommand("-o", "other-org", "my-space")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating space", "my-space", "other-org", "my-user"},
[]string{"OK"},
[]string{"Assigning", "my-user", "my-space", models.SpaceRoleToUserInput[models.SPACE_MANAGER]},
[]string{"Assigning", "my-user", "my-space", models.SpaceRoleToUserInput[models.SPACE_DEVELOPER]},
[]string{"TIP"},
))
Expect(spaceRepo.CreateSpaceName).To(Equal("my-space"))
Expect(spaceRepo.CreateSpaceOrgGuid).To(Equal(org.Guid))
Expect(userRepo.SetSpaceRoleUserGuid).To(Equal("my-user-guid"))
Expect(userRepo.SetSpaceRoleSpaceGuid).To(Equal("my-space-guid"))
示例6:
})
It("fails and tells the user", func() {
runCommand("my-nonexistent-security-group", "my-org", "my-space")
Expect(fakeSecurityGroupRepo.ReadArgsForCall(0)).To(Equal("my-nonexistent-security-group"))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"security group", "my-nonexistent-security-group", "not found"},
))
})
})
Context("when the org does not exist", func() {
BeforeEach(func() {
fakeOrgRepo.FindByNameReturns(models.Organization{}, errors.New("Org org not found"))
})
It("fails and tells the user", func() {
runCommand("sec group", "org", "space")
Expect(fakeOrgRepo.FindByNameArgsForCall(0)).To(Equal("org"))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"Org", "org", "not found"},
))
})
})
Context("when the space does not exist", func() {
BeforeEach(func() {
示例7:
runCommand("-s", "space-name", "source-app", "target-app")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"Error finding space by name."},
))
})
})
})
Describe("when an org and space name are passed as parameters", func() {
It("send the correct target application for the space and org", func() {
orgRepo.FindByNameReturns(models.Organization{
Spaces: []models.SpaceFields{
{
Name: "space-name",
Guid: "space-guid",
},
},
}, nil)
runCommand("-o", "org-name", "-s", "space-name", "source-app", "target-app")
targetAppName, spaceGuid := appRepo.ReadFromSpaceArgsForCall(0)
Expect(targetAppName).To(Equal("target-app"))
Expect(spaceGuid).To(Equal("space-guid"))
sourceAppGuid, targetAppGuid := copyAppSourceRepo.CopyApplicationArgsForCall(0)
Expect(sourceAppGuid).To(Equal("source-app-guid"))
Expect(targetAppGuid).To(Equal("target-app-guid"))
appArg, orgName, spaceName := appRestarter.ApplicationRestartArgsForCall(0)
示例8:
space2.Guid = "some-space-guid"
space2.Name = "some-space"
orgRepo.ListOrgsReturns([]models.Organization{org1, org2}, nil)
spaceRepo.ListSpacesStub = listSpacesStub([]models.Space{space1, space2})
spaceRepo.FindByNameStub = func(name string) (models.Space, error) {
m := map[string]models.Space{
space1.Name: space1,
space2.Name: space2,
}
return m[name], nil
}
})
It("lets the user select an org and space by number", func() {
orgRepo.FindByNameReturns(org2, nil)
OUT_OF_RANGE_CHOICE := "3"
ui.Inputs = []string{"api.example.com", "[email protected]", "password", OUT_OF_RANGE_CHOICE, "2", OUT_OF_RANGE_CHOICE, "1"}
testcmd.RunCliCommand("login", Flags, nil, updateCommandDependency, false)
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Select an org"},
[]string{"1. some-org"},
[]string{"2. my-new-org"},
[]string{"Select a space"},
[]string{"1. my-space"},
[]string{"2. some-space"},
))
Expect(Config.OrganizationFields().Guid).To(Equal("my-new-org-guid"))
示例9:
returnedBroker := serviceBroker1
brokerBuilder.GetBrokerWithSpecifiedServiceReturns(returnedBroker, nil)
brokers, err := actor.FilterBrokers("", "my-service1", "")
Expect(err).NotTo(HaveOccurred())
Expect(len(brokers)).To(Equal(1))
Expect(len(brokers[0].Services)).To(Equal(1))
Expect(brokers[0].Services[0].Guid).To(Equal("service-guid1"))
})
})
Context("when the -o flag is passed", func() {
It("returns an error if the org does not actually exist", func() {
orgRepo.FindByNameReturns(models.Organization{}, errors.NewModelNotFoundError("organization", "org-that-shall-not-be-found"))
_, err := actor.FilterBrokers("", "", "org-that-shall-not-be-found")
Expect(err).To(HaveOccurred())
})
It("returns a slice of brokers containing Services/Service Plans visible to the org", func() {
serviceBroker1.Services = []models.ServiceOffering{service1}
returnedBroker := []models.ServiceBroker{serviceBroker1}
serviceBuilder.GetServicesVisibleToOrgReturns([]models.ServiceOffering{service1}, nil)
brokerBuilder.AttachBrokersToServicesReturns(returnedBroker, nil)
brokers, err := actor.FilterBrokers("", "", "org1")
Expect(err).NotTo(HaveOccurred())
示例10:
[]string{"Creating org", "my-org"},
[]string{"OK"},
[]string{"my-org", "already exists"},
))
})
Context("when CC api version supports assigning orgRole by name, and feature-flag 'set_roles_by_username' is enabled", func() {
BeforeEach(func() {
config.SetApiVersion("2.37.0")
flagRepo.FindByNameReturns(models.FeatureFlag{
Name: "set_roles_by_username",
Enabled: true,
}, nil)
orgRepo.FindByNameReturns(models.Organization{
OrganizationFields: models.OrganizationFields{
Guid: "my-org-guid",
},
}, nil)
})
It("assigns manager role to user", func() {
runCommand("my-org")
orgGuid, role, userGuid, userName := orgRoleSetter.SetOrgRoleArgsForCall(0)
Ω(orgRoleSetter.SetOrgRoleCallCount()).To(Equal(1))
Ω(orgGuid).To(Equal("my-org-guid"))
Ω(role).To(Equal("OrgManager"))
Ω(userGuid).To(Equal(""))
Ω(userName).To(Equal("my-user"))
})