Skip to content

Commit

Permalink
Fix Windows CI fail due to GH13866 and patch up tests
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <[email protected]>
  • Loading branch information
John Howard committed Jul 9, 2015
1 parent 42eb82a commit c1b5244
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 339 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# if you want to ignore files created by your editor/tools,
# please consider a global .gitignore https://help.github.com/articles/ignoring-files
*.exe
*.exe~
*.orig
*.rej
*.test
Expand Down
13 changes: 10 additions & 3 deletions integration-cli/docker_api_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os/exec"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -73,6 +74,7 @@ func (s *DockerSuite) TestStoppedContainerStatsGoroutines(c *check.C) {
}

func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
testRequires(c, SameHostDaemon)
// Run container for 30 secs
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id := strings.TrimSpace(out)
Expand All @@ -85,17 +87,22 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) {

// Get the container networking stats before and after pinging the container
nwStatsPre := getNetworkStats(c, id)
_, err = exec.Command("ping", contIP, "-c", strconv.Itoa(numPings)).Output()
countParam := "-c"
if runtime.GOOS == "windows" {
countParam = "-n" // Ping count parameter is -n on Windows
}
pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).Output()
pingouts := string(pingout[:])
c.Assert(err, check.IsNil)
nwStatsPost := getNetworkStats(c, id)

// Verify the stats contain at least the expected number of packets (account for ARP)
expRxPkts := 1 + nwStatsPre.RxPackets + uint64(numPings)
expTxPkts := 1 + nwStatsPre.TxPackets + uint64(numPings)
c.Assert(nwStatsPost.TxPackets >= expTxPkts, check.Equals, true,
check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d", expTxPkts, nwStatsPost.TxPackets))
check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, nwStatsPost.TxPackets, pingouts))
c.Assert(nwStatsPost.RxPackets >= expRxPkts, check.Equals, true,
check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d", expRxPkts, nwStatsPost.RxPackets))
check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, nwStatsPost.RxPackets, pingouts))
}

func getNetworkStats(c *check.C, id string) types.Network {
Expand Down
48 changes: 0 additions & 48 deletions integration-cli/docker_cli_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"reflect"
"regexp"
Expand All @@ -13,38 +11,6 @@ import (
"github.com/go-check/check"
)

func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}

if !strings.HasPrefix(out, "-") {
c.Errorf("/etc/hosts should be a regular file")
}
}

func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) {
testRequires(c, SameHostDaemon)

runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}

hosts, err := ioutil.ReadFile("/etc/hosts")
if os.IsNotExist(err) {
c.Skip("/etc/hosts does not exist, skip this test")
}

if out != string(hosts) {
c.Errorf("container")
}

}

func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
exitCode, err := runCommand(runCmd)
Expand Down Expand Up @@ -217,20 +183,6 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) {

}

func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {

out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top"))
if err != nil {
c.Fatal(err, out)
}

out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true"))
if err == nil || !strings.Contains(out, "--net=host can't be used with links. This would result in undefined behavior") {
c.Fatalf("Running container linking to a container with --net host should have failed: %s", out)
}

}

func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
testRequires(c, SameHostDaemon, ExecSupport)

Expand Down
58 changes: 58 additions & 0 deletions integration-cli/docker_cli_links_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// +build !windows

package main

import (
"io/ioutil"
"os"
"os/exec"
"strings"

"github.com/go-check/check"
)

func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}

if !strings.HasPrefix(out, "-") {
c.Errorf("/etc/hosts should be a regular file")
}
}

func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) {
testRequires(c, SameHostDaemon)

runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts")
out, _, _, err := runCommandWithStdoutStderr(runCmd)
if err != nil {
c.Fatal(out, err)
}

hosts, err := ioutil.ReadFile("/etc/hosts")
if os.IsNotExist(err) {
c.Skip("/etc/hosts does not exist, skip this test")
}

if out != string(hosts) {
c.Errorf("container")
}

}

func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {

out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top"))
if err != nil {
c.Fatal(err, out)
}

out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true"))
if err == nil || !strings.Contains(out, "--net=host can't be used with links. This would result in undefined behavior") {
c.Fatalf("Running container linking to a container with --net host should have failed: %s", out)
}

}
77 changes: 0 additions & 77 deletions integration-cli/docker_cli_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"net"
"os/exec"
"regexp"
"sort"
Expand Down Expand Up @@ -148,82 +147,6 @@ func assertPortList(c *check.C, out string, expected []string) bool {
return true
}

func (s *DockerSuite) TestPortHostBinding(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox",
"nc", "-l", "-p", "80")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out)

runCmd = exec.Command(dockerBinary, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}

if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
c.Error("Port list is not correct")
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", "9876")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", "9876")
if out, _, err = runCommandWithOutput(runCmd); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}

func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--expose", "80", "busybox",
"nc", "-l", "-p", "80")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out)

runCmd = exec.Command(dockerBinary, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}

_, exposedPort, err := net.SplitHostPort(out)

if err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}

func stopRemoveContainer(id string, c *check.C) {
runCmd := exec.Command(dockerBinary, "rm", "-f", id)
_, _, err := runCommandWithOutput(runCmd)
Expand Down
87 changes: 87 additions & 0 deletions integration-cli/docker_cli_port_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// +build !windows

package main

import (
"net"
"os/exec"
"strings"

"github.com/go-check/check"
)

func (s *DockerSuite) TestPortHostBinding(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox",
"nc", "-l", "-p", "80")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out)

runCmd = exec.Command(dockerBinary, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}

if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
c.Error("Port list is not correct")
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", "9876")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", "9876")
if out, _, err = runCommandWithOutput(runCmd); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}

func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--expose", "80", "busybox",
"nc", "-l", "-p", "80")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}
firstID := strings.TrimSpace(out)

runCmd = exec.Command(dockerBinary, "port", firstID, "80")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
c.Fatal(out, err)
}

_, exposedPort, err := net.SplitHostPort(out)

if err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "rm", "-f", firstID)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
if out, _, err = runCommandWithOutput(runCmd); err == nil {
c.Error("Port is still bound after the Container is removed")
}
}
Loading

0 comments on commit c1b5244

Please sign in to comment.