本文整理匯總了Golang中code/cloudfoundry/org/cli/testhelpers/commands.RunCLICommand函數的典型用法代碼示例。如果您正苦於以下問題:Golang RunCLICommand函數的具體用法?Golang RunCLICommand怎麽用?Golang RunCLICommand使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RunCLICommand函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
deps.RepoLocator = deps.RepoLocator.SetAuthenticationRepository(authRepo)
deps.Config = configRepo
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("oauth-token").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
fakeLogger := new(tracefakes.FakePrinter)
authRepo = new(authenticationfakes.FakeRepository)
configRepo = testconfig.NewRepositoryWithDefaults()
requirementsFactory = new(requirementsfakes.FakeFactory)
deps = commandregistry.NewDependency(os.Stdout, fakeLogger, "")
})
runCommand := func() bool {
return testcmd.RunCLICommand("oauth-token", []string{}, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements", func() {
It("fails when the user is not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
Expect(runCommand()).ToNot(HavePassedRequirements())
})
})
Describe("when logged in", func() {
BeforeEach(func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
})
It("fails if oauth refresh fails", func() {
示例2:
serviceRepo = &apifakes.FakeServiceRepository{}
serviceInstance := models.ServiceInstance{}
serviceInstance.GUID = "fake-instance-guid"
serviceInstance.Name = "fake-service-instance"
serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
serviceKeyRepo = apifakes.NewFakeServiceKeyRepo()
requirementsFactory = new(requirementsfakes.FakeFactory)
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{})
serviceInstanceReq := new(requirementsfakes.FakeServiceInstanceRequirement)
requirementsFactory.NewServiceInstanceRequirementReturns(serviceInstanceReq)
serviceInstanceReq.GetServiceInstanceReturns(serviceInstance)
})
var callCreateService = func(args []string) bool {
return testcmd.RunCLICommand("create-service-key", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements", func() {
It("fails when not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
Expect(callCreateService([]string{"fake-service-instance", "fake-service-key"})).To(BeFalse())
})
It("requires two arguments to run", func() {
Expect(callCreateService([]string{})).To(BeFalse())
Expect(callCreateService([]string{"fake-arg-one"})).To(BeFalse())
Expect(callCreateService([]string{"fake-arg-one", "fake-arg-two", "fake-arg-three"})).To(BeFalse())
})
It("fails when service instance is not found", func() {
示例3:
)
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.RepoLocator = deps.RepoLocator.SetBuildpackRepository(buildpackRepo)
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("buildpacks").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
buildpackRepo = new(apifakes.OldFakeBuildpackRepository)
requirementsFactory = new(requirementsfakes.FakeFactory)
})
runCommand := func(args ...string) bool {
return testcmd.RunCLICommand("buildpacks", args, requirementsFactory, updateCommandDependency, false, ui)
}
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")
示例4:
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.RepoLocator = deps.RepoLocator.SetEnvironmentVariableGroupsRepository(environmentVariableGroupRepo)
deps.Config = configRepo
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("staging-environment-variable-group").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
configRepo = testconfig.NewRepositoryWithDefaults()
requirementsFactory = new(requirementsfakes.FakeFactory)
environmentVariableGroupRepo = new(environmentvariablegroupsfakes.FakeRepository)
})
runCommand := func(args ...string) bool {
return testcmd.RunCLICommand("staging-environment-variable-group", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements", func() {
It("requires the user to be logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
Expect(runCommand()).ToNot(HavePassedRequirements())
})
Context("when arguments are provided", func() {
var cmd commandregistry.Command
var flagContext flags.FlagContext
BeforeEach(func() {
cmd = &environmentvariablegroup.StagingEnvironmentVariableGroup{}
cmd.SetDependency(deps, false)
示例5:
{Name: "service-plan-d", Free: true}},
ServiceOfferingFields: models.ServiceOfferingFields{
Label: "aaa-my-service-offering",
Description: "service offering 2 description",
},
}
fakeServiceOfferings = []models.ServiceOffering{serviceWithAPaidPlan, service2}
})
Describe("Requirements", func() {
Context("when the an API endpoint is not targeted", func() {
It("does not meet its requirements", func() {
config = testconfig.NewRepository()
requirementsFactory.NewAPIEndpointRequirementReturns(requirements.Failing{Message: "no api"})
Expect(testcmd.RunCLICommand("marketplace", []string{}, requirementsFactory, updateCommandDependency, false, ui)).To(BeFalse())
})
Context("when arguments are provided", func() {
var cmd commandregistry.Command
var flagContext flags.FlagContext
BeforeEach(func() {
cmd = &service.MarketplaceServices{}
cmd.SetDependency(deps, false)
flagContext = flags.NewFlagContext(cmd.MetaData().Flags)
})
It("should fail with usage", func() {
flagContext.Parse("blahblah")
示例6:
OriginalCommand = commandregistry.Commands.FindCommand("restart")
appRestarter = new(applicationfakes.FakeRestarter)
//setup fakes to correctly interact with commandregistry
appRestarter.SetDependencyStub = func(_ commandregistry.Dependency, _ bool) commandregistry.Command {
return appRestarter
}
appRestarter.MetaDataReturns(commandregistry.CommandMetadata{Name: "restart"})
})
AfterEach(func() {
commandregistry.Register(OriginalCommand)
})
runCommand := func(args ...string) bool {
return testcmd.RunCLICommand("copy-source", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirement failures", func() {
It("when not logged in", func() {
requirementsFactory.NewUsageRequirementReturns(requirements.Passing{})
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
Expect(runCommand("source-app", "target-app")).ToNot(HavePassedRequirements())
})
It("when a space is not targeted", func() {
requirementsFactory.NewUsageRequirementReturns(requirements.Passing{})
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"})
Expect(runCommand("source-app", "target-app")).ToNot(HavePassedRequirements())
})
示例7:
config = testconfig.NewRepositoryWithDefaults()
requirementsFactory = new(requirementsfakes.FakeFactory)
authRepo = new(authenticationfakes.FakeRepository)
authRepo.AuthenticateStub = func(credentials map[string]string) error {
config.SetAccessToken("my-access-token")
config.SetRefreshToken("my-refresh-token")
return nil
}
fakeLogger = new(tracefakes.FakePrinter)
deps = commandregistry.NewDependency(os.Stdout, fakeLogger, "")
})
Describe("requirements", func() {
It("fails with usage when given too few arguments", func() {
testcmd.RunCLICommand("auth", []string{}, requirementsFactory, updateCommandDependency, false, ui)
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires", "arguments"},
))
})
It("fails if the user has not set an api endpoint", func() {
requirementsFactory.NewAPIEndpointRequirementReturns(requirements.Failing{Message: "no api set"})
Expect(testcmd.RunCLICommand("auth", []string{"username", "password"}, requirementsFactory, updateCommandDependency, false, ui)).To(BeFalse())
})
})
Context("when an api endpoint is targeted", func() {
BeforeEach(func() {
requirementsFactory.NewAPIEndpointRequirementReturns(requirements.Passing{})
示例8:
application.GUID = "my-app-guid"
application.InstanceCount = 1
applicationReq := new(requirementsfakes.FakeApplicationRequirement)
applicationReq.GetApplicationReturns(application)
requirementsFactory.NewApplicationRequirementReturns(applicationReq)
})
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.Config = config
deps.RepoLocator = deps.RepoLocator.SetAppInstancesRepository(appInstancesRepo)
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("restart-app-instance").SetDependency(deps, pluginCall))
}
runCommand := func(args ...string) bool {
return testcmd.RunCLICommand("restart-app-instance", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements", func() {
It("fails if not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
Expect(runCommand("my-app", "0")).To(BeFalse())
})
It("fails if a space is not targeted", func() {
requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Failing{Message: "not targeting space"})
Expect(runCommand("my-app", "0")).To(BeFalse())
})
It("fails when there is not exactly two arguments", func() {
Expect(runCommand("my-app")).To(BeFalse())
示例9:
deps.RepoLocator = deps.RepoLocator.SetBuildpackRepository(repo)
deps.RepoLocator = deps.RepoLocator.SetBuildpackBitsRepository(bitsRepo)
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("create-buildpack").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
requirementsFactory = new(requirementsfakes.FakeFactory)
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
repo = new(apifakes.OldFakeBuildpackRepository)
bitsRepo = new(apifakes.FakeBuildpackBitsRepository)
ui = &testterm.FakeUI{}
})
It("fails requirements when the user is not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
Expect(testcmd.RunCLICommand("create-buildpack", []string{"my-buildpack", "my-dir", "0"}, requirementsFactory, updateCommandDependency, false, ui)).To(BeFalse())
})
It("fails with usage when given fewer than three arguments", func() {
testcmd.RunCLICommand("create-buildpack", []string{}, requirementsFactory, updateCommandDependency, false, ui)
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires", "arguments"},
))
})
Context("when a file is provided", func() {
It("prints error and do not call create buildpack", func() {
bitsRepo.CreateBuildpackZipFileReturns(nil, "", fmt.Errorf("create buildpack error"))
testcmd.RunCLICommand("create-buildpack", []string{"my-buildpack", "file", "5"}, requirementsFactory, updateCommandDependency, false, ui)
示例10:
var (
pwDeps passwordDeps
ui *testterm.FakeUI
deps commandregistry.Dependency
)
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.Config = pwDeps.Config
deps.RepoLocator = deps.RepoLocator.SetPasswordRepository(pwDeps.PwdRepo)
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("passwd").SetDependency(deps, pluginCall))
}
callPassword := func(inputs []string, pwDeps passwordDeps) (*testterm.FakeUI, bool) {
ui = &testterm.FakeUI{Inputs: inputs}
passed := testcmd.RunCLICommand("passwd", []string{}, pwDeps.ReqFactory, updateCommandDependency, false, ui)
return ui, passed
}
BeforeEach(func() {
pwDeps = getPasswordDeps()
})
It("does not pass requirements if you are not logged in", func() {
pwDeps.ReqFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
_, passed := callPassword([]string{}, pwDeps)
Expect(passed).To(BeFalse())
})
Context("when logged in successfully", func() {
BeforeEach(func() {
示例11:
}
BeforeEach(func() {
org := models.OrganizationFields{}
org.Name = "MyOrg"
space := models.SpaceFields{}
space.Name = "MySpace"
config = testconfig.NewRepository()
config.SetAccessToken("MyAccessToken")
config.SetOrganizationFields(org)
config.SetSpaceFields(space)
ui = &testterm.FakeUI{}
testcmd.RunCLICommand("logout", []string{}, nil, updateCommandDependency, false, ui)
})
It("clears access token from the config", func() {
Expect(config.AccessToken()).To(Equal(""))
})
It("clears organization fields from the config", func() {
Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{}))
})
It("clears space fields from the config", func() {
Expect(config.SpaceFields()).To(Equal(models.SpaceFields{}))
})
})
示例12:
deps.UI = ui
deps.RepoLocator = deps.RepoLocator.SetServiceBrokerRepository(serviceBrokerRepo)
deps.Config = configRepo
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("rename-service-broker").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
ui = &testterm.FakeUI{}
requirementsFactory = new(requirementsfakes.FakeFactory)
serviceBrokerRepo = new(apifakes.FakeServiceBrokerRepository)
})
runCommand := func(args ...string) bool {
return testcmd.RunCLICommand("rename-service-broker", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements", func() {
It("fails with usage when not invoked with exactly two args", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
runCommand("welp")
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires", "arguments"},
))
})
It("fails when not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
Expect(runCommand("okay", "DO---IIIIT")).To(BeFalse())
})
示例13:
BeforeEach(func() {
ui = &testterm.FakeUI{}
configRepo = testconfig.NewRepositoryWithDefaults()
requirementsFactory = new(requirementsfakes.FakeFactory)
appRepo = new(applicationsfakes.FakeRepository)
})
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.Config = configRepo
deps.RepoLocator = deps.RepoLocator.SetApplicationRepository(appRepo)
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("get-health-check").SetDependency(deps, pluginCall))
}
runCommand := func(args ...string) bool {
return testcmd.RunCLICommand("get-health-check", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements", func() {
It("fails with usage when called without enough arguments", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
runCommand()
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"get-health-check"},
[]string{"Incorrect Usage", "Requires", "argument"},
))
})
It("fails requirements when not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
示例14:
)
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.Config = configRepo
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("config").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
configRepo = testconfig.NewRepositoryWithDefaults()
requirementsFactory = new(requirementsfakes.FakeFactory)
})
runCommand := func(args ...string) {
testcmd.RunCLICommand("config", args, requirementsFactory, updateCommandDependency, false, ui)
}
It("fails requirements when no flags are provided", func() {
runCommand()
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage"},
))
})
Context("--async-timeout flag", func() {
It("stores the timeout in minutes when the --async-timeout flag is provided", func() {
runCommand("--async-timeout", "12")
Expect(configRepo.AsyncTimeout()).Should(Equal(uint(12)))
})
示例15:
deps.Config = configRepo
deps.RepoLocator = deps.RepoLocator.SetSpaceQuotaRepository(quotaRepo)
deps.RepoLocator = deps.RepoLocator.SetSpaceRepository(spaceRepo)
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("unset-space-quota").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
configRepo = testconfig.NewRepositoryWithDefaults()
quotaRepo = new(spacequotasfakes.FakeSpaceQuotaRepository)
spaceRepo = new(spacesfakes.FakeSpaceRepository)
requirementsFactory = new(requirementsfakes.FakeFactory)
})
runCommand := func(args ...string) bool {
return testcmd.RunCLICommand("unset-space-quota", args, requirementsFactory, updateCommandDependency, false, ui)
}
It("fails with usage when provided too many or two few args", func() {
runCommand("space")
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires", "arguments"},
))
runCommand("space", "quota", "extra-stuff")
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires", "arguments"},
))
})
Describe("requirements", func() {