Merge pull request #14851 from bfirsh/golint-integration-cli

Golint integration-cli
This commit is contained in:
Tibor Vass 2015-07-22 11:28:19 -04:00
commit 875fffdff8
17 changed files with 186 additions and 183 deletions

View file

@ -15,6 +15,7 @@ packages=(
daemon/network
docker
dockerinit
integration-cli
pkg/chrootarchive
pkg/directory
pkg/fileutils

View file

@ -584,7 +584,7 @@ RUN echo 'right'
}
func (s *DockerSuite) TestBuildApiLowerDockerfile(c *check.C) {
git, err := fakeGIT("repo", map[string]string{
git, err := newFakeGit("repo", map[string]string{
"dockerfile": `FROM busybox
RUN echo from dockerfile`,
}, false)
@ -609,7 +609,7 @@ RUN echo from dockerfile`,
}
func (s *DockerSuite) TestBuildApiBuildGitWithF(c *check.C) {
git, err := fakeGIT("repo", map[string]string{
git, err := newFakeGit("repo", map[string]string{
"baz": `FROM busybox
RUN echo from baz`,
"Dockerfile": `FROM busybox
@ -638,7 +638,7 @@ RUN echo from Dockerfile`,
func (s *DockerSuite) TestBuildApiDoubleDockerfile(c *check.C) {
testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows
git, err := fakeGIT("repo", map[string]string{
git, err := newFakeGit("repo", map[string]string{
"Dockerfile": `FROM busybox
RUN echo from Dockerfile`,
"dockerfile": `FROM busybox
@ -809,14 +809,14 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
c.Assert(status, check.Equals, http.StatusCreated)
type resp struct {
Id string
ID string
}
var img resp
if err := json.Unmarshal(b, &img); err != nil {
c.Fatal(err)
}
cmd, err := inspectField(img.Id, "Config.Cmd")
cmd, err := inspectField(img.ID, "Config.Cmd")
if err != nil {
c.Fatal(err)
}
@ -824,7 +824,7 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
c.Fatalf("got wrong Cmd from commit: %q", cmd)
}
// sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.Id, "ls", "/test")
dockerCmd(c, "run", img.ID, "ls", "/test")
}
func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
@ -841,26 +841,26 @@ func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
c.Assert(status, check.Equals, http.StatusCreated)
type resp struct {
Id string
ID string
}
var img resp
if err := json.Unmarshal(b, &img); err != nil {
c.Fatal(err)
}
label1, err := inspectFieldMap(img.Id, "Config.Labels", "key1")
label1, err := inspectFieldMap(img.ID, "Config.Labels", "key1")
if err != nil {
c.Fatal(err)
}
c.Assert(label1, check.Equals, "value1")
label2, err := inspectFieldMap(img.Id, "Config.Labels", "key2")
label2, err := inspectFieldMap(img.ID, "Config.Labels", "key2")
if err != nil {
c.Fatal(err)
}
c.Assert(label2, check.Equals, "value2")
cmd, err := inspectField(img.Id, "Config.Cmd")
cmd, err := inspectField(img.ID, "Config.Cmd")
if err != nil {
c.Fatal(err)
}
@ -869,7 +869,7 @@ func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
}
// sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.Id, "ls", "/test")
dockerCmd(c, "run", img.ID, "ls", "/test")
}
func (s *DockerSuite) TestContainerApiBadPort(c *check.C) {
@ -909,14 +909,14 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
c.Assert(status, check.Equals, http.StatusCreated)
type createResp struct {
Id string
ID string
}
var container createResp
if err := json.Unmarshal(b, &container); err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "start", "-a", container.Id)
out, _ := dockerCmd(c, "start", "-a", container.ID)
if strings.TrimSpace(out) != "/test" {
c.Fatalf("expected output `/test`, got %q", out)
}
@ -1050,15 +1050,15 @@ func (s *DockerSuite) TestContainerApiCreateWithCpuSharesCpuset(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusOK)
var containerJson types.ContainerJSON
var containerJSON types.ContainerJSON
c.Assert(json.Unmarshal(body, &containerJson), check.IsNil)
c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil)
out, err := inspectField(containerJson.Id, "HostConfig.CpuShares")
out, err := inspectField(containerJSON.Id, "HostConfig.CpuShares")
c.Assert(err, check.IsNil)
c.Assert(out, check.Equals, "512")
outCpuset, errCpuset := inspectField(containerJson.Id, "HostConfig.CpusetCpus")
outCpuset, errCpuset := inspectField(containerJSON.Id, "HostConfig.CpusetCpus")
c.Assert(errCpuset, check.IsNil, check.Commentf("Output: %s", outCpuset))
c.Assert(outCpuset, check.Equals, "0,1")
}
@ -1154,14 +1154,14 @@ func (s *DockerSuite) TestContainerApiPostCreateNull(c *check.C) {
c.Fatal(err)
}
type createResp struct {
Id string
ID string
}
var container createResp
if err := json.Unmarshal(b, &container); err != nil {
c.Fatal(err)
}
out, err := inspectField(container.Id, "HostConfig.CpusetCpus")
out, err := inspectField(container.ID, "HostConfig.CpusetCpus")
if err != nil {
c.Fatal(err, out)
}
@ -1169,12 +1169,12 @@ func (s *DockerSuite) TestContainerApiPostCreateNull(c *check.C) {
c.Fatalf("expected empty string, got %q", out)
}
outMemory, errMemory := inspectField(container.Id, "HostConfig.Memory")
outMemory, errMemory := inspectField(container.ID, "HostConfig.Memory")
c.Assert(outMemory, check.Equals, "0")
if errMemory != nil {
c.Fatal(errMemory, outMemory)
}
outMemorySwap, errMemorySwap := inspectField(container.Id, "HostConfig.MemorySwap")
outMemorySwap, errMemorySwap := inspectField(container.ID, "HostConfig.MemorySwap")
c.Assert(outMemorySwap, check.Equals, "0")
if errMemorySwap != nil {
c.Fatal(errMemorySwap, outMemorySwap)

View file

@ -1890,7 +1890,7 @@ func (s *DockerSuite) TestBuildCancelationKillsSleep(c *check.C) {
}
// Get the exit status of `docker build`, check it exited because killed.
if err := buildCmd.Wait(); err != nil && !IsKilled(err) {
if err := buildCmd.Wait(); err != nil && !isKilled(err) {
c.Fatalf("wait failed during build run: %T %s", err, err)
}
@ -4065,7 +4065,7 @@ func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) {
func (s *DockerSuite) TestBuildFromGIT(c *check.C) {
name := "testbuildfromgit"
git, err := fakeGIT("repo", map[string]string{
git, err := newFakeGit("repo", map[string]string{
"Dockerfile": `FROM busybox
ADD first /first
RUN [ -f /first ]
@ -4092,7 +4092,7 @@ func (s *DockerSuite) TestBuildFromGIT(c *check.C) {
func (s *DockerSuite) TestBuildFromGITWithContext(c *check.C) {
name := "testbuildfromgit"
git, err := fakeGIT("repo", map[string]string{
git, err := newFakeGit("repo", map[string]string{
"docker/Dockerfile": `FROM busybox
ADD first /first
RUN [ -f /first ]

View file

@ -10,7 +10,7 @@ import (
)
func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
testRequires(c, CpuCfsQuota)
testRequires(c, cpuCfsQuota)
name := "testbuildresourceconstraints"
ctx, err := fakeContext(`
@ -32,8 +32,8 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
MemorySwap int64
CpusetCpus string
CpusetMems string
CpuShares int64
CpuQuota int64
CPUShares int64
CPUQuota int64
}
cfg, err := inspectFieldJSON(cID, "HostConfig")
@ -45,9 +45,9 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
if err := json.Unmarshal([]byte(cfg), &c1); err != nil {
c.Fatal(err, cfg)
}
if c1.Memory != 67108864 || c1.MemorySwap != -1 || c1.CpusetCpus != "0" || c1.CpusetMems != "0" || c1.CpuShares != 100 || c1.CpuQuota != 8000 {
c.Fatalf("resource constraints not set properly:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d",
c1.Memory, c1.MemorySwap, c1.CpusetCpus, c1.CpusetMems, c1.CpuShares, c1.CpuQuota)
if c1.Memory != 67108864 || c1.MemorySwap != -1 || c1.CpusetCpus != "0" || c1.CpusetMems != "0" || c1.CPUShares != 100 || c1.CPUQuota != 8000 {
c.Fatalf("resource constraints not set properly:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CPUShares: %d, CPUQuota: %d",
c1.Memory, c1.MemorySwap, c1.CpusetCpus, c1.CpusetMems, c1.CPUShares, c1.CPUQuota)
}
// Make sure constraints aren't saved to image
@ -61,9 +61,9 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
if err := json.Unmarshal([]byte(cfg), &c2); err != nil {
c.Fatal(err, cfg)
}
if c2.Memory == 67108864 || c2.MemorySwap == -1 || c2.CpusetCpus == "0" || c2.CpusetMems == "0" || c2.CpuShares == 100 || c2.CpuQuota == 8000 {
c.Fatalf("resource constraints leaked from build:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CpuShares: %d, CpuQuota: %d",
c2.Memory, c2.MemorySwap, c2.CpusetCpus, c2.CpusetMems, c2.CpuShares, c2.CpuQuota)
if c2.Memory == 67108864 || c2.MemorySwap == -1 || c2.CpusetCpus == "0" || c2.CpusetMems == "0" || c2.CPUShares == 100 || c2.CPUQuota == 8000 {
c.Fatalf("resource constraints leaked from build:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CPUShares: %d, CPUQuota: %d",
c2.Memory, c2.MemorySwap, c2.CpusetCpus, c2.CpusetMems, c2.CPUShares, c2.CPUQuota)
}
}

View file

@ -13,37 +13,37 @@ import (
"github.com/go-check/check"
)
type FileType uint32
type fileType uint32
const (
Regular FileType = iota
Dir
Symlink
ftRegular fileType = iota
ftDir
ftSymlink
)
type FileData struct {
filetype FileType
type fileData struct {
filetype fileType
path string
contents string
}
func (fd FileData) creationCommand() string {
func (fd fileData) creationCommand() string {
var command string
switch fd.filetype {
case Regular:
case ftRegular:
// Don't overwrite the file if it already exists!
command = fmt.Sprintf("if [ ! -f %s ]; then echo %q > %s; fi", fd.path, fd.contents, fd.path)
case Dir:
case ftDir:
command = fmt.Sprintf("mkdir -p %s", fd.path)
case Symlink:
case ftSymlink:
command = fmt.Sprintf("ln -fs %s %s", fd.contents, fd.path)
}
return command
}
func mkFilesCommand(fds []FileData) string {
func mkFilesCommand(fds []fileData) string {
commands := make([]string, len(fds))
for i, fd := range fds {
@ -53,29 +53,29 @@ func mkFilesCommand(fds []FileData) string {
return strings.Join(commands, " && ")
}
var defaultFileData = []FileData{
{Regular, "file1", "file1"},
{Regular, "file2", "file2"},
{Regular, "file3", "file3"},
{Regular, "file4", "file4"},
{Regular, "file5", "file5"},
{Regular, "file6", "file6"},
{Regular, "file7", "file7"},
{Dir, "dir1", ""},
{Regular, "dir1/file1-1", "file1-1"},
{Regular, "dir1/file1-2", "file1-2"},
{Dir, "dir2", ""},
{Regular, "dir2/file2-1", "file2-1"},
{Regular, "dir2/file2-2", "file2-2"},
{Dir, "dir3", ""},
{Regular, "dir3/file3-1", "file3-1"},
{Regular, "dir3/file3-2", "file3-2"},
{Dir, "dir4", ""},
{Regular, "dir4/file3-1", "file4-1"},
{Regular, "dir4/file3-2", "file4-2"},
{Dir, "dir5", ""},
{Symlink, "symlink1", "target1"},
{Symlink, "symlink2", "target2"},
var defaultFileData = []fileData{
{ftRegular, "file1", "file1"},
{ftRegular, "file2", "file2"},
{ftRegular, "file3", "file3"},
{ftRegular, "file4", "file4"},
{ftRegular, "file5", "file5"},
{ftRegular, "file6", "file6"},
{ftRegular, "file7", "file7"},
{ftDir, "dir1", ""},
{ftRegular, "dir1/file1-1", "file1-1"},
{ftRegular, "dir1/file1-2", "file1-2"},
{ftDir, "dir2", ""},
{ftRegular, "dir2/file2-1", "file2-1"},
{ftRegular, "dir2/file2-2", "file2-2"},
{ftDir, "dir3", ""},
{ftRegular, "dir3/file3-1", "file3-1"},
{ftRegular, "dir3/file3-2", "file3-2"},
{ftDir, "dir4", ""},
{ftRegular, "dir4/file3-1", "file4-1"},
{ftRegular, "dir4/file3-2", "file4-2"},
{ftDir, "dir5", ""},
{ftSymlink, "symlink1", "target1"},
{ftSymlink, "symlink2", "target2"},
}
func defaultMkContentCommand() string {
@ -86,15 +86,15 @@ func makeTestContentInDir(c *check.C, dir string) {
for _, fd := range defaultFileData {
path := filepath.Join(dir, filepath.FromSlash(fd.path))
switch fd.filetype {
case Regular:
case ftRegular:
if err := ioutil.WriteFile(path, []byte(fd.contents+"\n"), os.FileMode(0666)); err != nil {
c.Fatal(err)
}
case Dir:
case ftDir:
if err := os.Mkdir(path, os.FileMode(0777)); err != nil {
c.Fatal(err)
}
case Symlink:
case ftSymlink:
if err := os.Symlink(fd.contents, path); err != nil {
c.Fatal(err)
}

View file

@ -476,10 +476,10 @@ func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
defer d.Restart()
bridgeName := "external-bridge"
bridgeIp := "192.169.1.1/24"
_, bridgeIPNet, _ := net.ParseCIDR(bridgeIp)
bridgeIP := "192.169.1.1/24"
_, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName)
@ -498,11 +498,11 @@ func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
_, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top")
c.Assert(err, check.IsNil)
containerIp := d.findContainerIP("ExtContainer")
ip := net.ParseIP(containerIp)
containerIP := d.findContainerIP("ExtContainer")
ip := net.ParseIP(containerIP)
c.Assert(bridgeIPNet.Contains(ip), check.Equals, true,
check.Commentf("Container IP-Address must be in the same subnet range : %s",
containerIp))
containerIP))
}
func createInterface(c *check.C, ifType string, ifName string, ipNet string) (string, error) {
@ -547,10 +547,10 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
d := s.d
bridgeIp := "192.169.1.1/24"
ip, bridgeIPNet, _ := net.ParseCIDR(bridgeIp)
bridgeIP := "192.169.1.1/24"
ip, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
err := d.StartWithBusybox("--bip", bridgeIp)
err := d.StartWithBusybox("--bip", bridgeIP)
c.Assert(err, check.IsNil)
defer d.Restart()
@ -575,11 +575,11 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top")
c.Assert(err, check.IsNil)
containerIp := d.findContainerIP("test")
ip = net.ParseIP(containerIp)
containerIP := d.findContainerIP("test")
ip = net.ParseIP(containerIP)
c.Assert(bridgeIPNet.Contains(ip), check.Equals, true,
check.Commentf("Container IP-Address must be in the same subnet range : %s",
containerIp))
containerIP))
deleteInterface(c, defaultNetworkBridge)
}
@ -622,9 +622,9 @@ func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) {
d := s.d
bridgeName := "external-bridge"
bridgeIp := "192.169.1.1/24"
bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName)
@ -649,18 +649,18 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Implicit(c *check.C) {
d := s.d
bridgeIp := "192.169.1.1"
bridgeIpNet := fmt.Sprintf("%s/24", bridgeIp)
bridgeIP := "192.169.1.1"
bridgeIPNet := fmt.Sprintf("%s/24", bridgeIP)
err := d.StartWithBusybox("--bip", bridgeIpNet)
err := d.StartWithBusybox("--bip", bridgeIPNet)
c.Assert(err, check.IsNil)
defer d.Restart()
expectedMessage := fmt.Sprintf("default via %s dev", bridgeIp)
expectedMessage := fmt.Sprintf("default via %s dev", bridgeIP)
out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
c.Assert(strings.Contains(out, expectedMessage), check.Equals, true,
check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'",
bridgeIp, strings.TrimSpace(out)))
bridgeIP, strings.TrimSpace(out)))
deleteInterface(c, defaultNetworkBridge)
}
@ -670,19 +670,19 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Explicit(c *check.C) {
d := s.d
bridgeIp := "192.169.1.1"
bridgeIpNet := fmt.Sprintf("%s/24", bridgeIp)
gatewayIp := "192.169.1.254"
bridgeIP := "192.169.1.1"
bridgeIPNet := fmt.Sprintf("%s/24", bridgeIP)
gatewayIP := "192.169.1.254"
err := d.StartWithBusybox("--bip", bridgeIpNet, "--default-gateway", gatewayIp)
err := d.StartWithBusybox("--bip", bridgeIPNet, "--default-gateway", gatewayIP)
c.Assert(err, check.IsNil)
defer d.Restart()
expectedMessage := fmt.Sprintf("default via %s dev", gatewayIp)
expectedMessage := fmt.Sprintf("default via %s dev", gatewayIP)
out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
c.Assert(strings.Contains(out, expectedMessage), check.Equals, true,
check.Commentf("Explicit default gateway should be %s, but default route was '%s'",
gatewayIp, strings.TrimSpace(out)))
gatewayIP, strings.TrimSpace(out)))
deleteInterface(c, defaultNetworkBridge)
}
@ -723,9 +723,9 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
d := s.d
bridgeName := "external-bridge"
bridgeIp := "192.169.1.1/24"
bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName)
@ -763,9 +763,9 @@ func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) {
d := s.d
bridgeName := "external-bridge"
bridgeIp := "192.169.1.1/24"
bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName)
@ -792,9 +792,9 @@ func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) {
func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *check.C) {
bridgeName := "external-bridge"
bridgeIp := "192.169.1.1/24"
bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIp)
out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName)
@ -1210,16 +1210,16 @@ func (s *DockerDaemonSuite) TestDaemonRestartKillWait(c *check.C) {
// TestHttpsInfo connects via two-way authenticated HTTPS to the info endpoint
func (s *DockerDaemonSuite) TestHttpsInfo(c *check.C) {
const (
testDaemonHttpsAddr = "localhost:4271"
testDaemonHTTPSAddr = "localhost:4271"
)
if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem",
"--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHttpsAddr); err != nil {
"--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil {
c.Fatalf("Could not start daemon with busybox: %v", err)
}
//force tcp protocol
host := fmt.Sprintf("tcp://%s", testDaemonHttpsAddr)
host := fmt.Sprintf("tcp://%s", testDaemonHTTPSAddr)
daemonArgs := []string{"--host", host, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"}
out, err := s.d.CmdWithArgs(daemonArgs, "info")
if err != nil {
@ -1232,15 +1232,15 @@ func (s *DockerDaemonSuite) TestHttpsInfo(c *check.C) {
func (s *DockerDaemonSuite) TestHttpsInfoRogueCert(c *check.C) {
const (
errBadCertificate = "remote error: bad certificate"
testDaemonHttpsAddr = "localhost:4271"
testDaemonHTTPSAddr = "localhost:4271"
)
if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem",
"--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHttpsAddr); err != nil {
"--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil {
c.Fatalf("Could not start daemon with busybox: %v", err)
}
//force tcp protocol
host := fmt.Sprintf("tcp://%s", testDaemonHttpsAddr)
host := fmt.Sprintf("tcp://%s", testDaemonHTTPSAddr)
daemonArgs := []string{"--host", host, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
out, err := s.d.CmdWithArgs(daemonArgs, "info")
if err == nil || !strings.Contains(out, errBadCertificate) {
@ -1253,15 +1253,15 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueCert(c *check.C) {
func (s *DockerDaemonSuite) TestHttpsInfoRogueServerCert(c *check.C) {
const (
errCaUnknown = "x509: certificate signed by unknown authority"
testDaemonRogueHttpsAddr = "localhost:4272"
testDaemonRogueHTTPSAddr = "localhost:4272"
)
if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-rogue-cert.pem",
"--tlskey", "fixtures/https/server-rogue-key.pem", "-H", testDaemonRogueHttpsAddr); err != nil {
"--tlskey", "fixtures/https/server-rogue-key.pem", "-H", testDaemonRogueHTTPSAddr); err != nil {
c.Fatalf("Could not start daemon with busybox: %v", err)
}
//force tcp protocol
host := fmt.Sprintf("tcp://%s", testDaemonRogueHttpsAddr)
host := fmt.Sprintf("tcp://%s", testDaemonRogueHTTPSAddr)
daemonArgs := []string{"--host", host, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
out, err := s.d.CmdWithArgs(daemonArgs, "info")
if err == nil || !strings.Contains(out, errCaUnknown) {

View file

@ -16,9 +16,9 @@ import (
// regression test for #12546
func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
contId := strings.TrimSpace(out)
contID := strings.TrimSpace(out)
cmd := exec.Command(dockerBinary, "exec", "-i", contId, "echo", "-n", "hello")
cmd := exec.Command(dockerBinary, "exec", "-i", contID, "echo", "-n", "hello")
p, err := pty.Start(cmd)
if err != nil {
c.Fatal(err)

View file

@ -139,17 +139,17 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
// create container 1
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
containerId1 := strings.TrimSpace(out)
containerID1 := strings.TrimSpace(out)
// tag as foobox
out, _ = dockerCmd(c, "commit", containerId1, "foobox")
imageId := stringid.TruncateID(strings.TrimSpace(out))
out, _ = dockerCmd(c, "commit", containerID1, "foobox")
imageID := stringid.TruncateID(strings.TrimSpace(out))
// overwrite the tag, making the previous image dangling
dockerCmd(c, "tag", "-f", "busybox", "foobox")
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
if e, a := 1, strings.Count(out, imageId); e != a {
if e, a := 1, strings.Count(out, imageID); e != a {
c.Fatalf("expected 1 dangling image, got %d: %s", a, out)
}
}

View file

@ -171,12 +171,12 @@ func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
return
}
deviceId, err := inspectField(imageTest, "GraphDriver.Data.DeviceId")
deviceID, err := inspectField(imageTest, "GraphDriver.Data.DeviceId")
c.Assert(err, check.IsNil)
_, err = strconv.Atoi(deviceId)
_, err = strconv.Atoi(deviceID)
if err != nil {
c.Fatalf("failed to inspect DeviceId of the image: %s, %v", deviceId, err)
c.Fatalf("failed to inspect DeviceId of the image: %s, %v", deviceID, err)
}
deviceSize, err := inspectField(imageTest, "GraphDriver.Data.DeviceSize")
@ -203,12 +203,12 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
return
}
deviceId, err := inspectField(out, "GraphDriver.Data.DeviceId")
deviceID, err := inspectField(out, "GraphDriver.Data.DeviceId")
c.Assert(err, check.IsNil)
_, err = strconv.Atoi(deviceId)
_, err = strconv.Atoi(deviceID)
if err != nil {
c.Fatalf("failed to inspect DeviceId of the image: %s, %v", deviceId, err)
c.Fatalf("failed to inspect DeviceId of the image: %s, %v", deviceID, err)
}
deviceSize, err := inspectField(out, "GraphDriver.Data.DeviceSize")

View file

@ -1825,7 +1825,7 @@ func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) {
dockerCmd(c, "run", "-v", "/foo", "-v", "/bar/", "--name", "dark_helmet", "run_volumes_clean_paths")
out, err := inspectMountSourceField("dark_helmet", "/foo/")
if err != mountNotFound {
if err != errMountNotFound {
c.Fatalf("Found unexpected volume entry for '/foo/' in volumes\n%q", out)
}
@ -1836,7 +1836,7 @@ func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) {
}
out, err = inspectMountSourceField("dark_helmet", "/bar/")
if err != mountNotFound {
if err != errMountNotFound {
c.Fatalf("Found unexpected volume entry for '/bar/' in volumes\n%q", out)
}

View file

@ -250,7 +250,7 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
// "test" should be printed
func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
testRequires(c, CpuCfsQuota)
testRequires(c, cpuCfsQuota)
out, _, err := dockerCmdWithError(c, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test")
if err != nil {
@ -270,7 +270,7 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
}
func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
testRequires(c, CpuCfsPeriod)
testRequires(c, cpuCfsPeriod)
if _, _, err := dockerCmdWithError(c, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true"); err != nil {
c.Fatalf("failed to run container: %v", err)
@ -284,7 +284,7 @@ func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
}
func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
testRequires(c, OomControl)
testRequires(c, oomControl)
errChan := make(chan error)
go func() {
defer close(errChan)

View file

@ -269,7 +269,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
c.Fatalf("failed to open %s: %s", layerPath, err)
}
entries, err := ListTar(f)
entries, err := listTar(f)
for _, e := range entries {
if !strings.Contains(e, "dev/") {
entriesSansDev = append(entriesSansDev, e)

View file

@ -289,6 +289,8 @@ func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
return string(b), err
}
// CmdWithArgs will execute a docker CLI command against a daemon with the
// given additional arguments
func (d *Daemon) CmdWithArgs(daemonArgs []string, name string, arg ...string) (string, error) {
args := append(daemonArgs, name)
args = append(args, arg...)
@ -297,33 +299,34 @@ func (d *Daemon) CmdWithArgs(daemonArgs []string, name string, arg ...string) (s
return string(b), err
}
// LogfileName returns the path the the daemon's log file
func (d *Daemon) LogfileName() string {
return d.logFile.Name()
}
func daemonHost() string {
daemonUrlStr := "unix://" + opts.DefaultUnixSocket
daemonURLStr := "unix://" + opts.DefaultUnixSocket
if daemonHostVar := os.Getenv("DOCKER_HOST"); daemonHostVar != "" {
daemonUrlStr = daemonHostVar
daemonURLStr = daemonHostVar
}
return daemonUrlStr
return daemonURLStr
}
func sockConn(timeout time.Duration) (net.Conn, error) {
daemon := daemonHost()
daemonUrl, err := url.Parse(daemon)
daemonURL, err := url.Parse(daemon)
if err != nil {
return nil, fmt.Errorf("could not parse url %q: %v", daemon, err)
}
var c net.Conn
switch daemonUrl.Scheme {
switch daemonURL.Scheme {
case "unix":
return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Path, timeout)
return net.DialTimeout(daemonURL.Scheme, daemonURL.Path, timeout)
case "tcp":
return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Host, timeout)
return net.DialTimeout(daemonURL.Scheme, daemonURL.Host, timeout)
default:
return c, fmt.Errorf("unknown scheme %v (%s)", daemonUrl.Scheme, daemon)
return c, fmt.Errorf("unknown scheme %v (%s)", daemonURL.Scheme, daemon)
}
}
@ -638,10 +641,12 @@ func getContainerCount() (int, error) {
return 0, fmt.Errorf("couldn't find the Container count in the output")
}
// FakeContext creates directories that can be used as a build context
type FakeContext struct {
Dir string
}
// Add a file at a path, creating directories where necessary
func (f *FakeContext) Add(file, content string) error {
return f.addFile(file, []byte(content))
}
@ -658,11 +663,13 @@ func (f *FakeContext) addFile(file string, content []byte) error {
}
// Delete a file at a path
func (f *FakeContext) Delete(file string) error {
filepath := path.Join(f.Dir, file)
return os.RemoveAll(filepath)
}
// Close deletes the context
func (f *FakeContext) Close() error {
return os.RemoveAll(f.Dir)
}
@ -898,7 +905,7 @@ func inspectMountPoint(name, destination string) (types.MountPoint, error) {
return inspectMountPointJSON(out, destination)
}
var mountNotFound = errors.New("mount point not found")
var errMountNotFound = errors.New("mount point not found")
func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
var mp []types.MountPoint
@ -915,7 +922,7 @@ func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
}
if m == nil {
return types.MountPoint{}, mountNotFound
return types.MountPoint{}, errMountNotFound
}
return *m, nil
@ -1027,7 +1034,7 @@ func buildImageFromPath(name, path string, useCache bool) (string, error) {
return getIDByName(name)
}
type GitServer interface {
type gitServer interface {
URL() string
Close() error
}
@ -1045,18 +1052,18 @@ func (r *localGitServer) URL() string {
return r.Server.URL
}
type FakeGIT struct {
type fakeGit struct {
root string
server GitServer
server gitServer
RepoURL string
}
func (g *FakeGIT) Close() {
func (g *fakeGit) Close() {
g.server.Close()
os.RemoveAll(g.root)
}
func fakeGIT(name string, files map[string]string, enforceLocalServer bool) (*FakeGIT, error) {
func newFakeGit(name string, files map[string]string, enforceLocalServer bool) (*fakeGit, error) {
ctx, err := fakeContextWithFiles(files)
if err != nil {
return nil, err
@ -1112,7 +1119,7 @@ func fakeGIT(name string, files map[string]string, enforceLocalServer bool) (*Fa
return nil, err
}
var server GitServer
var server gitServer
if !enforceLocalServer {
// use fakeStorage server, which might be local or remote (at test daemon)
server, err = fakeStorageWithContext(fakeContextFromDir(root))
@ -1124,7 +1131,7 @@ func fakeGIT(name string, files map[string]string, enforceLocalServer bool) (*Fa
httpServer := httptest.NewServer(http.FileServer(http.Dir(root)))
server = &localGitServer{httpServer}
}
return &FakeGIT{
return &fakeGit{
root: root,
server: server,
RepoURL: fmt.Sprintf("%s/%s.git", server.URL(), name),
@ -1162,8 +1169,8 @@ func readFile(src string, c *check.C) (content string) {
return string(data)
}
func containerStorageFile(containerId, basename string) string {
return filepath.Join("/var/lib/docker/containers", containerId, basename)
func containerStorageFile(containerID, basename string) string {
return filepath.Join("/var/lib/docker/containers", containerID, basename)
}
// docker commands that use this function must be run with the '-d' switch.
@ -1180,8 +1187,8 @@ func runCommandAndReadContainerFile(filename string, cmd *exec.Cmd) ([]byte, err
return readContainerFile(contID, filename)
}
func readContainerFile(containerId, filename string) ([]byte, error) {
f, err := os.Open(containerStorageFile(containerId, filename))
func readContainerFile(containerID, filename string) ([]byte, error) {
f, err := os.Open(containerStorageFile(containerID, filename))
if err != nil {
return nil, err
}
@ -1195,8 +1202,8 @@ func readContainerFile(containerId, filename string) ([]byte, error) {
return content, nil
}
func readContainerFileWithExec(containerId, filename string) ([]byte, error) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "exec", containerId, "cat", filename))
func readContainerFileWithExec(containerID, filename string) ([]byte, error) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "exec", containerID, "cat", filename))
return []byte(out), err
}

View file

@ -66,7 +66,7 @@ func (t *testRegistryV2) Ping() error {
return nil
}
func (r *testRegistryV2) Close() {
r.cmd.Process.Kill()
os.RemoveAll(r.dir)
func (t *testRegistryV2) Close() {
t.cmd.Process.Kill()
os.RemoveAll(t.dir)
}

View file

@ -13,10 +13,10 @@ import (
"github.com/go-check/check"
)
type TestCondition func() bool
type testCondition func() bool
type TestRequirement struct {
Condition TestCondition
type testRequirement struct {
Condition testCondition
SkipMessage string
}
@ -24,19 +24,19 @@ type TestRequirement struct {
var (
daemonExecDriver string
SameHostDaemon = TestRequirement{
SameHostDaemon = testRequirement{
func() bool { return isLocalDaemon },
"Test requires docker daemon to runs on the same machine as CLI",
}
UnixCli = TestRequirement{
UnixCli = testRequirement{
func() bool { return isUnixCli },
"Test requires posix utilities or functionality to run.",
}
ExecSupport = TestRequirement{
ExecSupport = testRequirement{
func() bool { return supportsExec },
"Test requires 'docker exec' capabilities on the tested daemon.",
}
Network = TestRequirement{
Network = testRequirement{
func() bool {
// Set a timeout on the GET at 15s
var timeout = time.Duration(15 * time.Second)
@ -57,14 +57,14 @@ var (
},
"Test requires network availability, environment variable set to none to run in a non-network enabled mode.",
}
Apparmor = TestRequirement{
Apparmor = testRequirement{
func() bool {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
return err == nil && len(buf) > 1 && buf[0] == 'Y'
},
"Test requires apparmor is enabled.",
}
RegistryHosting = TestRequirement{
RegistryHosting = testRequirement{
func() bool {
// for now registry binary is built only if we're running inside
// container through `make test`. Figure that out by testing if
@ -74,7 +74,7 @@ var (
},
fmt.Sprintf("Test requires an environment that can host %s in the same host", v2binary),
}
NativeExecDriver = TestRequirement{
NativeExecDriver = testRequirement{
func() bool {
if daemonExecDriver == "" {
// get daemon info
@ -98,7 +98,7 @@ var (
},
"Test requires the native (libcontainer) exec driver.",
}
NotOverlay = TestRequirement{
NotOverlay = testRequirement{
func() bool {
cmd := exec.Command("grep", "^overlay / overlay", "/proc/mounts")
if err := cmd.Run(); err != nil {
@ -108,7 +108,7 @@ var (
},
"Test requires underlying root filesystem not be backed by overlay.",
}
IPv6 = TestRequirement{
IPv6 = testRequirement{
func() bool {
cmd := exec.Command("test", "-f", "/proc/net/if_inet6")
@ -123,7 +123,7 @@ var (
// testRequires checks if the environment satisfies the requirements
// for the test to run or skips the tests.
func testRequires(c *check.C, requirements ...TestRequirement) {
func testRequires(c *check.C, requirements ...testRequirement) {
for _, r := range requirements {
if !r.Condition() {
c.Skip(r.SkipMessage)

View file

@ -10,33 +10,33 @@ import (
)
var (
CpuCfsPeriod = TestRequirement{
cpuCfsPeriod = testRequirement{
func() bool {
cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
cgroupCPUMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
if err != nil {
return false
}
if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_period_us")); err != nil {
if _, err := ioutil.ReadFile(path.Join(cgroupCPUMountpoint, "cpu.cfs_period_us")); err != nil {
return false
}
return true
},
"Test requires an environment that supports cgroup cfs period.",
}
CpuCfsQuota = TestRequirement{
cpuCfsQuota = testRequirement{
func() bool {
cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
cgroupCPUMountpoint, err := cgroups.FindCgroupMountpoint("cpu")
if err != nil {
return false
}
if _, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, "cpu.cfs_quota_us")); err != nil {
if _, err := ioutil.ReadFile(path.Join(cgroupCPUMountpoint, "cpu.cfs_quota_us")); err != nil {
return false
}
return true
},
"Test requires an environment that supports cgroup cfs quota.",
}
OomControl = TestRequirement{
oomControl = testRequirement{
func() bool {
cgroupMemoryMountpoint, err := cgroups.FindCgroupMountpoint("memory")
if err != nil {

View file

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"net/http/httptest"
"os"
"os/exec"
"path"
@ -41,7 +40,7 @@ func processExitCode(err error) (exitCode int) {
return
}
func IsKilled(err error) bool {
func isKilled(err error) bool {
if exitErr, ok := err.(*exec.ExitError); ok {
status, ok := exitErr.Sys().(syscall.WaitStatus)
if !ok {
@ -114,13 +113,13 @@ func runCommandWithOutputForDuration(cmd *exec.Cmd, duration time.Duration) (out
return
}
var ErrCmdTimeout = fmt.Errorf("command timed out")
var errCmdTimeout = fmt.Errorf("command timed out")
func runCommandWithOutputAndTimeout(cmd *exec.Cmd, timeout time.Duration) (output string, exitCode int, err error) {
var timedOut bool
output, exitCode, timedOut, err = runCommandWithOutputForDuration(cmd, timeout)
if timedOut {
err = ErrCmdTimeout
err = errCmdTimeout
}
return
}
@ -253,7 +252,7 @@ func compareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error {
return nil
}
func ListTar(f io.Reader) ([]string, error) {
func listTar(f io.Reader) ([]string, error) {
tr := tar.NewReader(f)
var entries []string
@ -270,10 +269,6 @@ func ListTar(f io.Reader) ([]string, error) {
}
}
type FileServer struct {
*httptest.Server
}
// randomUnixTmpDirPath provides a temporary unix path with rand string appended.
// does not create or checks if it exists.
func randomUnixTmpDirPath(s string) string {