summaryrefslogtreecommitdiffhomepage
path: root/runsc/test/root/chroot_test.go
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-01-14 14:07:05 -0800
committerShentubot <shentubot@google.com>2019-01-14 14:08:19 -0800
commita46b6d453d198b96949342a81750114bfa5a5429 (patch)
tree71c32eae0ee72b46576226b0266ed63e0bf93463 /runsc/test/root/chroot_test.go
parent7182b9cf52087bc354104ad2a23fcf4c468ab20e (diff)
runsc: set up a minimal chroot from the sandbox process
In this case, new mounts are not created in the host mount namspaces, so tearDownChroot isn't needed, because chroot will be destroyed with a sandbox mount namespace. In additional, pivot_root can't be called instead of chroot. PiperOrigin-RevId: 229250871 Change-Id: I765bdb587d0b8287a6a8efda8747639d37c7e7b6
Diffstat (limited to 'runsc/test/root/chroot_test.go')
-rw-r--r--runsc/test/root/chroot_test.go16
1 files changed, 6 insertions, 10 deletions
diff --git a/runsc/test/root/chroot_test.go b/runsc/test/root/chroot_test.go
index 9f705c860..04124703d 100644
--- a/runsc/test/root/chroot_test.go
+++ b/runsc/test/root/chroot_test.go
@@ -52,12 +52,13 @@ func TestChroot(t *testing.T) {
}
// Check that sandbox is chroot'ed.
- chroot, err := filepath.EvalSymlinks(filepath.Join("/proc", strconv.Itoa(pid), "root"))
+ procRoot := filepath.Join("/proc", strconv.Itoa(pid), "root")
+ chroot, err := filepath.EvalSymlinks(procRoot)
if err != nil {
t.Fatalf("error resolving /proc/<pid>/root symlink: %v", err)
}
- if want := "/tmp/runsc-sandbox-chroot-"; !strings.HasPrefix(chroot, want) {
- t.Errorf("sandbox is not chroot'd, it should be inside: %q, got: %q", want, chroot)
+ if chroot != "/" {
+ t.Errorf("sandbox is not chroot'd, it should be inside: /, got: %q", chroot)
}
path, err := filepath.EvalSymlinks(filepath.Join("/proc", strconv.Itoa(pid), "cwd"))
@@ -68,12 +69,12 @@ func TestChroot(t *testing.T) {
t.Errorf("sandbox current dir is wrong, want: %q, got: %q", chroot, path)
}
- fi, err := ioutil.ReadDir(chroot)
+ fi, err := ioutil.ReadDir(procRoot)
if err != nil {
t.Fatalf("error listing %q: %v", chroot, err)
}
if want, got := 2, len(fi); want != got {
- t.Fatalf("chroot dir got %d entries, want %d", want, got)
+ t.Fatalf("chroot dir got %d entries, want %d", got, want)
}
// chroot dir is prepared by runsc and should contains only the executable
@@ -85,11 +86,6 @@ func TestChroot(t *testing.T) {
}
d.CleanUp()
-
- // Check that chroot directory was cleaned up.
- if _, err := os.Stat(chroot); err == nil || !os.IsNotExist(err) {
- t.Errorf("chroot directory %q was not deleted: %v", chroot, err)
- }
}
func TestChrootGofer(t *testing.T) {