本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/commandregistry.Command.Requirements方法的典型用法代碼示例。如果您正苦於以下問題:Golang Command.Requirements方法的具體用法?Golang Command.Requirements怎麽用?Golang Command.Requirements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/commandregistry.Command
的用法示例。
在下文中一共展示了Command.Requirements方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
}
Context("when arguments are provided", func() {
var cmd commandregistry.Command
var flagContext flags.FlagContext
BeforeEach(func() {
cmd = &buildpack.ListBuildpacks{}
cmd.SetDependency(deps, false)
flagContext = flags.NewFlagContext(cmd.MetaData().Flags)
})
It("should fail with usage", func() {
flagContext.Parse("blahblah")
reqs := cmd.Requirements(requirementsFactory, flagContext)
err := testcmd.RunRequirements(reqs)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Incorrect Usage"))
Expect(err.Error()).To(ContainSubstring("No argument required"))
})
})
It("fails requirements when login fails", func() {
Expect(runCommand()).To(BeFalse())
})
Context("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
示例2:
userRequirement.ExecuteReturns(nil)
factory.NewUserRequirementReturns(userRequirement)
organizationRequirement = new(requirementsfakes.FakeOrganizationRequirement)
organizationRequirement.ExecuteReturns(nil)
factory.NewOrganizationRequirementReturns(organizationRequirement)
})
Describe("Requirements", func() {
Context("when not provided exactly four args", func() {
BeforeEach(func() {
flagContext.Parse("the-user-name", "the-org-name", "the-space-name")
})
It("fails with usage", func() {
Expect(func() { cmd.Requirements(factory, flagContext) }).To(Panic())
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage. Requires USERNAME, ORG, SPACE, ROLE as arguments"},
[]string{"NAME"},
[]string{"USAGE"},
))
})
})
Context("when provided four args", func() {
BeforeEach(func() {
flagContext.Parse("the-user-name", "the-org-name", "the-space-name", "SpaceManager")
})
It("returns a LoginRequirement", func() {
actualRequirements := cmd.Requirements(factory, flagContext)
示例3:
minAPIVersionRequirement = &passingRequirement{Name: "min-api-version-requirement"}
factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement)
targetedSpaceRequirement = &passingRequirement{Name: "targeted-space-requirement"}
factory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement)
})
Describe("Requirements", func() {
Context("when not provided exactly one arg", func() {
BeforeEach(func() {
flagContext.Parse("service-instance", "extra-arg")
})
It("fails with usage", func() {
_, err := cmd.Requirements(factory, flagContext)
Expect(err).To(HaveOccurred())
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"Incorrect Usage. Requires an argument"},
))
})
})
Context("when provided exactly one arg", func() {
BeforeEach(func() {
flagContext.Parse("service-instance")
})
It("returns a LoginRequirement", func() {
actualRequirements, err := cmd.Requirements(factory, flagContext)
示例4:
}
cmd = &commands.OneTimeSSHCode{}
cmd.SetDependency(deps, false)
flagContext = flags.NewFlagContext(cmd.MetaData().Flags)
factory = new(requirementsfakes.FakeFactory)
endpointRequirement = &passingRequirement{Name: "endpoint-requirement"}
factory.NewAPIEndpointRequirementReturns(endpointRequirement)
})
Describe("Requirements", func() {
It("returns an EndpointRequirement", func() {
actualRequirements := cmd.Requirements(factory, flagContext)
Expect(factory.NewAPIEndpointRequirementCallCount()).To(Equal(1))
Expect(actualRequirements).To(ContainElement(endpointRequirement))
})
Context("when not provided exactly zero args", func() {
BeforeEach(func() {
flagContext.Parse("domain-name")
})
It("fails with usage", func() {
var firstErr error
reqs := cmd.Requirements(factory, flagContext)
for _, req := range reqs {