Merge pull request #6721 from LK4D4/integration_test_on_links

Integration cli tests on Links in inspect
This commit is contained in:
Michael Crosby 2014-06-27 13:29:13 -07:00
commit 3aa75210c4
2 changed files with 36 additions and 1 deletions

View file

@ -2,12 +2,13 @@ package main
import (
"fmt"
"github.com/dotcloud/docker/pkg/iptables"
"io/ioutil"
"os"
"os/exec"
"strings"
"testing"
"github.com/dotcloud/docker/pkg/iptables"
)
func TestEtcHostsRegularFile(t *testing.T) {
@ -90,3 +91,33 @@ func TestIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
logDone("link - verify iptables when link and unlink")
}
func TestInspectLinksStarted(t *testing.T) {
defer deleteAllContainers()
cmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
cmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
cmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sleep", "10")
links, err := inspectField("testinspectlink", "HostConfig.Links")
if err != nil {
t.Fatal(err)
}
if expected := "[/container1:/testinspectlink/alias1 /container2:/testinspectlink/alias2]"; links != expected {
t.Fatalf("Links %s, but expected %s", links, expected)
}
logDone("link - links in started container inspect")
}
func TestInspectLinksStopped(t *testing.T) {
defer deleteAllContainers()
cmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
cmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
cmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
links, err := inspectField("testinspectlink", "HostConfig.Links")
if err != nil {
t.Fatal(err)
}
if expected := "[/container1:/testinspectlink/alias1 /container2:/testinspectlink/alias2]"; links != expected {
t.Fatalf("Links %s, but expected %s", links, expected)
}
logDone("link - links in stopped container inspect")
}

View file

@ -16,6 +16,10 @@ import (
func deleteContainer(container string) error {
container = strings.Replace(container, "\n", " ", -1)
container = strings.Trim(container, " ")
killArgs := fmt.Sprintf("kill %v", container)
killSplitArgs := strings.Split(killArgs, " ")
killCmd := exec.Command(dockerBinary, killSplitArgs...)
runCommand(killCmd)
rmArgs := fmt.Sprintf("rm %v", container)
rmSplitArgs := strings.Split(rmArgs, " ")
rmCmd := exec.Command(dockerBinary, rmSplitArgs...)