Using checkers assert for integration-cli/docker_cli_experimental_test.go

Signed-off-by: Mohammed Aaqib Ansari <maaquib@gmail.com>
This commit is contained in:
Mohammed Aaqib Ansari 2015-10-22 20:22:23 -04:00
Родитель c516aa645e
Коммит ff91c8ac1a
1 изменённых файлов: 16 добавлений и 23 удалений

Просмотреть файл

@ -11,6 +11,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/docker/docker/pkg/integration/checker"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -19,14 +20,12 @@ func (s *DockerSuite) TestExperimentalVersion(c *check.C) {
out, _ := dockerCmd(c, "version") out, _ := dockerCmd(c, "version")
for _, line := range strings.Split(out, "\n") { for _, line := range strings.Split(out, "\n") {
if strings.HasPrefix(line, "Experimental (client):") || strings.HasPrefix(line, "Experimental (server):") { if strings.HasPrefix(line, "Experimental (client):") || strings.HasPrefix(line, "Experimental (server):") {
c.Assert(line, check.Matches, "*true") c.Assert(line, checker.Matches, "*true")
} }
} }
out, _ = dockerCmd(c, "-v") out, _ = dockerCmd(c, "-v")
if !strings.Contains(out, ", experimental") { c.Assert(out, checker.Contains, ", experimental", check.Commentf("docker version did not contain experimental"))
c.Fatalf("docker version did not contain experimental: %s", out)
}
} }
// user namespaces test: run daemon with remapped root setting // user namespaces test: run daemon with remapped root setting
@ -36,49 +35,43 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
testRequires(c, NativeExecDriver) testRequires(c, NativeExecDriver)
testRequires(c, SameHostDaemon) testRequires(c, SameHostDaemon)
c.Assert(s.d.StartWithBusybox("--userns-remap", "default"), check.IsNil) c.Assert(s.d.StartWithBusybox("--userns-remap", "default"), checker.IsNil)
tmpDir, err := ioutil.TempDir("", "userns") tmpDir, err := ioutil.TempDir("", "userns")
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err)
}
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
// we need to find the uid and gid of the remapped root from the daemon's root dir info // we need to find the uid and gid of the remapped root from the daemon's root dir info
uidgid := strings.Split(filepath.Base(s.d.root), ".") uidgid := strings.Split(filepath.Base(s.d.root), ".")
c.Assert(len(uidgid), check.Equals, 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.root))) c.Assert(uidgid, checker.HasLen, 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.root)))
uid, err := strconv.Atoi(uidgid[0]) uid, err := strconv.Atoi(uidgid[0])
c.Assert(err, check.IsNil, check.Commentf("Can't parse uid: %v", err)) c.Assert(err, checker.IsNil, check.Commentf("Can't parse uid"))
gid, err := strconv.Atoi(uidgid[1]) gid, err := strconv.Atoi(uidgid[1])
c.Assert(err, check.IsNil, check.Commentf("Can't parse gid: %v", err)) c.Assert(err, checker.IsNil, check.Commentf("Can't parse gid"))
//writeable by the remapped root UID/GID pair //writeable by the remapped root UID/GID pair
c.Assert(os.Chown(tmpDir, uid, gid), check.IsNil) c.Assert(os.Chown(tmpDir, uid, gid), checker.IsNil)
out, err := s.d.Cmd("run", "-d", "--name", "userns", "-v", tmpDir+":/goofy", "busybox", "sh", "-c", "touch /goofy/testfile; top") out, err := s.d.Cmd("run", "-d", "--name", "userns", "-v", tmpDir+":/goofy", "busybox", "sh", "-c", "touch /goofy/testfile; top")
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
pid, err := s.d.Cmd("inspect", "--format='{{.State.Pid}}'", "userns") pid, err := s.d.Cmd("inspect", "--format='{{.State.Pid}}'", "userns")
if err != nil { c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid))
c.Fatalf("Could not inspect running container: out: %q; err: %v", pid, err)
}
// check the uid and gid maps for the PID to ensure root is remapped // check the uid and gid maps for the PID to ensure root is remapped
// (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1') // (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1')
out, rc1, err := runCommandPipelineWithOutput( out, rc1, err := runCommandPipelineWithOutput(
exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/uid_map"), exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/uid_map"),
exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", uid))) exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", uid)))
c.Assert(rc1, check.Equals, 0, check.Commentf("Didn't match uid_map: output: %s", out)) c.Assert(rc1, checker.Equals, 0, check.Commentf("Didn't match uid_map: output: %s", out))
out, rc2, err := runCommandPipelineWithOutput( out, rc2, err := runCommandPipelineWithOutput(
exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/gid_map"), exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/gid_map"),
exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", gid))) exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", gid)))
c.Assert(rc2, check.Equals, 0, check.Commentf("Didn't match gid_map: output: %s", out)) c.Assert(rc2, checker.Equals, 0, check.Commentf("Didn't match gid_map: output: %s", out))
// check that the touched file is owned by remapped uid:gid // check that the touched file is owned by remapped uid:gid
stat, err := system.Stat(filepath.Join(tmpDir, "testfile")) stat, err := system.Stat(filepath.Join(tmpDir, "testfile"))
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err) c.Assert(stat.UID(), checker.Equals, uint32(uid), check.Commentf("Touched file not owned by remapped root UID"))
} c.Assert(stat.GID(), checker.Equals, uint32(gid), check.Commentf("Touched file not owned by remapped root GID"))
c.Assert(stat.UID(), check.Equals, uint32(uid), check.Commentf("Touched file not owned by remapped root UID"))
c.Assert(stat.GID(), check.Equals, uint32(gid), check.Commentf("Touched file not owned by remapped root GID"))
} }