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

Golang gexpect.Spawn函数代码示例

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

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



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

示例1: SpawnOrFail

func (a *GoroutineAssistant) SpawnOrFail(cmd string) *gexpect.ExpectSubprocess {
	a.t.Logf("Command: %v", cmd)
	child, err := gexpect.Spawn(cmd)
	if err != nil {
		a.Fatalf("Cannot exec rkt: %v", err)
	}
	return child
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:8,代码来源:goroutineassistant.go


示例2: spawnOrFail

func spawnOrFail(t *testing.T, cmd string) *gexpect.ExpectSubprocess {
	t.Logf("Running command: %v", cmd)
	child, err := gexpect.Spawn(cmd)
	if err != nil {
		t.Fatalf("Cannot exec rkt: %v", err)
	}
	return child
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:8,代码来源:rkt_tests.go


示例3: TestUserns

func TestUserns(t *testing.T) {
	if !common.SupportsUserNS() {
		t.Skip("User namespaces are not supported on this host.")
	}

	if err := checkUserNS(); err != nil {
		t.Skip("User namespaces don't work on this host.")
	}

	// we need CAP_SYS_PTRACE to read /proc/1/root
	image := patchTestACI("rkt-inspect-stat.aci", "--exec=/inspect --stat-file", "--capability=CAP_SYS_PTRACE")
	defer os.Remove(image)
	ctx := testutils.NewRktRunCtx()
	defer ctx.Cleanup()

	for i, tt := range usernsTests {
		for _, userNsOpt := range []string{"", "--private-users"} {
			runCmd := tt.runCmd
			runCmd = strings.Replace(runCmd, "^IMAGE^", image, -1)
			runCmd = strings.Replace(runCmd, "^RKT_BIN^", ctx.Cmd(), -1)
			runCmd = strings.Replace(runCmd, "^FILE^", tt.file, -1)
			runCmd = strings.Replace(runCmd, "^USERNS^", userNsOpt, -1)

			if userNsOpt == "--private-users" {
				t.Logf("Running 'run' test #%v: %v", i, runCmd)
				child, err := gexpect.Spawn(runCmd)
				if err != nil {
					t.Fatalf("Cannot exec rkt #%v: %v", i, err)
				}

				expectedResult := tt.file + `: mode: (\w+.\w+.\w+)`
				result, _, err := expectRegexWithOutput(child, expectedResult)
				if err != nil || result[1] != tt.expectMode {
					t.Fatalf("Expected %q but not found: %v", tt.expectMode, result)
				}
				expectedResult = tt.file + `: user: (\d)`
				result, _, err = expectRegexWithOutput(child, expectedResult)
				if err != nil || result[0] == tt.expectUid {
					t.Fatalf("Expected %q but not found: %v", tt.expectUid, result)
				}
				expectedResult = tt.file + `: group: (\d)`
				result, _, err = expectRegexWithOutput(child, expectedResult)
				if err != nil || result[0] == tt.expectGid {
					t.Fatalf("Expected %q but not found: %v", tt.expectGid, result)
				}

				err = child.Wait()
				if err != nil {
					t.Fatalf("rkt didn't terminate correctly: %v", err)
				}

				ctx.Reset()
			}
		}
	}
}
开发者ID:nak3,项目名称:rkt,代码行数:56,代码来源:rkt_userns_test.go


示例4: main

func main() {
	log.Printf("Testing Ping interact... \n")

	child, err := gexpect.Spawn("ping -c8 127.0.0.1")
	if err != nil {
		panic(err)
	}
	child.Interact()
	log.Printf("Success\n")
}
开发者ID:kinvolk,项目名称:gexpect,代码行数:10,代码来源:ping.go


示例5: TestImageGCTreeStore

func TestImageGCTreeStore(t *testing.T) {
	ctx := testutils.NewRktRunCtx()
	defer ctx.Cleanup()

	expectedTreeStores := 2
	// If overlayfs is not supported only the stage1 image is rendered in the treeStore
	if !common.SupportsOverlay() {
		expectedTreeStores = 1
	}

	// at this point we know that RKT_INSPECT_IMAGE env var is not empty
	referencedACI := os.Getenv("RKT_INSPECT_IMAGE")
	cmd := fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s", ctx.Cmd(), referencedACI)
	t.Logf("Running %s: %v", referencedACI, cmd)
	child, err := gexpect.Spawn(cmd)
	if err != nil {
		t.Fatalf("Cannot exec: %v", err)
	}
	if err := child.Wait(); err != nil {
		t.Fatalf("rkt didn't terminate correctly: %v", err)
	}

	treeStoreIDs, err := getTreeStoreIDs(ctx)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	// We expect 2 treeStoreIDs for stage1 and app (only 1 if overlay is not supported/enabled)
	if len(treeStoreIDs) != expectedTreeStores {
		t.Fatalf("expected %d entries in the treestore but found %d entries", expectedTreeStores, len(treeStoreIDs))
	}

	runImageGC(t, ctx)

	treeStoreIDs, err = getTreeStoreIDs(ctx)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	// We expect 1/2 treeStoreIDs again as no pod gc has been executed
	if len(treeStoreIDs) != expectedTreeStores {
		t.Fatalf("expected %d entries in the treestore but found %d entries", expectedTreeStores, len(treeStoreIDs))
	}

	runGC(t, ctx)
	runImageGC(t, ctx)

	treeStoreIDs, err = getTreeStoreIDs(ctx)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if len(treeStoreIDs) != 0 {
		t.Fatalf("expected empty treestore but found %d entries", len(treeStoreIDs))
	}
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:53,代码来源:rkt_image_gc_test.go


示例6: removeImage

func removeImage(t *testing.T, ctx *testutils.RktRunCtx, images ...string) {
	cmd := fmt.Sprintf("%s image rm %s", ctx.Cmd(), strings.Join(images, " "))
	child, err := gexpect.Spawn(cmd)
	if err != nil {
		t.Fatalf("Cannot exec: %v", err)
	}
	if err := expectWithOutput(child, rmImageOk); err != nil {
		t.Fatalf("Expected %q but not found: %v", rmImageOk, err)
	}
	if err := child.Wait(); err != nil {
		t.Fatalf("rkt didn't terminate correctly: %v", err)
	}
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:13,代码来源:rkt_image_rm_test.go


示例7: TestUserns

func TestUserns(t *testing.T) {
	if !common.SupportsUserNS() {
		t.Skip("User namespaces are not supported on this host.")
	}

	if err := checkUserNS(); err != nil {
		t.Skip("User namespaces don't work on this host.")
	}

	image := patchTestACI("rkt-inspect-stat.aci", "--exec=/inspect --stat-file")
	defer os.Remove(image)
	ctx := testutils.NewRktRunCtx()
	defer ctx.Cleanup()

	for i, tt := range usernsTests {
		for _, userNsOpt := range []string{"", "--private-users"} {
			runCmd := tt.runCmd
			runCmd = strings.Replace(runCmd, "^IMAGE^", image, -1)
			runCmd = strings.Replace(runCmd, "^RKT_BIN^", ctx.Cmd(), -1)
			runCmd = strings.Replace(runCmd, "^FILE^", tt.file, -1)
			runCmd = strings.Replace(runCmd, "^USERNS^", userNsOpt, -1)

			t.Logf("Running 'run' test #%v: %v", i, runCmd)
			child, err := gexpect.Spawn(runCmd)
			if err != nil {
				t.Fatalf("Cannot exec rkt #%v: %v", i, err)
			}

			err = expectWithOutput(child, tt.file+": mode: "+tt.expectMode)
			if err != nil {
				t.Fatalf("Expected %q but not found: %v", tt.expectMode, err)
			}
			err = expectWithOutput(child, tt.file+": user: "+tt.expectUid)
			if err != nil {
				t.Fatalf("Expected %q but not found: %v", tt.expectUid, err)
			}
			err = expectWithOutput(child, tt.file+": group: "+tt.expectGid)
			if err != nil {
				t.Fatalf("Expected %q but not found: %v", tt.expectGid, err)
			}

			err = child.Wait()
			if err != nil {
				t.Fatalf("rkt didn't terminate correctly: %v", err)
			}

			ctx.Reset()
		}
	}
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:50,代码来源:rkt_userns_test.go


示例8: main

func main() {
	waitChan := make(chan string)

	fmt.Printf("Starting screen.. \n")

	child, err := gexpect.Spawn("screen")
	if err != nil {
		panic(err)
	}

	sender, reciever := child.AsyncInteractChannels()
	go func() {
		waitString := ""
		count := 0
		for {
			select {
			case waitString = <-waitChan:
				count++
			case msg, open := <-reciever:
				if !open {
					return
				}
				fmt.Printf("Recieved: %s\n", msg)

				if strings.Contains(msg, waitString) {
					if count >= 1 {
						waitChan <- msg
						count -= 1
					}
				}
			}
		}
	}()
	wait := func(str string) {
		waitChan <- str
		<-waitChan
	}
	fmt.Printf("Waiting until started.. \n")
	wait(" ")
	fmt.Printf("Sending Enter.. \n")
	sender <- "\n"
	wait("$")
	fmt.Printf("Sending echo.. \n")
	sender <- "echo Hello World\n"
	wait("Hello World")
	fmt.Printf("Received echo. \n")
}
开发者ID:kinvolk,项目名称:gexpect,代码行数:47,代码来源:screen.go


示例9: main

func main() {
	fmt.Printf("Starting python.. \n")
	child, err := gexpect.Spawn("python")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Expecting >>>.. \n")
	child.Expect(">>>")
	fmt.Printf("print 'Hello World'..\n")
	child.SendLine("print 'Hello World'")
	child.Expect(">>>")

	fmt.Printf("Interacting.. \n")
	child.Interact()
	fmt.Printf("Done \n")
	child.Close()
}
开发者ID:kinvolk,项目名称:gexpect,代码行数:17,代码来源:python.go


示例10: getImageID

func getImageID(ctx *testutils.RktRunCtx, name string) (string, error) {
	cmd := fmt.Sprintf(`/bin/sh -c "%s image list --fields=id,name --no-legend | grep %s | awk '{print $1}'"`, ctx.Cmd(), name)
	child, err := gexpect.Spawn(cmd)
	if err != nil {
		return "", fmt.Errorf("Cannot exec rkt: %v", err)
	}
	imageID, err := child.ReadLine()
	imageID = strings.TrimSpace(imageID)
	imageID = string(bytes.Trim([]byte(imageID), "\x00"))
	if err != nil {
		return "", fmt.Errorf("Cannot exec: %v", err)
	}
	if err := child.Wait(); err != nil {
		return "", fmt.Errorf("rkt didn't terminate correctly: %v", err)
	}
	return imageID, nil
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:17,代码来源:rkt_image_rm_test.go


示例11: TestPrepareAppEnsureEtcHosts

func TestPrepareAppEnsureEtcHosts(t *testing.T) {
	etcHostsCreateImage := patchTestACI("rkt-inspect-etc-hosts-create.aci", "--exec=/inspect --read-file")
	defer os.Remove(etcHostsCreateImage)
	etcHostsExistsImage := patchTestACI("rkt-inspect-etc-hosts-exists.aci", "--exec=/inspect --read-file", "--mounts=etc,path=/etc,readOnly=false")
	defer os.Remove(etcHostsExistsImage)
	ctx := testutils.NewRktRunCtx()
	defer ctx.Cleanup()

	tmpdir := createTempDirOrPanic("rkt-tests.")
	defer os.RemoveAll(tmpdir)
	tmpetc := createTempDirOrPanic("rkt-tests-etc.")
	defer os.RemoveAll(tmpetc)

	tmpfile := filepath.Join(tmpetc, "hosts")
	if err := ioutil.WriteFile(tmpfile, []byte(`<<<preexisting etc>>>`), 0600); err != nil {
		t.Fatalf("Cannot create etc/hosts file: %v", err)
	}

	for i, tt := range etcHostsTests {
		cmd := strings.Replace(tt.rktCmd, "^TMPDIR^", tmpdir, -1)
		cmd = strings.Replace(cmd, "^RKT_BIN^", ctx.Cmd(), -1)
		cmd = strings.Replace(cmd, "^ETC_HOSTS_CREATE^", etcHostsCreateImage, -1)
		cmd = strings.Replace(cmd, "^ETC_HOSTS_EXISTS^", etcHostsExistsImage, -1)
		cmd = strings.Replace(cmd, "^TMPETC^", tmpetc, -1)

		t.Logf("Running test #%v: %v", i, cmd)

		child, err := gexpect.Spawn(cmd)
		if err != nil {
			t.Fatalf("Cannot exec rkt #%v: %v", i, err)
		}

		_, _, err = expectRegexTimeoutWithOutput(child, tt.expectRegEx, time.Minute)
		if err != nil {
			t.Fatalf("Expected %q but not found #%v: %v", tt.expectRegEx, i, err)
		}

		err = child.Wait()
		if err != nil {
			t.Fatalf("rkt didn't terminate correctly: %v", err)
		}
	}
}
开发者ID:nak3,项目名称:rkt,代码行数:43,代码来源:rkt_etc_hosts_test.go


示例12: main

func main() {
	log.Printf("Testing Ftp... ")

	child, err := gexpect.Spawn("ftp ftp.openbsd.org")
	if err != nil {
		panic(err)
	}
	child.Expect("Name")
	child.SendLine("anonymous")
	child.Expect("Password")
	child.SendLine("[email protected]")
	child.Expect("ftp> ")
	child.SendLine("cd /pub/OpenBSD/3.7/packages/i386")
	child.Expect("ftp> ")
	child.SendLine("bin")
	child.Expect("ftp> ")
	child.SendLine("prompt")
	child.Expect("ftp> ")
	child.SendLine("pwd")
	child.Expect("ftp> ")
	log.Printf("Success\n")
}
开发者ID:kinvolk,项目名称:gexpect,代码行数:22,代码来源:ftp.go


示例13: spawnCmd

func spawnCmd(args []string) (*gexpect.ExpectSubprocess, error) {
	// redirect stderr to stdout since gexpect only uses stdout
	cmd := `/bin/sh -c "` + strings.Join(args, " ") + ` 2>&1 "`
	return gexpect.Spawn(cmd)
}
开发者ID:rhuss,项目名称:gofabric8,代码行数:5,代码来源:etcd_test.go


示例14: TestEtcHosts

/*
	The stage0 can create an etc hosts

	prepare-app will overwrite the app's /etc/hosts if the stage0 created one
	Otherwise, it will create a fallback /etc/hosts if the stage2 does not have one
*/
func TestEtcHosts(t *testing.T) {
	ctx := testutils.NewRktRunCtx()
	defer ctx.Cleanup()

	tmpdir := createTempDirOrPanic("rkt-tests.")
	defer os.RemoveAll(tmpdir)
	tmpetc := createTempDirOrPanic("rkt-tests-etc.")
	defer os.RemoveAll(tmpetc)

	tmpfile := filepath.Join(tmpetc, "hosts")
	if err := ioutil.WriteFile(tmpfile, []byte(`<<<preexisting etc>>>`), 0600); err != nil {
		t.Fatalf("Cannot create etc/hosts file: %v", err)
	}

	dat, err := ioutil.ReadFile("/etc/hosts")
	if err != nil {
		t.Fatal("Could not read host's /etc/hosts", err)
	}

	sum := fmt.Sprintf("%x", sha1.Sum(dat))

	tests := []struct {
		rktArgs     string
		inspectArgs string
		expectRegEx string
	}{
		{
			fmt.Sprintf("--volume hosts,kind=host,source=%s", tmpfile),
			"--mount volume=hosts,target=/etc/hosts --exec=/inspect -- -file-name=/etc/hosts -read-file",
			"<<<preexisting etc>>>",
		},
		{ // Test that with no /etc/hosts, the fallback is created
			"",
			"--exec=/inspect -- -file-name=/etc/hosts -hash-file",
			"192f716fb0db669de1c537b845b632f03c9aeb40",
		},
		{ // Test that with --hosts-entry=host, the host's is copied
			"--hosts-entry=host",
			"--exec=/inspect -- -file-name=/etc/hosts -hash-file",
			sum,
		},
		{ // test that we create our own
			"--hosts-entry=128.66.0.99=host1",
			"--exec=/inspect -- -file-name=/etc/hosts -read-file",
			"128.66.0.99 host1",
		},
	}

	for i, tt := range tests {
		cmd := fmt.Sprintf(
			"%s run --insecure-options=image %s %s %s",
			ctx.Cmd(),
			tt.rktArgs,
			getInspectImagePath(),
			tt.inspectArgs)

		t.Logf("Running test #%v: %v", i, cmd)

		child, err := gexpect.Spawn(cmd)
		if err != nil {
			t.Fatalf("Cannot exec rkt #%v: %v", i, err)
		}

		_, out, err := expectRegexTimeoutWithOutput(child, tt.expectRegEx, 30*time.Second)
		if err != nil {
			t.Fatalf("Test %d %v %v", i, err, out)
		}

		waitOrFail(t, child, 0)
	}
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:77,代码来源:rkt_etc_hosts_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang gexpect.ExpectSubprocess类代码示例发布时间:2022-05-23
下一篇:
Golang gexpect.Command函数代码示例发布时间: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