Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
unit-test: delete what ioutil.TempDir() creates
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Pennyzct committed Jan 17, 2020
1 parent aa62781 commit 0244d95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions virtcontainers/kata_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()}
Expand Down
13 changes: 10 additions & 3 deletions virtcontainers/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package virtcontainers
import (
"context"
"io/ioutil"
"os"
"testing"

"github.com/kata-containers/runtime/virtcontainers/utils"
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0244d95

Please sign in to comment.