Golang Start示例

说明

golang start示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: github.com/onsi/gomega/gexec

示例#1
文件: utils.go 项目: projectcalico/calico-cni

func DeleteContainer(netconf, netnspath, name string) (session *gexec.Session, err error) {
	netnsname := path.Base(netnspath)
	container_id := netnsname[:10]
	var k8s_env = ""
	if name != "" {

		k8s_env = fmt.Sprintf("CNI_ARGS=\"K8S_POD_NAME=%s;K8S_POD_NAMESPACE=test;K8S_POD_INFRA_CONTAINER_ID=whatever\"", name)
	}

	// Set up the env for running the CNI plugin
	cni_env := fmt.Sprintf("CNI_COMMAND=DEL CNI_CONTAINERID=%s CNI_NETNS=%s CNI_IFNAME=eth0 CNI_PATH=dist %s", container_id, netnspath, k8s_env)

	// Run the CNI plugin passing in the supplied netconf
	subProcess := exec.Command("bash", "-c", fmt.Sprintf("%s dist/%s", cni_env, os.Getenv("PLUGIN")), netconf)
	stdin, err := subProcess.StdinPipe()
	if err != nil {
		panic("some error found")
	}

	io.WriteString(stdin, netconf)
	io.WriteString(stdin, "\n")
	stdin.Close()

	session, err = gexec.Start(subProcess, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	return
}

示例#2
文件: integration_suite_test.go 项目: jamiemonserrate/temp-to-delete

func startRedis(configPath string) {
	cmd := exec.Command("redis-server", configPath)
	var err error
	redisSession, err = gexec.Start(cmd, nil, nil)
	Expect(err).ToNot(HaveOccurred())
	time.Sleep(time.Second * 5)
}

示例#3
文件: helpers.go 项目: tsheasha/AWSnycast

func RunTerraform() {
	command := exec.Command("terraform", "apply")
	session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Ω(err).ShouldNot(HaveOccurred())
	session.Wait(1800 * time.Second)
	Eventually(session).Should(gexec.Exit(0))
}

示例#4
文件: nats_runner.go 项目: rakutentech/gorouter

func (runner *NATSRunner) Start() {
	if runner.natsSession != nil {
		panic("starting an already started NATS runner!!!")
	}

	_, err := exec.LookPath("gnatsd")
	if err != nil {
		fmt.Println("You need gnatsd installed!")
		os.Exit(1)
	}

	cmd := exec.Command("gnatsd", "-p", strconv.Itoa(runner.port))
	sess, err := gexec.Start(
		cmd,
		gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[34m[gnatsd]\x1b[0m ", ginkgo.GinkgoWriter),
		gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[34m[gnatsd]\x1b[0m ", ginkgo.GinkgoWriter),
	)
	Expect(err).NotTo(HaveOccurred(), "Make sure to have gnatsd on your path")

	runner.natsSession = sess

	Expect(err).NotTo(HaveOccurred())

	var messageBus *nats.Conn
	Eventually(func() error {
		messageBus, err = nats.Connect(fmt.Sprintf("nats://127.0.0.1:%d", runner.port))
		return err
	}, 5, 0.1).ShouldNot(HaveOccurred())

	runner.MessageBus = messageBus
}

示例#5
文件: bbl.go 项目: pivotal-cf-experimental/bosh-bootloader

func (b BBL) execute(args []string, stdout io.Writer, stderr io.Writer) *gexec.Session {
	cmd := exec.Command(b.pathToBBL, args...)
	session, err := gexec.Start(cmd, stdout, stderr)
	Expect(err).NotTo(HaveOccurred())

	return session
}

示例#6
文件: stager_runner.go 项目: cfibmers/stager

func (r *StagerRunner) Start(args ...string) {
	if r.session != nil {
		panic("starting more than one stager runner!!!")
	}

	stagerSession, err := gexec.Start(
		exec.Command(
			r.Config.StagerBin,
			append([]string{
				"-bbsAddress", r.Config.BBSURL,
				"-listenAddress", r.Config.ListenAddress,
				"-stagingTaskCallbackURL", r.Config.TaskCallbackURL,
				"-ccBaseURL", r.Config.CCBaseURL,
				"-dockerStagingStack", r.Config.DockerStagingStack,
				"-consulCluster", r.Config.ConsulCluster,
			}, args...)...,
		),
		gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[95m[stager]\x1b[0m ", ginkgo.GinkgoWriter),
		gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[95m[stager]\x1b[0m ", ginkgo.GinkgoWriter),
	)

	Expect(err).NotTo(HaveOccurred())

	r.session = stagerSession
}

示例#7
文件: fake_starter.go 项目: nickwei84/cf-acceptance-tests

func (s *FakeCmdStarter) Start(reporter internal.Reporter, executable string, args ...string) (*gexec.Session, error) {
	output := s.ToReturn[s.TotalCallsToStart].Output
	if output == "" {
		output = `\{\}`
	}
	sleepTime := s.ToReturn[s.TotalCallsToStart].SleepTime
	exitCode := s.ToReturn[s.TotalCallsToStart].ExitCode
	err := s.ToReturn[s.TotalCallsToStart].Err

	s.TotalCallsToStart += 1

	callToStart := callToStartMethod{
		Executable: executable,
		Args:       args,
		Reporter:   reporter,
	}
	s.CalledWith = append(s.CalledWith, callToStart)

	reporter.Report(time.Now(), exec.Command(executable, args...))
	cmd := exec.Command(
		"bash",
		"-c",
		fmt.Sprintf(
			"echo %s; sleep %d; exit %d",
			output,
			sleepTime,
			exitCode,
		),
	)
	session, _ := gexec.Start(cmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	return session, err
}

示例#8
文件: runner.go 项目: vito/warden-linux

func (r *Runner) Start(argv ...string) error {
	wardenArgs := argv
	wardenArgs = append(
		wardenArgs,
		"--listenNetwork", r.Network,
		"--listenAddr", r.Addr,
		"--bin", r.BinPath,
		"--depot", r.DepotPath,
		"--rootfs", r.RootFSPath,
		"--snapshots", r.SnapshotsPath,
		"--debug",
		"--disableQuotas",
	)

	warden := exec.Command(r.wardenBin, wardenArgs...)

	warden.Stdout = os.Stdout
	warden.Stderr = os.Stderr

	session, err := gexec.Start(warden, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	if err != nil {
		return err
	}

	r.wardenSession = session

	return r.WaitForStart()
}

示例#9
文件: ui_test.go 项目: robdimsdale/garagepi

func startMainWithArgs(args ...string) *gexec.Session {
	command := exec.Command(garagepiBinPath, args...)
	session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
	Eventually(session).Should(gbytes.Say("garagepi starting"))
	return session
}

示例#10
文件: runner.go 项目: xoebus/checkin

func (runner *Runner) Truncate() {
	truncate := exec.Command(
		"psql",
		"-U", "postgres",
		"-p", strconv.Itoa(runner.Port),
		"testdb",
		"-c", `
			SET client_min_messages TO WARNING;

			CREATE OR REPLACE FUNCTION truncate_tables() RETURNS void AS $$
			DECLARE
					statements CURSOR FOR
							SELECT tablename FROM pg_tables
							WHERE schemaname = 'public' AND tablename != 'migration_version';
			BEGIN
					FOR stmt IN statements LOOP
							EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' RESTART IDENTITY CASCADE;';
					END LOOP;
			END;
			$$ LANGUAGE plpgsql;

			SELECT truncate_tables();
		`,
	)

	truncateS, err := gexec.Start(truncate, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	<-truncateS.Exited

	Expect(truncateS).To(gexec.Exit(0))
}

示例#11
文件: agentintegration_suite_test.go 项目: nimbus-cloud/cf-redis-broker

func startAgent() *gexec.Session {
	config := &agentconfig.Config{
		DefaultConfPath:     helpers.AssetPath("redis.conf.default"),
		ConfPath:            redisConfPath,
		MonitExecutablePath: helpers.AssetPath("fake_monit"),
		Port:                "9876",
		AuthConfiguration: agentconfig.AuthConfiguration{
			Username: "admin",
			Password: "supersecretpassword",
		},
	}

	configFile, err := ioutil.TempFile("", "config.yml")
	Expect(err).ToNot(HaveOccurred())

	encoder := candiedyaml.NewEncoder(configFile)
	err = encoder.Encode(config)
	Ω(err).ShouldNot(HaveOccurred())
	configFile.Close()

	agentPath, err := gexec.Build("github.com/pivotal-cf/cf-redis-broker/cmd/agent")
	Ω(err).ShouldNot(HaveOccurred())

	session, err := gexec.Start(
		exec.Command(agentPath, fmt.Sprintf("-agentConfig=%s", configFile.Name())),
		GinkgoWriter,
		GinkgoWriter,
	)
	Ω(err).ShouldNot(HaveOccurred())

	Expect(helpers.ServiceAvailable(9876)).To(BeTrue())
	return session
}

示例#12
文件: integration_suite_test.go 项目: jamiemonserrate/temp-to-delete

func runBinary(params ...string) *gexec.Session {
	command := exec.Command(pathToBinary, params...)
	session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).ToNot(HaveOccurred())
	session.Wait()
	return session
}

示例#13
文件: simulation_suite_test.go 项目: emc-xchallenge/auction

func launchExternalHTTPReps() map[string]rep.SimClient {
	repNodeBinary, err := gexec.Build("github.com/cloudfoundry-incubator/auction/simulation/repnode")
	Expect(err).NotTo(HaveOccurred())

	cells := map[string]rep.SimClient{}

	client := &http.Client{
		Timeout: timeout,
	}
	for i := 0; i < numCells; i++ {
		repGuid := cellGuid(i)
		httpAddr := fmt.Sprintf("127.0.0.1:%d", 30000+i)

		serverCmd := exec.Command(
			repNodeBinary,
			"-repGuid", repGuid,
			"-httpAddr", httpAddr,
			"-memoryMB", fmt.Sprintf("%d", repResources.MemoryMB),
			"-diskMB", fmt.Sprintf("%d", repResources.DiskMB),
			"-containers", fmt.Sprintf("%d", repResources.Containers),
			"-stack", linuxStack,
			"-zone", zone(i),
		)

		sess, err := gexec.Start(serverCmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
		sessionsToTerminate = append(sessionsToTerminate, sess)
		Eventually(sess).Should(gbytes.Say("listening"))

		cells[cellGuid(i)] = rep.NewClient(client, "http://"+httpAddr).(rep.SimClient)
	}

	return cells
}

示例#14
文件: helpers.go 项目: rakutentech/loggregator

func StartUnencryptedTCPServer(pathToTCPEchoServer string, syslogDrainAddress string) *gexec.Session {
	command := exec.Command(pathToTCPEchoServer, "-address", syslogDrainAddress)
	drainSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	return drainSession
}

示例#15
文件: helpers.go 项目: rakutentech/loggregator

func StartHTTPSServer(pathToHTTPEchoServer string) *gexec.Session {
	command := exec.Command(pathToHTTPEchoServer, "-cert", "fixtures/key.crt", "-key", "fixtures/key.key")
	session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	return session
}

示例#16
文件: create_test.go 项目: cloudfoundry/guardian

func numPipes(pid int) (num int) {
	sess, err := gexec.Start(exec.Command("sh", "-c", fmt.Sprintf("lsof -p %d | grep pipe", pid)), GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
	Eventually(sess).Should(gexec.Exit(0))

	return bytes.Count(sess.Out.Contents(), []byte{'\n'})
}

示例#17
文件: helpers.go 项目: rakutentech/loggregator

func StartEncryptedTCPServer(pathToTCPEchoServer string, syslogDrainAddress string) *gexec.Session {
	command := exec.Command(pathToTCPEchoServer, "-address", syslogDrainAddress, "-ssl", "-cert", "fixtures/key.crt", "-key", "fixtures/key.key")
	drainSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	return drainSession
}

示例#18
文件: tag_release_test.go 项目: alphagov/paas-cf

func runBashScript(baseCmd *exec.Cmd, script string) *gexec.Session {
	cmd := bashScript(baseCmd, script)
	session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
	Expect(err).ToNot(HaveOccurred())
	Eventually(session, ExecutionTimeout).Should(gexec.Exit(0))
	return session
}

示例#19
文件: run.go 项目: predix/rdpg-boshrelease

func innerRun(cmd *exec.Cmd) *gexec.Session {
	sayCommandWillRun(time.Now(), cmd)

	sess, err := gexec.Start(CommandInterceptor(cmd), ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	return sess
}

示例#20
文件: syslog_writer_test.go 项目: Jonty/loggregator

func startSyslogServer(syslogDrainAddress string) *gexec.Session {
	command := exec.Command(pathToTCPEchoServer, "-address", syslogDrainAddress)
	drainSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	time.Sleep(1000 * time.Millisecond) // give time for server to come up
	return drainSession
}

示例#21
文件: ctl_test.go 项目: glestaris/clique

func cleanupCliqueAgent() {
	sess, err := gexec.Start(
		exec.Command("pkill", "-9", "clique-agent"),
		GinkgoWriter, GinkgoWriter,
	)
	Expect(err).NotTo(HaveOccurred())
	Eventually(sess).Should(gexec.Exit())
}

示例#22
文件: tls_writer_test.go 项目: JimmyMa/loggregator

func startEncryptedTCPServer(syslogDrainAddress string) *gexec.Session {
	command := exec.Command(pathToTCPEchoServer, "-address", syslogDrainAddress, "-ssl", "-cert", "fixtures/key.crt", "-key", "fixtures/key.key")
	drainSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
	Eventually(drainSession.Err, 10).Should(gbytes.Say("Startup: tcp echo server listening"))

	return drainSession
}

示例#23
文件: init_test.go 项目: pivotal-cf-experimental/bosh-bootloader

func executeCommand(args []string, exitCode int) *gexec.Session {
	cmd := exec.Command(pathToBBL, args...)
	session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
	Eventually(session, 10*time.Second).Should(gexec.Exit(exitCode))

	return session
}

示例#24
文件: integration_test.go 项目: wdxxs2z/greenhouse-install-script-generator

func StartGeneratorWithArgs(args ...string) *gexec.Session {
	generatePath, err := gexec.Build("generate")
	Expect(err).NotTo(HaveOccurred())
	command := exec.Command(generatePath, args...)
	session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
	return session
}

示例#25
文件: postgresrunner.go 项目: utako/atc

func (runner *Runner) CreateTestDB() {
	createdb := exec.Command("createdb", "-U", "postgres", "-p", strconv.Itoa(runner.Port), "testdb")

	createS, err := gexec.Start(createdb, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	Ω(err).ShouldNot(HaveOccurred())

	status := createS.Wait(10 * time.Second)
	if status.ExitCode() != 0 {
		runner.DropTestDB()

		createdb := exec.Command("createdb", "-U", "postgres", "-p", strconv.Itoa(runner.Port), "testdb")
		createS, err = gexec.Start(createdb, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
		Ω(err).ShouldNot(HaveOccurred())
	}

	Eventually(createS, 10*time.Second).Should(gexec.Exit(0))
}

示例#26
文件: postgresrunner.go 项目: ACPK/atc

func (runner *Runner) Truncate() {
	truncate := exec.Command(
		"psql",
		"-U", "postgres",
		"-p", strconv.Itoa(runner.Port),
		"testdb",
		"-c", `
			SET client_min_messages TO WARNING;

			CREATE OR REPLACE FUNCTION truncate_tables() RETURNS void AS $$
			DECLARE
					statements CURSOR FOR
							SELECT tablename FROM pg_tables
							WHERE schemaname = 'public' AND tablename != 'migration_version';
			BEGIN
					FOR stmt IN statements LOOP
							EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' RESTART IDENTITY CASCADE;';
					END LOOP;
			END;
			$$ LANGUAGE plpgsql;

			CREATE OR REPLACE FUNCTION drop_ephemeral_sequences() RETURNS void AS $$
			DECLARE
					statements CURSOR FOR
							SELECT relname FROM pg_class
							WHERE relname LIKE 'build_event_id_seq_%';
			BEGIN
					FOR stmt IN statements LOOP
							EXECUTE 'DROP SEQUENCE ' || quote_ident(stmt.relname) || ';';
					END LOOP;
			END;
			$$ LANGUAGE plpgsql;

			CREATE OR REPLACE FUNCTION reset_global_sequences() RETURNS void AS $$
			DECLARE
					statements CURSOR FOR
							SELECT relname FROM pg_class
							WHERE relname IN ('one_off_name', 'config_version_seq');
			BEGIN
					FOR stmt IN statements LOOP
							EXECUTE 'ALTER SEQUENCE ' || quote_ident(stmt.relname) || ' RESTART WITH 1;';
					END LOOP;
			END;
			$$ LANGUAGE plpgsql;

			SELECT truncate_tables();
			SELECT drop_ephemeral_sequences();
			SELECT reset_global_sequences();
		`,
	)

	truncateS, err := gexec.Start(truncate, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	<-truncateS.Exited

	Expect(truncateS).To(gexec.Exit(0))
}

示例#27
文件: cluster_test_runner.go 项目: rowhit/lattice

func (runner *clusterTestRunner) removeApp(timeout time.Duration, appName string, args ...string) {
	fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to remove app %s", appName)))

	command := runner.command("remove", appName)
	session, err := gexec.Start(command, getStyledWriter("remove"), getStyledWriter("remove"))
	Expect(err).NotTo(HaveOccurred())

	expectExit(timeout, session)
}

示例#28
文件: postgresrunner.go 项目: ACPK/atc

func (runner *Runner) DropTestDB() {
	dropdb := exec.Command("dropdb", "-U", "postgres", "-p", strconv.Itoa(runner.Port), "testdb")
	dropS, err := gexec.Start(dropdb, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())

	<-dropS.Exited

	Expect(dropS).To(gexec.Exit(0))
}

示例#29
文件: focker_test.go 项目: hatofmonkeys/cloudfocker

func cp(src string, dst string) {
	session, err := gexec.Start(
		exec.Command("cp", "-a", src, dst),
		GinkgoWriter,
		GinkgoWriter,
	)
	Ω(err).ShouldNot(HaveOccurred())
	Eventually(session).Should(gexec.Exit(0))
}

示例#30
文件: run.go 项目: mattcui/bosh-init

func RunComplexCommand(cmd *exec.Cmd) (*gexec.Session, error) {
	session, err := gexec.Start(cmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
	if err != nil {
		return nil, err
	}

	session.Wait(20 * time.Second)
	return session, nil
}

展开阅读全文