本文整理匯總了Golang中github.com/nttlabs/cli/testhelpers/terminal.FakeUI.Inputs方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeUI.Inputs方法的具體用法?Golang FakeUI.Inputs怎麽用?Golang FakeUI.Inputs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nttlabs/cli/testhelpers/terminal.FakeUI
的用法示例。
在下文中一共展示了FakeUI.Inputs方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
space = maker.NewSpace(maker.Overrides{
"name": "space-to-delete",
"guid": "space-to-delete-guid",
})
requirementsFactory = &testreq.FakeReqFactory{
LoginSuccess: true,
TargetedOrgSuccess: true,
Space: space,
}
})
Describe("requirements", func() {
BeforeEach(func() {
ui.Inputs = []string{"y"}
})
It("fails when not logged in", func() {
requirementsFactory.LoginSuccess = false
runCommand("my-space")
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("fails when not targeting a space", func() {
requirementsFactory.TargetedOrgSuccess = false
runCommand("my-space")
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
})
It("deletes a space, given its name", func() {
示例2:
Expect(brokerRepo.DeletedServiceBrokerGuid).To(Equal("service-broker-to-delete-guid"))
Expect(ui.Prompts).To(BeEmpty())
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Deleting service broker", "service-broker-to-delete", "my-user"},
[]string{"OK"},
))
})
})
Context("when the service broker does not exist", func() {
BeforeEach(func() {
brokerRepo.FindByNameNotFound = true
})
It("warns the user", func() {
ui.Inputs = []string{}
runCommand("-f", "service-broker-to-delete")
Expect(brokerRepo.FindByNameName).To(Equal("service-broker-to-delete"))
Expect(brokerRepo.DeletedServiceBrokerGuid).To(Equal(""))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Deleting service broker", "service-broker-to-delete"},
[]string{"OK"},
))
Expect(ui.WarnOutputs).To(ContainSubstrings([]string{"service-broker-to-delete", "does not exist"}))
})
})
})
示例3:
It("fails requirements when an org is not targeted", func() {
requirementsFactory.TargetedOrgSuccess = false
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
Context("When the quota provided exists", func() {
BeforeEach(func() {
quota := models.SpaceQuota{}
quota.Name = "my-quota"
quota.Guid = "my-quota-guid"
quota.OrgGuid = "my-org-guid"
quotaRepo.FindByNameReturns(quota, nil)
})
It("deletes a quota with a given name when the user confirms", func() {
ui.Inputs = []string{"y"}
runCommand("my-quota")
Expect(quotaRepo.DeleteArgsForCall(0)).To(Equal("my-quota-guid"))
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"Really delete the quota", "my-quota"},
))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Deleting space quota", "my-quota", "as", "my-user"},
[]string{"OK"},
))
})
It("does not prompt when the -f flag is provided", func() {
示例4:
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Showing", "my-app", "my-org", "my-space", "my-user"},
[]string{"OK"},
[]string{"memory", "256M"},
[]string{"disk", "1G"},
[]string{"instances", "42"},
))
Expect(ui.Outputs).ToNot(ContainSubstrings([]string{"Scaling", "my-app", "my-org", "my-space", "my-user"}))
})
})
Context("when the user does not confirm 'yes'", func() {
It("does not restart the app", func() {
ui.Inputs = []string{"whatever"}
testcmd.RunCommand(cmd, []string{"-i", "5", "-m", "512M", "-k", "2G", "my-app"}, requirementsFactory)
Expect(restarter.ApplicationRestartCallCount()).To(Equal(0))
})
})
Context("when the user provides the -f flag", func() {
It("does not prompt the user", func() {
testcmd.RunCommand(cmd, []string{"-f", "-i", "5", "-m", "512M", "-k", "2G", "my-app"}, requirementsFactory)
application, orgName, spaceName := restarter.ApplicationRestartArgsForCall(0)
Expect(application).To(Equal(app))
Expect(orgName).To(Equal(config.OrganizationFields().Name))
Expect(spaceName).To(Equal(config.SpaceFields().Name))
})
示例5:
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("requires five arguments to run", func() {
requirementsFactory.LoginSuccess = true
args = []string{"one", "two", "three"}
testcmd.RunCommand(cmd, args, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("passes requirements if user is logged in and provided five args to run", func() {
requirementsFactory.LoginSuccess = true
args = []string{"one", "two", "three", "four", "five"}
ui.Inputs = append(ui.Inputs, "no")
testcmd.RunCommand(cmd, args, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
})
})
Describe("migrating service instances", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
args = []string{"v1-service-label", "v1-provider-name", "v1-plan-name", "v2-service-label", "v2-plan-name"}
serviceRepo.ServiceInstanceCountForServicePlan = 1
})
It("displays the warning and the prompt including info about the instances and plan to migrate", func() {
示例6:
runCommand("foo.com")
Expect(domainRepo.DeleteDomainGuid).To(Equal("foo-guid"))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Deleting domain", "foo.com"},
[]string{"FAILED"},
[]string{"foo.com"},
[]string{"failed badly"},
))
})
})
Context("when the user does not confirm", func() {
BeforeEach(func() {
ui.Inputs = []string{"no"}
})
It("does nothing", func() {
runCommand("foo.com")
Expect(domainRepo.DeleteDomainGuid).To(Equal(""))
Expect(ui.Prompts).To(ContainSubstrings([]string{"delete", "foo.com"}))
Expect(ui.Outputs).To(BeEmpty())
})
})
Context("when the user provides the -f flag", func() {
BeforeEach(func() {
示例7:
It("deletes a user with the given name", func() {
runCommand("user-name")
Expect(ui.Prompts).To(ContainSubstrings([]string{"Really delete the user user-name"}))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Deleting user", "user-name", "admin-user"},
[]string{"OK"},
))
Expect(userRepo.FindByUsernameUsername).To(Equal("user-name"))
Expect(userRepo.DeleteUserGuid).To(Equal("user-guid"))
})
It("does not delete the user when no confirmation is given", func() {
ui.Inputs = []string{"nope"}
runCommand("user")
Expect(ui.Prompts).To(ContainSubstrings([]string{"Really delete"}))
Expect(userRepo.FindByUsernameUsername).To(Equal(""))
Expect(userRepo.DeleteUserGuid).To(Equal(""))
})
It("deletes without confirmation when the -f flag is given", func() {
ui.Inputs = []string{}
runCommand("-f", "user-name")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Deleting user", "user-name"},
[]string{"OK"},
))
示例8:
space1 := models.Space{}
space1.Guid = "my-space-guid"
space1.Name = "my-space"
space2 = models.Space{}
space2.Guid = "some-space-guid"
space2.Name = "some-space"
orgRepo.ListOrgsReturns([]models.Organization{org1, org2}, nil)
spaceRepo.Spaces = []models.Space{space1, space2}
})
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"}
l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
testcmd.RunCommand(l, Flags, nil)
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"))
Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
示例9:
requirementsFactory.LoginSuccess = false
testcmd.RunCommand(cmd, []string{"my-service"}, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
})
It("creates a new user provided service given just a name", func() {
testcmd.RunCommand(cmd, []string{"my-custom-service"}, requirementsFactory)
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating user provided service"},
[]string{"OK"},
))
})
It("accepts service parameters interactively", func() {
ui.Inputs = []string{"foo value", "bar value", "baz value"}
testcmd.RunCommand(cmd, []string{"-p", `"foo, bar, baz"`, "my-custom-service"}, requirementsFactory)
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"foo"},
[]string{"bar"},
[]string{"baz"},
))
Expect(repo.CreateName).To(Equal("my-custom-service"))
Expect(repo.CreateParams).To(Equal(map[string]interface{}{
"foo": "foo value",
"bar": "bar value",
"baz": "baz value",
}))