libct/int: adapt to Go 1.15

1. Use t.TempDir instead of ioutil.TempDir. This means no need for an
   explicit cleanup, which removes some code, including newTestBundle
   and newTestRoot.

2. Move newRootfs invocation down to newTemplateConfig, removing a need
   for explicit rootfs creation. Also, remove rootfs from tParam as it
   is no longer needed (there was a since test case in which two
   containers shared the same rootfs, but it does not look like it's
   required for the test).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-07-19 17:12:53 -07:00
parent 1eeaf11301
commit 3bc606e9d3
8 changed files with 102 additions and 407 deletions
+8 -39
View File
@@ -3,7 +3,6 @@ package integration
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -98,42 +97,15 @@ func waitProcess(p *libcontainer.Process, t *testing.T) {
}
}
func newTestRoot() (string, error) {
dir, err := ioutil.TempDir("", "libcontainer")
if err != nil {
return "", err
}
if err := os.MkdirAll(dir, 0o700); err != nil {
return "", err
}
testRoots = append(testRoots, dir)
return dir, nil
}
func newTestBundle() (string, error) {
dir, err := ioutil.TempDir("", "bundle")
if err != nil {
return "", err
}
if err := os.MkdirAll(dir, 0o700); err != nil {
return "", err
}
return dir, nil
}
// newRootfs creates a new tmp directory and copies the busybox root filesystem
func newRootfs() (string, error) {
dir, err := ioutil.TempDir("", "")
if err != nil {
return "", err
}
if err := os.MkdirAll(dir, 0o700); err != nil {
return "", err
}
// newRootfs creates a new tmp directory and copies the busybox root
// filesystem to it.
func newRootfs(t *testing.T) string {
t.Helper()
dir := t.TempDir()
if err := copyBusybox(dir); err != nil {
return "", err
t.Fatal(err)
}
return dir, nil
return dir
}
func remove(dir string) {
@@ -152,10 +124,7 @@ func copyBusybox(dest string) error {
func newContainer(t *testing.T, config *configs.Config) (libcontainer.Container, error) {
name := strings.ReplaceAll(t.Name(), "/", "_") + strconv.FormatInt(-int64(time.Now().Nanosecond()), 35)
root, err := newTestRoot()
if err != nil {
return nil, err
}
root := t.TempDir()
f, err := libcontainer.New(root, libcontainer.Cgroupfs)
if err != nil {