• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang test_helpers.ExecuteCommandWithArgs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry-incubator/ltc/test_helpers.ExecuteCommandWithArgs函数的典型用法代码示例。如果您正苦于以下问题:Golang ExecuteCommandWithArgs函数的具体用法?Golang ExecuteCommandWithArgs怎么用?Golang ExecuteCommandWithArgs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ExecuteCommandWithArgs函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1:

			logsCommand = commandFactory.MakeLogsCommand()
		})

		It("tails logs", func() {
			appExaminer.AppExistsReturns(true, nil)

			doneChan := test_helpers.AsyncExecuteCommandWithArgs(logsCommand, []string{"my-app-guid"})

			Eventually(fakeTailedLogsOutputter.OutputTailedLogsCallCount).Should(Equal(1))
			Expect(fakeTailedLogsOutputter.OutputTailedLogsArgsForCall(0)).To(Equal("my-app-guid"))

			Consistently(doneChan).ShouldNot(BeClosed())
		})

		It("handles invalid appguids", func() {
			test_helpers.ExecuteCommandWithArgs(logsCommand, []string{})

			Expect(outputBuffer).To(test_helpers.SayIncorrectUsage())
			Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.InvalidSyntax}))
		})

		It("handles non existent application", func() {
			appExaminer.AppExistsReturns(false, nil)
			taskExaminer.TaskStatusReturns(task_examiner.TaskInfo{}, errors.New("task not found"))

			doneChan := test_helpers.AsyncExecuteCommandWithArgs(logsCommand, []string{"non_existent_app"})

			Eventually(fakeTailedLogsOutputter.OutputTailedLogsCallCount).Should(Equal(1))
			Expect(fakeTailedLogsOutputter.OutputTailedLogsArgsForCall(0)).To(Equal("non_existent_app"))

			Eventually(outputBuffer).Should(test_helpers.SayLine("Application or task non_existent_app not found."))
开发者ID:cloudfoundry-incubator,项目名称:ltc,代码行数:31,代码来源:logs_command_factory_test.go


示例2:

		Context("when the json file exists", func() {
			BeforeEach(func() {
				var err error
				tmpFile, err = ioutil.TempFile("", "tmp_json")
				Expect(err).ToNot(HaveOccurred())

				jsonContents = []byte(`{"Value":"test value"}`)
				Expect(ioutil.WriteFile(tmpFile.Name(), jsonContents, 0700)).To(Succeed())
			})

			It("submits a task from json", func() {
				fakeTaskRunner.SubmitTaskReturns("some-task", nil)

				args := []string{tmpFile.Name()}
				test_helpers.ExecuteCommandWithArgs(submitTaskCommand, args)

				Expect(outputBuffer).To(test_helpers.SayLine(colors.Green("Successfully submitted some-task")))
				Expect(fakeTaskRunner.SubmitTaskCallCount()).To(Equal(1))
				Expect(fakeTaskRunner.SubmitTaskArgsForCall(0)).To(Equal(jsonContents))
			})

			It("prints an error returned by the task_runner", func() {
				fakeTaskRunner.SubmitTaskReturns("some-task", errors.New("taskypoo"))

				args := []string{tmpFile.Name()}
				test_helpers.ExecuteCommandWithArgs(submitTaskCommand, args)

				Expect(fakeTaskRunner.SubmitTaskCallCount()).To(Equal(1))
				Expect(fakeTaskRunner.SubmitTaskArgsForCall(0)).To(Equal(jsonContents))
开发者ID:cloudfoundry-incubator,项目名称:ltc,代码行数:29,代码来源:task_runner_command_factory_test.go


示例3:

	})

	Describe("SSHCommand", func() {
		var sshCommand cli.Command

		BeforeEach(func() {
			commandFactory := command_factory.NewSSHCommandFactory(config, terminalUI, fakeExitHandler, fakeAppExaminer, fakeSSH)
			sshCommand = commandFactory.MakeSSHCommand()
		})

		Context("when connecting fails", func() {
			It("should print an error", func() {
				fakeAppExaminer.AppStatusReturns(app_examiner.AppInfo{ActualRunningInstances: 1}, nil)
				fakeSSH.ConnectReturns(errors.New("connection failed"))

				test_helpers.ExecuteCommandWithArgs(sshCommand, []string{"good-name"})

				Expect(outputBuffer).To(test_helpers.SayLine("Error connecting to good-name/0: connection failed"))

				Expect(fakeSSH.ConnectCallCount()).To(Equal(1))
				Expect(fakeSSH.ForwardCallCount()).To(Equal(0))
				Expect(fakeSSH.ShellCallCount()).To(Equal(0))
				Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.CommandFailed}))
			})
		})

		Describe("port forwarding", func() {
			It("should forward a local port to a remote host and port", func() {
				fakeAppExaminer.AppStatusReturns(app_examiner.AppInfo{ActualRunningInstances: 1}, nil)

				test_helpers.ExecuteCommandWithArgs(sshCommand, []string{"app-name", "-N", "-L", "mrlocalhost:1234:remotehost:5678"})
开发者ID:davidwadden,项目名称:ltc,代码行数:31,代码来源:command_factory_test.go


示例4:

				"--http-route=route-1111-wahoo:1111",
				"--http-route=route-1111-me-too:1111",
				"--env=TIMEZONE=CST",
				`--env=LANG="Chicago English"`,
				`--env=JAVA_OPTS="-Djava.arg=/dev/urandom"`,
				"--env=COLOR",
				"--env=UNSET",
				"--timeout=28s",
				"cool-web-app",
				"superfun/app:mycooltag",
				"--",
				"/start-me-please",
				"AppArg0",
				`--appFlavor="purple"`,
			}
			test_helpers.ExecuteCommandWithArgs(createCommand, args)

			Expect(fakeDockerMetadataFetcher.FetchMetadataCallCount()).To(Equal(1))
			Expect(fakeDockerMetadataFetcher.FetchMetadataArgsForCall(0)).To(Equal("superfun/app:mycooltag"))

			Expect(fakeAppRunner.CreateAppCallCount()).To(Equal(1))
			createAppParams := fakeAppRunner.CreateAppArgsForCall(0)
			Expect(createAppParams.Name).To(Equal("cool-web-app"))
			Expect(createAppParams.StartCommand).To(Equal("/start-me-please"))
			Expect(createAppParams.RootFS).To(Equal("docker:///superfun/app#mycooltag"))
			Expect(createAppParams.AppArgs).To(Equal([]string{"AppArg0", "--appFlavor=\"purple\""}))
			Expect(createAppParams.Instances).To(Equal(22))
			Expect(createAppParams.EnvironmentVariables).To(Equal(map[string]string{
				"DOCKER":       "ME",
				"TIMEZONE":     "CST",
				"LANG":         `"Chicago English"`,
开发者ID:davidwadden,项目名称:ltc,代码行数:31,代码来源:docker_runner_command_factory_test.go


示例5:

	)

	BeforeEach(func() {
		commandRan = false

		cliCommand = cli.Command{
			Name: "exec",
			Action: func(*cli.Context) {
				commandRan = true
			},
		}
	})

	Describe("ExecuteCommandWithArgs", func() {
		It("executes the command", func() {
			test_helpers.ExecuteCommandWithArgs(cliCommand, []string{})

			Expect(commandRan).To(BeTrue())
		})
	})

	Describe("AsyncExecuteCommandWithArgs", func() {
		It("executes the command", func() {
			doneChan := test_helpers.AsyncExecuteCommandWithArgs(cliCommand, []string{})

			Eventually(doneChan, 3).Should(BeClosed())
			Expect(commandRan).To(BeTrue())
		})
	})
})
开发者ID:cloudfoundry-incubator,项目名称:ltc,代码行数:30,代码来源:command_executor_test.go


示例6:

			buildDropletCommand = commandFactory.MakeBuildDropletCommand()
			fakeBlobStoreVerifier.VerifyReturns(true, nil)
		})

		Context("when the archive path is a folder and exists", func() {
			BeforeEach(func() {
				fakeCFIgnore.ShouldIgnoreStub = func(path string) bool {
					return path == "some-ignored-file"
				}
			})

			It("zips up current working folder and uploads as the droplet name", func() {
				fakeZipper.IsZipFileReturns(false)
				fakeZipper.ZipReturns("xyz.zip", nil)

				test_helpers.ExecuteCommandWithArgs(buildDropletCommand, []string{"droplet-name", "http://some.url/for/buildpack"})

				Expect(outputBuffer).To(test_helpers.SayLine("Uploading application bits..."))
				Expect(outputBuffer).To(test_helpers.SayLine("Uploaded."))

				Expect(fakeBlobStoreVerifier.VerifyCallCount()).To(Equal(1))
				Expect(fakeBlobStoreVerifier.VerifyArgsForCall(0)).To(Equal(config))

				Expect(outputBuffer).To(test_helpers.SayLine("Submitted build of droplet-name"))
				Expect(fakeDropletRunner.UploadBitsCallCount()).To(Equal(1))
				dropletName, uploadPath := fakeDropletRunner.UploadBitsArgsForCall(0)
				Expect(dropletName).To(Equal("droplet-name"))

				Expect(uploadPath).NotTo(BeNil())
				Expect(uploadPath).To(Equal("xyz.zip"))
开发者ID:davidwadden,项目名称:ltc,代码行数:30,代码来源:droplet_runner_command_factory_test.go


示例7:

			commandFactory := command_factory.NewTaskExaminerCommandFactory(fakeTaskExaminer, terminalUI, fakeExitHandler)
			taskCommand = commandFactory.MakeTaskCommand()
		})

		It("displays info for a pending task", func() {
			taskInfo := task_examiner.TaskInfo{
				TaskGuid:      "boop",
				State:         "PENDING",
				CellID:        "cell-01",
				Failed:        false,
				FailureReason: "",
				Result:        "",
			}
			fakeTaskExaminer.TaskStatusReturns(taskInfo, nil)

			test_helpers.ExecuteCommandWithArgs(taskCommand, []string{"boop"})

			Expect(outputBuffer).To(test_helpers.Say("Task GUID"))
			Expect(outputBuffer).To(test_helpers.Say("boop"))
			Expect(outputBuffer).To(test_helpers.Say("Cell ID"))
			Expect(outputBuffer).To(test_helpers.Say("cell-01"))
			Expect(outputBuffer).To(test_helpers.Say("Status"))
			Expect(outputBuffer).To(test_helpers.Say(colors.Yellow("PENDING")))
			Expect(outputBuffer).NotTo(test_helpers.Say("Result"))
			Expect(outputBuffer).NotTo(test_helpers.Say("Failure Reason"))
			Expect(outputBuffer).To(test_helpers.SayNewLine())

			Expect(fakeTaskExaminer.TaskStatusCallCount()).To(Equal(1))
			Expect(fakeTaskExaminer.TaskStatusArgsForCall(0)).To(Equal("boop"))
		})
开发者ID:davidwadden,项目名称:ltc,代码行数:30,代码来源:task_examiner_command_factory_test.go


示例8:

		BeforeEach(func() {
			versionCommand = commandFactory.MakeVersionCommand()
			fakeVersionManager.ServerVersionsReturns(version.ServerVersions{
				CfRelease:           "v219",
				CfRoutingRelease:    "v220",
				DiegoRelease:        "v221",
				GardenLinuxRelease:  "v222",
				LatticeRelease:      "v223",
				LatticeReleaseImage: "v224",
				Ltc:                 "v225",
				Receptor:            "v226",
			}, nil)
		})

		It("Prints the CLI and API versions", func() {
			test_helpers.ExecuteCommandWithArgs(versionCommand, []string{})

			Expect(outputBuffer).To(test_helpers.SayLine("Client version: 1.8.0"))
			Expect(outputBuffer).To(test_helpers.SayLine("CF release version: v219"))
			Expect(outputBuffer).To(test_helpers.SayLine("CF routing release version: v220"))
			Expect(outputBuffer).To(test_helpers.SayLine("Diego release version: v221"))
			Expect(outputBuffer).To(test_helpers.SayLine("Garden linux release version: v222"))
			Expect(outputBuffer).To(test_helpers.SayLine("Lattice release version: v223"))
			Expect(outputBuffer).To(test_helpers.SayLine("Lattice release image version: v224"))
			Expect(outputBuffer).To(test_helpers.SayLine("Receptor version: v226"))
		})

		Context("when the version manager returns an error", func() {
			It("should print an error", func() {
				fakeVersionManager.ServerVersionsReturns(version.ServerVersions{}, errors.New("failed"))
开发者ID:davidwadden,项目名称:ltc,代码行数:30,代码来源:command_factory_test.go


示例9:

				tmpFile *os.File
			)
			BeforeEach(func() {
				tmpDir = os.TempDir()
				var err error
				tmpFile, err = ioutil.TempFile(tmpDir, "tmp_json")
				Expect(err).NotTo(HaveOccurred())

				Expect(ioutil.WriteFile(tmpFile.Name(), []byte(`{"Value":"test value"}`), 0700)).To(Succeed())
			})

			It("creates an app from json", func() {
				fakeAppRunner.SubmitLrpReturns("my-json-app", nil)

				args := []string{tmpFile.Name()}
				test_helpers.ExecuteCommandWithArgs(submitLrpCommand, args)

				Expect(outputBuffer).To(test_helpers.SayLine(colors.Green("Successfully submitted my-json-app.")))
				Expect(outputBuffer).To(test_helpers.SayLine("To view the status of your application: ltc status my-json-app"))
				Expect(fakeAppRunner.SubmitLrpCallCount()).To(Equal(1))
				Expect(fakeAppRunner.SubmitLrpArgsForCall(0)).To(Equal([]byte(`{"Value":"test value"}`)))
			})

			It("prints an error returned by the app_runner", func() {
				fakeAppRunner.SubmitLrpReturns("app-that-broke", errors.New("some error"))
				args := []string{tmpFile.Name()}
				test_helpers.ExecuteCommandWithArgs(submitLrpCommand, args)

				Expect(outputBuffer).To(test_helpers.SayLine("Error creating app-that-broke: some error"))
				Expect(fakeAppRunner.SubmitLrpCallCount()).To(Equal(1))
				Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.CommandFailed}))
开发者ID:davidwadden,项目名称:ltc,代码行数:31,代码来源:app_runner_command_factory_test.go


示例10:

			Expect(newConfig.Receptor()).To(Equal("http://olduser:[email protected]"))
		}

		BeforeEach(func() {
			commandFactory := command_factory.NewConfigCommandFactory(config, terminalUI, fakeTargetVerifier, fakeBlobStoreVerifier, fakeExitHandler, fakeVersionManager)
			targetCommand = commandFactory.MakeTargetCommand()

			config.SetTarget("oldtarget.com")
			config.SetLogin("olduser", "oldpass")
			Expect(config.Save()).To(Succeed())
		})

		Context("displaying the target", func() {
			JustBeforeEach(func() {
				test_helpers.ExecuteCommandWithArgs(targetCommand, []string{})
			})

			It("outputs the current user and target host", func() {
				Expect(outputBuffer).To(test_helpers.SayLine("Target:\t\[email protected]"))
			})

			Context("when no username is set", func() {
				BeforeEach(func() {
					config.SetLogin("", "")
					Expect(config.Save()).To(Succeed())
				})

				It("only prints the target", func() {
					Expect(outputBuffer).To(test_helpers.SayLine("Target:\t\toldtarget.com"))
				})
开发者ID:davidwadden,项目名称:ltc,代码行数:30,代码来源:config_command_factory_test.go


示例11:

					FailureReason: "No compatible container",
					Result:        "Finished",
					State:         "COMPLETED",
				},
				{
					TaskGuid:      "task-guid-3",
					CellID:        "",
					Failed:        true,
					FailureReason: "",
					Result:        "",
					State:         "COMPLETED",
				},
			}
			fakeTaskExaminer.ListTasksReturns(listTasks, nil)

			test_helpers.ExecuteCommandWithArgs(listAppsCommand, []string{})

			Expect(outputBuffer).To(test_helpers.Say(colors.Bold("App Name")))
			Expect(outputBuffer).To(test_helpers.Say(colors.Bold("Instances")))
			Expect(outputBuffer).To(test_helpers.Say(colors.Bold("DiskMB")))
			Expect(outputBuffer).To(test_helpers.Say(colors.Bold("MemoryMB")))
			Expect(outputBuffer).To(test_helpers.Say(colors.Bold("Route")))

			Expect(outputBuffer).To(test_helpers.Say(colors.Bold("process1")))
			Expect(outputBuffer).To(test_helpers.Say(colors.Red("0/21")))
			Expect(outputBuffer).To(test_helpers.Say(colors.NoColor("100")))
			Expect(outputBuffer).To(test_helpers.Say(colors.NoColor("50")))
			Expect(outputBuffer).To(test_helpers.Say("alldaylong.com => 54321"))

			Expect(outputBuffer).To(test_helpers.Say(colors.Bold("process2")))
			Expect(outputBuffer).To(test_helpers.Say(colors.Yellow("9/8")))
开发者ID:SrinivasChilveri,项目名称:ltc,代码行数:31,代码来源:app_examiner_command_factory_test.go


示例12:

	BeforeEach(func() {
		fakeClusterTestRunner = &fake_cluster_test_runner.FakeClusterTestRunner{}
	})

	Describe("MakeClusterTestCommand", func() {
		var clusterTestCommand cli.Command

		BeforeEach(func() {
			commandFactory := command_factory.NewClusterTestCommandFactory(fakeClusterTestRunner)
			clusterTestCommand = commandFactory.MakeClusterTestCommand()
		})

		It("prints the integration test run output and args", func() {
			args := []string{"--timeout=50s", "--verbose=true"}
			test_helpers.ExecuteCommandWithArgs(clusterTestCommand, args)

			Expect(fakeClusterTestRunner.RunCallCount()).To(Equal(1))
			timeoutArg, verboseArg := fakeClusterTestRunner.GetArgsForRun()
			Expect(timeoutArg).To(Equal(time.Second * 50))
			Expect(verboseArg).To(BeTrue())
		})

		It("has sane defaults", func() {
			test_helpers.ExecuteCommandWithArgs(clusterTestCommand, []string{})

			Expect(fakeClusterTestRunner.RunCallCount()).To(Equal(1))
			timeoutArg, verboseArg := fakeClusterTestRunner.GetArgsForRun()
			Expect(timeoutArg).To(Equal(time.Minute * 5))
			Expect(verboseArg).To(BeFalse())
		})
开发者ID:cloudfoundry-incubator,项目名称:ltc,代码行数:30,代码来源:cluster_test_command_factory_test.go



注:本文中的github.com/cloudfoundry-incubator/ltc/test_helpers.ExecuteCommandWithArgs函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang test_helpers.Say函数代码示例发布时间:2022-05-23
下一篇:
Golang colors.Red函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap