當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeUI.Inputs方法代碼示例

本文整理匯總了Golang中testhelpers/terminal.FakeUI.Inputs方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeUI.Inputs方法的具體用法?Golang FakeUI.Inputs怎麽用?Golang FakeUI.Inputs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在testhelpers/terminal.FakeUI的用法示例。


在下文中一共展示了FakeUI.Inputs方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init

func init() {
	Describe("migrating service instances from v1 to v2", func() {
		var (
			ui                  *testterm.FakeUI
			serviceRepo         *testapi.FakeServiceRepo
			cmd                 *MigrateServiceInstances
			requirementsFactory *testreq.FakeReqFactory
			context             *cli.Context
			args                []string
		)

		BeforeEach(func() {
			ui = &testterm.FakeUI{}
			config := testconfig.NewRepository()
			serviceRepo = &testapi.FakeServiceRepo{}
			cmd = NewMigrateServiceInstances(ui, config, serviceRepo)
			requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
			args = []string{}
		})

		Describe("requirements", func() {
			It("requires you to be logged in", func() {
				context = testcmd.NewContext("migrate-service-instances", args)
				testcmd.RunCommand(cmd, context, requirementsFactory)

				Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
			})

			It("requires five arguments to run", func() {
				requirementsFactory.LoginSuccess = true
				args = []string{"one", "two", "three"}
				context = testcmd.NewContext("migrate-service-instances", args)
				testcmd.RunCommand(cmd, context, 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")

				context = testcmd.NewContext("migrate-service-instances", args)
				testcmd.RunCommand(cmd, context, requirementsFactory)

				Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
			})
		})

		Describe("migrating service instances", func() {
			BeforeEach(func() {
				requirementsFactory.LoginSuccess = true
				args = []string{"v1-service-name", "v1-provider-name", "v1-plan-name", "v2-service-name", "v2-plan-name"}
				context = testcmd.NewContext("migrate-service-instances", args)
				serviceRepo.ServiceInstanceCountForServicePlan = 1
			})

			It("displays the warning and the prompt including info about the instances and plan to migrate", func() {
				ui.Inputs = []string{""}
				testcmd.RunCommand(cmd, context, requirementsFactory)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"WARNING:", "this operation is to replace a service broker"},
				})
				testassert.SliceContains(ui.Prompts, testassert.Lines{
					{"Really migrate", "1 service instance",
						"from plan", "v1-service-name", "v1-provider-name", "v1-plan-name",
						"to", "v2-service-name", "v2-plan-name"},
				})
			})

			Context("when the user confirms", func() {
				BeforeEach(func() {
					ui.Inputs = []string{"yes"}
				})

				Context("when the v1 and v2 service instances exists", func() {
					BeforeEach(func() {
						serviceRepo.FindServicePlanByDescriptionResultGuids = []string{"v1-guid", "v2-guid"}
						serviceRepo.MigrateServicePlanFromV1ToV2ReturnedCount = 1
					})

					It("makes a request to migrate the v1 service instance", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						Expect(serviceRepo.V1GuidToMigrate).To(Equal("v1-guid"))
						Expect(serviceRepo.V2GuidToMigrate).To(Equal("v2-guid"))
					})

					It("finds the v1 service plan by its name, provider and service label", func() {
						testcmd.RunCommand(cmd, context, requirementsFactory)

						expectedV1 := api.ServicePlanDescription{
							ServicePlanName: "v1-plan-name",
							ServiceProvider: "v1-provider-name",
							ServiceName:     "v1-service-name",
						}
						Expect(serviceRepo.FindServicePlanByDescriptionArguments[0]).To(Equal(expectedV1))
					})

//.........這裏部分代碼省略.........
開發者ID:normalnorman,項目名稱:cli,代碼行數:101,代碼來源:migrate_service_instances_test.go

示例2:

		})

		It("deletes the service auth token", func() {
			runCommand("a label", "a provider")
			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Deleting service auth token as", "my-user"},
				{"OK"},
			})

			Expect(authTokenRepo.FindByLabelAndProviderLabel).To(Equal("a label"))
			Expect(authTokenRepo.FindByLabelAndProviderProvider).To(Equal("a provider"))
			Expect(authTokenRepo.DeletedServiceAuthTokenFields.Guid).To(Equal("the-guid"))
		})

		It("does nothing when the user does not confirm", func() {
			ui.Inputs = []string{"nope"}
			runCommand("a label", "a provider")

			testassert.SliceContains(ui.Prompts, testassert.Lines{
				{"Really delete", "service auth token", "a label", "a provider"},
			})
			Expect(ui.Outputs).To(BeEmpty())
			Expect(authTokenRepo.DeletedServiceAuthTokenFields).To(Equal(models.ServiceAuthTokenFields{}))
		})

		It("does not prompt the user when the -f flag is given", func() {
			ui.Inputs = []string{}
			runCommand("-f", "a label", "a provider")

			Expect(ui.Prompts).To(BeEmpty())
			testassert.SliceContains(ui.Outputs, testassert.Lines{
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:delete_service_auth_token_test.go

示例3:

		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true
		})

		It("provides the user usage text when no app name is given", func() {
			runCommand()
			Expect(ui.FailedWithUsage).To(BeTrue())
		})

		Context("When provided an app that exists", func() {
			BeforeEach(func() {
				appRepo.ReadReturns.App = app
			})

			It("deletes an app when the user confirms", func() {
				ui.Inputs = []string{"y"}

				runCommand("app-to-delete")

				Expect(appRepo.ReadArgs.Name).To(Equal("app-to-delete"))
				Expect(appRepo.DeletedAppGuid).To(Equal("app-to-delete-guid"))

				testassert.SliceContains(ui.Prompts, testassert.Lines{
					{"Really delete the app app-to-delete"},
				})

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Deleting", "app-to-delete", "my-org", "my-space", "my-user"},
					{"OK"},
				})
			})
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:delete_test.go

示例4:

					{"OK"},
				})
				Expect(orgRepo.FindByNameName).To(Equal("org-to-delete"))
				Expect(orgRepo.DeletedOrganizationGuid).To(Equal("org-to-delete-guid"))
			})

			It("does not untarget the org and space", func() {
				runCommand("org-to-delete")

				Expect(config.OrganizationFields().Name).To(Equal("some-other-org"))
				Expect(config.SpaceFields().Name).To(Equal("some-other-space"))
			})
		})

		It("does not prompt when the -f flag is given", func() {
			ui.Inputs = []string{}
			runCommand("-f", "org-to-delete")

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Deleting", "org-to-delete"},
				{"OK"},
			})
			Expect(orgRepo.FindByNameName).To(Equal("org-to-delete"))
			Expect(orgRepo.DeletedOrganizationGuid).To(Equal("org-to-delete-guid"))
		})

		It("warns the user when the org does not exist", func() {
			orgRepo.FindByNameNotFound = true

			runCommand("org-to-delete")
開發者ID:nota-ja,項目名稱:cli,代碼行數:30,代碼來源:delete_org_test.go

示例5:

				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.Organizations = []models.Organization{org1, org2}
				spaceRepo.Spaces = []models.Space{space1, space2}
			})

			It("lets the user select an org and space by number", func() {
				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, testcmd.NewContext("login", Flags), nil)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Select an org"},
					{"1. some-org"},
					{"2. my-new-org"},
					{"Select a space"},
					{"1. my-space"},
					{"2. some-space"},
				})

				Expect(Config.OrganizationFields().Guid).To(Equal("my-new-org-guid"))
				Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
開發者ID:juggernaut,項目名稱:cli,代碼行數:31,代碼來源:login_test.go

示例6:

		orgFields := models.OrganizationFields{}
		orgFields.Name = "my-org"

		token := configuration.TokenInfo{Username: "my-user"}
		config = testconfig.NewRepositoryWithAccessToken(token)
		config.SetSpaceFields(spaceFields)
		config.SetOrganizationFields(orgFields)

		org := models.Organization{}
		org.Name = "org-to-delete"
		org.Guid = "org-to-delete-guid"
		orgRepo = &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
	})

	It("TestDeleteOrgConfirmingWithY", func() {
		ui.Inputs = []string{"y"}
		cmd := NewDeleteOrg(ui, config, orgRepo)
		testcmd.RunCommand(cmd, testcmd.NewContext("delete-org", []string{"org-to-delete"}), reqFactory)

		testassert.SliceContains(ui.Prompts, testassert.Lines{
			{"Really delete"},
		})

		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Deleting", "org-to-delete"},
			{"OK"},
		})
		Expect(orgRepo.FindByNameName).To(Equal("org-to-delete"))
		Expect(orgRepo.DeletedOrganizationGuid).To(Equal("org-to-delete-guid"))
	})
開發者ID:knolleary,項目名稱:cli,代碼行數:30,代碼來源:delete_org_test.go

示例7:

				runCommand("foo.com")

				Expect(domainRepo.DeleteDomainGuid).To(Equal("foo-guid"))

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Deleting domain", "foo.com"},
					{"FAILED"},
					{"foo.com"},
					{"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(""))

				testassert.SliceContains(ui.Prompts, testassert.Lines{
					{"delete", "foo.com"},
				})

				Expect(ui.Outputs).To(BeEmpty())
			})
		})
開發者ID:nota-ja,項目名稱:cli,代碼行數:30,代碼來源:delete_domain_test.go

示例8:

					{"Showing", "my-app", "my-org", "my-space", "my-user"},
					{"OK"},
					{"memory", "256M"},
					{"disk", "1G"},
					{"instances", "42"},
				})

				testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{
					{"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, testcmd.NewContext("scale", []string{"-i", "5", "-m", "512M", "-k", "2G", "my-app"}), reqFactory)

				Expect(restarter.AppToRestart.Guid).To(Equal(""))
			})
		})

		Context("when the user provides the -f flag", func() {
			It("does not prompt the user", func() {
				testcmd.RunCommand(cmd, testcmd.NewContext("scale", []string{"-f", "-i", "5", "-m", "512M", "-k", "2G", "my-app"}), reqFactory)
				Expect(restarter.AppToRestart.Guid).To(Equal("my-app-guid"))
			})
		})

		Context("when the user confirms they want to restart", func() {
			BeforeEach(func() {
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:scale_test.go

示例9:

			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	It("creates a new user provided service given just a name", func() {
		args := []string{"my-custom-service"}
		ctxt := testcmd.NewContext("create-user-provided-service", args)
		testcmd.RunCommand(cmd, ctxt, requirementsFactory)
		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating user provided service"},
			{"OK"},
		})
	})

	It("accepts service parameters interactively", func() {
		ui.Inputs = []string{"foo value", "bar value", "baz value"}
		ctxt := testcmd.NewContext("create-user-provided-service", []string{"-p", `"foo, bar, baz"`, "my-custom-service"})
		testcmd.RunCommand(cmd, ctxt, requirementsFactory)

		testassert.SliceContains(ui.Prompts, testassert.Lines{
			{"foo"},
			{"bar"},
			{"baz"},
		})

		Expect(repo.CreateName).To(Equal("my-custom-service"))
		Expect(repo.CreateParams).To(Equal(map[string]string{
			"foo": "foo value",
			"bar": "bar value",
			"baz": "baz value",
		}))
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:create_user_provided_service_test.go

示例10:

		routeRepo  *testapi.FakeRouteRepository
		reqFactory *testreq.FakeReqFactory
		ui         *testterm.FakeUI
		cmd        *DeleteRoute
	)

	BeforeEach(func() {
		configRepo := testconfig.NewRepositoryWithDefaults()
		ui = &testterm.FakeUI{}
		routeRepo = &testapi.FakeRouteRepository{}
		reqFactory = &testreq.FakeReqFactory{}
		cmd = NewDeleteRoute(ui, configRepo, routeRepo)
	})

	var callDeleteRoute = func(confirmation string, args []string) {
		ui.Inputs = []string{confirmation}
		testcmd.RunCommand(cmd, testcmd.NewContext("delete-route", args), reqFactory)
	}

	It("fails requirements when not logged in", func() {
		callDeleteRoute("y", []string{"-n", "my-host", "example.com"})
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	Context("when logged in successfully", func() {
		BeforeEach(func() {
			reqFactory.LoginSuccess = true
			route := models.Route{}
			route.Guid = "route-guid"
			route.Host = "my-host"
			route.Domain = models.DomainFields{
開發者ID:julz,項目名稱:cli,代碼行數:31,代碼來源:delete_route_test.go


注:本文中的testhelpers/terminal.FakeUI.Inputs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。