зеркало из https://github.com/microsoft/docker.git
integration-cli: add mechanism to skip tests
If DOCKER_CLIENTONLY is set for test-integration-cli, we don't set the 'daemon' build tag. 'isRemoteDaemon' will help us skip such tests without a need to move them to a separate file and accidentally lose track of them. Added `testRequires` function to skip tests based on predefined conditions evaluated in runtime. This way we can easily extend test requirements like: testRequires(t, Networking, SameHostDaemon, Linux) Signed-off-by: Ahmet Alp Balkan <ahmetb@microsoft.com>
This commit is contained in:
Родитель
ee95aa1b81
Коммит
bc37c036b5
|
@ -31,6 +31,8 @@ func TestLinksEtcHostsRegularFile(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLinksEtcHostsContentMatch(t *testing.T) {
|
||||
testRequires(t, SameHostDaemon)
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
|
@ -93,6 +95,8 @@ func TestLinksPingLinkedContainersAfterRename(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
|
||||
testRequires(t, SameHostDaemon)
|
||||
|
||||
dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10")
|
||||
dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10")
|
||||
|
||||
|
@ -197,6 +201,8 @@ func TestLinksNotStartedParentNotFail(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLinksHostsFilesInject(t *testing.T) {
|
||||
testRequires(t, SameHostDaemon)
|
||||
|
||||
defer deleteAllContainers()
|
||||
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "one", "busybox", "top"))
|
||||
|
@ -249,6 +255,8 @@ func TestLinksNetworkHostContainer(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLinksUpdateOnRestart(t *testing.T) {
|
||||
testRequires(t, SameHostDaemon)
|
||||
|
||||
defer deleteAllContainers()
|
||||
|
||||
if out, err := exec.Command(dockerBinary, "run", "-d", "--name", "one", "busybox", "top").CombinedOutput(); err != nil {
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
)
|
||||
|
||||
func TestNetworkNat(t *testing.T) {
|
||||
testRequires(t, SameHostDaemon)
|
||||
|
||||
iface, err := net.InterfaceByName("eth0")
|
||||
if err != nil {
|
||||
t.Skipf("Test not running with `make test`. Interface eth0 not found: %s", err)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
// +build !daemon
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
// tests should not assume daemon runs on the same machine as CLI
|
||||
isLocalDaemon = false
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
// +build daemon
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
// tests can assume daemon runs on the same machine as CLI
|
||||
isLocalDaemon = true
|
||||
)
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type TestCondition func() bool
|
||||
|
||||
type TestRequirement struct {
|
||||
Condition TestCondition
|
||||
SkipMessage string
|
||||
}
|
||||
|
||||
// List test requirements
|
||||
var (
|
||||
SameHostDaemon = TestRequirement{
|
||||
func() bool { return isLocalDaemon },
|
||||
"Test requires docker daemon to runs on the same machine as CLI",
|
||||
}
|
||||
)
|
||||
|
||||
// testRequires checks if the environment satisfies the requirements
|
||||
// for the test to run or skips the tests.
|
||||
func testRequires(t *testing.T, requirements ...TestRequirement) {
|
||||
for _, r := range requirements {
|
||||
if !r.Condition() {
|
||||
t.Skip(r.SkipMessage)
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче