Merge pull request #6681 from Juneezee/test/t.TempDir

This commit is contained in:
Fu Wei
2022-03-16 14:54:16 +08:00
committed by GitHub
40 changed files with 136 additions and 431 deletions

View File

@@ -455,11 +455,7 @@ func TestCheckpointRestoreWithImagePath(t *testing.T) {
}
// create image path store criu image files
crDir, err := os.MkdirTemp("", "test-cr")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(crDir)
crDir := t.TempDir()
imagePath := filepath.Join(crDir, "cr")
// checkpoint task
if _, err := task.Checkpoint(ctx, WithCheckpointImagePath(imagePath)); err != nil {

View File

@@ -35,15 +35,7 @@ import (
// TestDaemonRuntimeRoot ensures plugin.linux.runtime_root is not ignored
func TestDaemonRuntimeRoot(t *testing.T) {
runtimeRoot, err := os.MkdirTemp("", "containerd-test-runtime-root")
if err != nil {
t.Fatal(err)
}
defer func() {
if err != nil {
os.RemoveAll(runtimeRoot)
}
}()
runtimeRoot := t.TempDir()
configTOML := `
version = 2
[plugins]

View File

@@ -49,22 +49,14 @@ func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, fun
buf = bytes.NewBuffer(nil)
)
tempDir, err := os.MkdirTemp("", "containerd-test-new-daemon-with-config")
if err != nil {
t.Fatal(err)
}
defer func() {
if err != nil {
os.RemoveAll(tempDir)
}
}()
tempDir := t.TempDir()
configTOMLFile := filepath.Join(tempDir, "config.toml")
if err = os.WriteFile(configTOMLFile, []byte(configTOML), 0600); err != nil {
if err := os.WriteFile(configTOMLFile, []byte(configTOML), 0600); err != nil {
t.Fatal(err)
}
if err = srvconfig.LoadConfig(configTOMLFile, &configTOMLDecoded); err != nil {
if err := srvconfig.LoadConfig(configTOMLFile, &configTOMLDecoded); err != nil {
t.Fatal(err)
}
@@ -83,7 +75,7 @@ func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, fun
if configTOMLDecoded.State == "" {
args = append(args, "--state", filepath.Join(tempDir, "state"))
}
if err = ctrd.start("containerd", address, args, buf, buf); err != nil {
if err := ctrd.start("containerd", address, args, buf, buf); err != nil {
t.Fatalf("%v: %s", err, buf.String())
}