ut: fix UT failure due to incorrect cleanup

cleanup() actually removes all things under testdir and
causes UT failures.

=== RUN   TestCreateMockSandbox
ERRO[0000] Create new sandbox failed                     error="QEMU path (/tmp/vc-tmp-007004370/hypervisor) does not exist" sandbox=7f49d00d-1995-4156-8c79-5f5ab24ce138 sandboxid=7f49d00d-1995-4156-8c79-5f5ab24ce138 source=virtcontainers subsystem=sandbox
exit status 1

Fixes: #1525

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao 2019-04-11 23:22:16 -07:00
parent a0f49a91e4
commit 9040f6a8cd

View File

@ -53,13 +53,19 @@ func cleanUp() {
os.MkdirAll(dir, store.DirMode)
}
setup()
}
func setup() {
os.Mkdir(filepath.Join(testDir, testBundle), store.DirMode)
_, err := os.Create(filepath.Join(testDir, testImage))
for _, filename := range []string{testQemuKernelPath, testQemuInitrdPath, testQemuImagePath, testQemuPath} {
_, err := os.Create(filename)
if err != nil {
fmt.Println("Could not recreate test image:", err)
fmt.Printf("Could not recreate %s:%v", filename, err)
os.Exit(1)
}
}
}
// TestMain is the common main function used by ALL the test functions
@ -95,36 +101,7 @@ func TestMain(m *testing.M) {
testQemuImagePath = filepath.Join(testDir, testImage)
testQemuPath = filepath.Join(testDir, testHypervisor)
fmt.Printf("INFO: Creating virtcontainers test kernel %s\n", testQemuKernelPath)
_, err = os.Create(testQemuKernelPath)
if err != nil {
fmt.Println("Could not create test kernel:", err)
os.RemoveAll(testDir)
os.Exit(1)
}
fmt.Printf("INFO: Creating virtcontainers test image %s\n", testQemuImagePath)
_, err = os.Create(testQemuImagePath)
if err != nil {
fmt.Println("Could not create test image:", err)
os.RemoveAll(testDir)
os.Exit(1)
}
fmt.Printf("INFO: Creating virtcontainers test hypervisor %s\n", testQemuPath)
_, err = os.Create(testQemuPath)
if err != nil {
fmt.Println("Could not create test hypervisor:", err)
os.RemoveAll(testDir)
os.Exit(1)
}
err = os.Mkdir(filepath.Join(testDir, testBundle), store.DirMode)
if err != nil {
fmt.Println("Could not create test bundle directory:", err)
os.RemoveAll(testDir)
os.Exit(1)
}
setup()
// allow the tests to run without affecting the host system.
store.ConfigStoragePath = filepath.Join(testDir, store.StoragePathSuffix, "config")