mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
unit-test: delete what ioutil.TempDir() creates
Normally, ioutil.TempDir will create a new temporary dir under /tmp. And we should do cleaning up after ioutil.TempDir(). Fixes: #2398 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
This commit is contained in:
parent
aa62781aa7
commit
0244d95edd
@ -636,6 +636,7 @@ func TestAgentConfigure(t *testing.T) {
|
||||
|
||||
dir, err := ioutil.TempDir("", "kata-agent-test")
|
||||
assert.Nil(err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
k := &kataAgent{}
|
||||
h := &mockHypervisor{}
|
||||
@ -758,6 +759,7 @@ func TestAgentCreateContainer(t *testing.T) {
|
||||
|
||||
dir, err := ioutil.TempDir("", "kata-agent-test")
|
||||
assert.Nil(err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
err = k.configure(&mockHypervisor{}, sandbox.id, dir, true, KataAgentConfig{})
|
||||
assert.Nil(err)
|
||||
@ -904,8 +906,10 @@ func TestKataCleanupSandbox(t *testing.T) {
|
||||
s := Sandbox{
|
||||
id: "testFoo",
|
||||
}
|
||||
dir := path.Join(kataHostSharedDir(), s.id)
|
||||
err := os.MkdirAll(dir, 0777)
|
||||
|
||||
dir := kataHostSharedDir()
|
||||
defer os.RemoveAll(dir)
|
||||
err := os.MkdirAll(path.Join(dir, s.id), 0777)
|
||||
assert.Nil(err)
|
||||
|
||||
k := &kataAgent{ctx: context.Background()}
|
||||
|
@ -8,6 +8,7 @@ package virtcontainers
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||
@ -17,7 +18,10 @@ import (
|
||||
func TestNewVM(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
||||
testDir, err := ioutil.TempDir("", "vmfactory-tmp-")
|
||||
assert.Nil(err)
|
||||
defer os.RemoveAll(testDir)
|
||||
|
||||
config := VMConfig{
|
||||
HypervisorType: MockHypervisor,
|
||||
AgentType: NoopAgentType,
|
||||
@ -31,7 +35,7 @@ func TestNewVM(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
var vm *VM
|
||||
_, err := NewVM(ctx, config)
|
||||
_, err = NewVM(ctx, config)
|
||||
assert.Error(err)
|
||||
|
||||
config.HypervisorConfig = hyperConfig
|
||||
@ -82,7 +86,10 @@ func TestVMConfigValid(t *testing.T) {
|
||||
err := config.Valid()
|
||||
assert.Error(err)
|
||||
|
||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
||||
testDir, err := ioutil.TempDir("", "vmfactory-tmp-")
|
||||
assert.Nil(err)
|
||||
defer os.RemoveAll(testDir)
|
||||
|
||||
config.HypervisorConfig = HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
InitrdPath: testDir,
|
||||
|
Loading…
Reference in New Issue
Block a user