示例#1
0
func TestThirdPartyCompatibility(t *testing.T) {
	test := its.NewTest(t)
	defer test.TearDown()

	test.RequireDriver("ci-test")

	test.Run("create", func() {
		test.Machine("create -d $DRIVER --url url default").Should().Succeed()
	})

	test.Run("ls", func() {
		test.Machine("ls -q").Should().Succeed().ContainLines(1).EqualLine(0, "default")
	})

	test.Run("url", func() {
		test.Machine("url default").Should().Succeed("url")
	})

	test.Run("status", func() {
		test.Machine("status default").Should().Succeed("Running")
	})

	test.Run("rm", func() {
		test.Machine("rm -y default").Should().Succeed()
	})
}
示例#2
0
func TestInspect(t *testing.T) {
	test := its.NewTest(t)
	defer test.TearDown()

	test.Run("inspect: show error in case of no args", func() {
		test.Machine("inspect").Should().Fail(`Error: No machine name(s) specified and no "default" machine exists.`)
	})
}
示例#3
0
func TestDriverHelp(t *testing.T) {
	test := its.NewTest(t)
	defer test.TearDown()

	test.SkipDriver("ci-test")

	test.Run("no --help flag or command specified", func() {
		test.Machine("create -d $DRIVER").Should().Fail("Error: No machine name specified")
	})

	test.Run("-h flag specified", func() {
		test.Machine("create -d $DRIVER -h").Should().Succeed(test.DriverName())
	})

	test.Run("--help flag specified", func() {
		test.Machine("create -d $DRIVER --help").Should().Succeed(test.DriverName())
	})
}
示例#4
0
func TestLs(t *testing.T) {
	test := its.NewTest(t)
	defer test.TearDown()

	test.Run("setup", func() {
		test.Machine("create -d none --url url5 --engine-label app=1 testmachine5").Should().Succeed()
		test.Machine("create -d none --url url4 --engine-label foo=bar --engine-label app=1 testmachine4").Should().Succeed()
		test.Machine("create -d none --url url3 testmachine3").Should().Succeed()
		test.Machine("create -d none --url url2 testmachine2").Should().Succeed()
		test.Machine("create -d none --url url1 testmachine").Should().Succeed()
	})

	test.Run("ls: no filter", func() {
		test.Machine("ls").Should().Succeed().
			ContainLines(6).
			MatchLine(0, "NAME[ ]+ACTIVE[ ]+DRIVER[ ]+STATE[ ]+URL[ ]+SWARM[ ]+DOCKER[ ]+ERRORS").
			MatchLine(1, "testmachine[ ]+-[ ]+none[ ]+Running[ ]+url1[ ]+Unknown[ ]+Unable to query docker version: .*").
			MatchLine(2, "testmachine2[ ]+-[ ]+none[ ]+Running[ ]+url2[ ]+Unknown[ ]+Unable to query docker version: .*").
			MatchLine(3, "testmachine3[ ]+-[ ]+none[ ]+Running[ ]+url3[ ]+Unknown[ ]+Unable to query docker version: .*").
			MatchLine(4, "testmachine4[ ]+-[ ]+none[ ]+Running[ ]+url4[ ]+Unknown[ ]+Unable to query docker version: .*").
			MatchLine(5, "testmachine5[ ]+-[ ]+none[ ]+Running[ ]+url5[ ]+Unknown[ ]+Unable to query docker version: .*")
	})

	test.Run("ls: filter on label", func() {
		test.Machine("ls --filter label=foo=bar").Should().Succeed().
			ContainLines(2).
			ContainLine(0, "NAME").
			ContainLine(1, "testmachine4")
	})

	test.Run("ls: mutiple filters on label", func() {
		test.Machine("ls --filter label=foo=bar --filter label=app=1").Should().Succeed().
			ContainLines(3).
			ContainLine(0, "NAME").
			ContainLine(1, "testmachine4").
			ContainLine(2, "testmachine5")
	})

	test.Run("ls: non-existing filter on label", func() {
		test.Machine("ls --filter label=invalid=filter").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")
	})

	test.Run("ls: filter on driver", func() {
		test.Machine("ls --filter driver=none").Should().Succeed().
			ContainLines(6).
			ContainLine(0, "NAME").
			ContainLine(1, "testmachine").
			ContainLine(2, "testmachine2").
			ContainLine(3, "testmachine3").
			ContainLine(4, "testmachine4").
			ContainLine(5, "testmachine5")
	})

	test.Run("ls: filter on driver", func() {
		test.Machine("ls -q --filter driver=none").Should().Succeed().
			ContainLines(5).
			EqualLine(0, "testmachine").
			EqualLine(1, "testmachine2").
			EqualLine(2, "testmachine3")
	})

	test.Run("ls: filter on state", func() {
		test.Machine("ls --filter state=Running").Should().Succeed().
			ContainLines(6).
			ContainLine(0, "NAME").
			ContainLine(1, "testmachine").
			ContainLine(2, "testmachine2").
			ContainLine(3, "testmachine3")

		test.Machine("ls -q --filter state=Running").Should().Succeed().
			ContainLines(5).
			EqualLine(0, "testmachine").
			EqualLine(1, "testmachine2").
			EqualLine(2, "testmachine3")

		test.Machine("ls --filter state=None").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")

		test.Machine("ls --filter state=Paused").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")

		test.Machine("ls --filter state=Saved").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")

		test.Machine("ls --filter state=Stopped").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")

		test.Machine("ls --filter state=Stopping").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")

		test.Machine("ls --filter state=Starting").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")

		test.Machine("ls --filter state=Error").Should().Succeed().
			ContainLines(1).
			ContainLine(0, "NAME")
	})

	test.Run("ls: filter on name", func() {
		test.Machine("ls --filter name=testmachine2").Should().Succeed().
			ContainLines(2).
			ContainLine(0, "NAME").
			ContainLine(1, "testmachine2")

		test.Machine("ls -q --filter name=testmachine3").Should().Succeed().
			ContainLines(1).
			EqualLine(0, "testmachine3")
	})

	test.Run("ls: filter on name with regex", func() {
		test.Machine("ls --filter name=^t.*e[3-5]").Should().Succeed().
			ContainLines(4).
			ContainLine(0, "NAME").
			ContainLine(1, "testmachine3").
			ContainLine(2, "testmachine4").
			ContainLine(3, "testmachine5")

		test.Machine("ls -q --filter name=^t.*e[45]").Should().Succeed().
			ContainLines(2).
			EqualLine(0, "testmachine4").
			EqualLine(1, "testmachine5")
	})

	test.Run("setup swarm", func() {
		test.Machine("create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-master --swarm-discovery token://deadbeef testswarm").Should().Succeed()
		test.Machine("create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-discovery token://deadbeef testswarm2").Should().Succeed()
		test.Machine("create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-discovery token://deadbeef testswarm3").Should().Succeed()
	})

	test.Run("ls: filter on swarm", func() {
		test.Machine("ls --filter swarm=testswarm").Should().Succeed().
			ContainLines(4).
			ContainLine(0, "NAME").
			ContainLine(1, "testswarm").
			ContainLine(2, "testswarm2").
			ContainLine(3, "testswarm3")
	})

	test.Run("ls: multi filter", func() {
		test.Machine("ls -q --filter swarm=testswarm --filter name=^t.*e --filter driver=none --filter state=Running").Should().Succeed().
			ContainLines(3).
			EqualLine(0, "testswarm").
			EqualLine(1, "testswarm2").
			EqualLine(2, "testswarm3")
	})

	test.Run("ls: format on driver", func() {
		test.Machine("ls --format {{.DriverName}}").Should().Succeed().
			ContainLines(8).
			EqualLine(0, "none").
			EqualLine(1, "none").
			EqualLine(2, "none").
			EqualLine(3, "none").
			EqualLine(4, "none").
			EqualLine(5, "none").
			EqualLine(6, "none").
			EqualLine(7, "none")
	})

	test.Run("ls: format on name and driver", func() {
		test.Machine("ls --format 'table {{.Name}}: {{.DriverName}}'").Should().Succeed().
			ContainLines(9).
			ContainLine(0, "NAME").
			EqualLine(1, "testmachine: none").
			EqualLine(2, "testmachine2: none").
			EqualLine(3, "testmachine3: none").
			EqualLine(4, "testmachine4: none").
			EqualLine(5, "testmachine5: none").
			EqualLine(6, "testswarm: none").
			EqualLine(7, "testswarm2: none").
			EqualLine(8, "testswarm3: none")
	})
}
示例#5
0
func TestCreateRm(t *testing.T) {
	test := its.NewTest(t)
	defer test.TearDown()

	test.Run("non-existent driver fails", func() {
		test.Machine("create -d bogus bogus").Should().Fail(`Driver "bogus" not found. Do you have the plugin binary accessible in your PATH?`)
	})

	test.Run("non-existent driver fails", func() {
		test.Machine("create -d bogus bogus").Should().Fail(`Driver "bogus" not found. Do you have the plugin binary accessible in your PATH?`)
	})

	test.Run("create with no name fails", func() {
		test.Machine("create -d none").Should().Fail(`Error: No machine name specified`)
	})

	test.Run("create with invalid name fails", func() {
		test.Machine("create -d none --url none ∞").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`)
	})

	test.Run("create with invalid name fails", func() {
		test.Machine("create -d none --url none -").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`)
	})

	test.Run("create with invalid name fails", func() {
		test.Machine("create -d none --url none .").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`)
	})

	test.Run("create with invalid name fails", func() {
		test.Machine("create -d none --url none ..").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`)
	})

	test.Run("create with weird but valid name succeeds", func() {
		test.Machine("create -d none --url none a").Should().Succeed()
	})

	test.Run("fail with extra argument", func() {
		test.Machine("create -d none --url none a extra").Should().Fail(`Invalid command line. Found extra arguments [extra]`)
	})

	test.Run("create with weird but valid name", func() {
		test.Machine("create -d none --url none 0").Should().Succeed()
	})

	test.Run("rm with no name fails", func() {
		test.Machine("rm -y").Should().Fail(`Error: Expected to get one or more machine names as arguments`)
	})

	test.Run("rm non existent machine fails", func() {
		test.Machine("rm ∞ -y").Should().Fail(`Error removing host "∞": Host does not exist: "∞"`)
	})

	test.Run("rm existing machine", func() {
		test.Machine("rm 0 -y").Should().Succeed()
	})

	test.Run("rm ask user confirmation when -y is not provided", func() {
		test.Machine("create -d none --url none ba").Should().Succeed()
		test.Cmd("echo y | machine rm ba").Should().Succeed()
	})

	test.Run("rm deny user confirmation when -y is not provided", func() {
		test.Machine("create -d none --url none ab").Should().Succeed()
		test.Cmd("echo n | machine rm ab").Should().Succeed()
	})

	test.Run("rm never prompt user confirmation when -f is provided", func() {
		test.Machine("create -d none --url none c").Should().Succeed()
		test.Machine("rm -f c").Should().Succeed("Successfully removed c")
	})
}
示例#6
0
func TestHelp(t *testing.T) {
	test := its.NewTest(t)
	defer test.TearDown()

	test.Run("cli: show info", func() {
		test.Machine("").Should().Succeed("Usage:", "Create and manage machines running Docker")
	})

	test.Run("cli: show active help", func() {
		test.Machine("active -h").Should().Succeed("machine active")
	})

	test.Run("cli: show config help", func() {
		test.Machine("config -h").Should().Succeed("machine config")
	})

	test.Run("cli: show create help", func() {
		test.Machine("create -h").Should().Succeed("machine create")
	})

	test.Run("cli: show env help", func() {
		test.Machine("env -h").Should().Succeed("machine env")
	})

	test.Run("cli: show inspect help", func() {
		test.Machine("inspect -h").Should().Succeed("machine inspect")
	})

	test.Run("cli: show ip help", func() {
		test.Machine("ip -h").Should().Succeed("machine ip")
	})

	test.Run("cli: show kill help", func() {
		test.Machine("kill -h").Should().Succeed("machine kill")
	})

	test.Run("cli: show ls help", func() {
		test.Machine("ls -h").Should().Succeed("machine ls")
	})

	test.Run("cli: show regenerate-certs help", func() {
		test.Machine("regenerate-certs -h").Should().Succeed("machine regenerate-certs")
	})

	test.Run("cli: show restart help", func() {
		test.Machine("restart -h").Should().Succeed("machine restart")
	})

	test.Run("cli: show rm help", func() {
		test.Machine("rm -h").Should().Succeed("machine rm")
	})

	test.Run("cli: show scp help", func() {
		test.Machine("scp -h").Should().Succeed("machine scp")
	})

	test.Run("cli: show ssh help", func() {
		test.Machine("ssh -h").Should().Succeed("machine ssh")
	})

	test.Run("cli: show start help", func() {
		test.Machine("start -h").Should().Succeed("machine start")
	})

	test.Run("cli: show status help", func() {
		test.Machine("status -h").Should().Succeed("machine status")
	})

	test.Run("cli: show stop help", func() {
		test.Machine("stop -h").Should().Succeed("machine stop")
	})

	test.Run("cli: show upgrade help", func() {
		test.Machine("upgrade -h").Should().Succeed("machine upgrade")
	})

	test.Run("cli: show url help", func() {
		test.Machine("url -h").Should().Succeed("machine url")
	})

	test.Run("cli: show version", func() {
		test.Machine("-v").Should().Succeed("version")
	})

	test.Run("cli: show help", func() {
		test.Machine("--help").Should().Succeed("Usage:")
	})
}