virtcontainers: Remove code duplication in the test setup

And add some additional log output for displaying the directories and
files created when kicking the virtcontainers tests.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2018-12-18 17:02:17 +01:00
parent cf22f402d8
commit a02fd5982c

View File

@ -81,27 +81,36 @@ func TestMain(m *testing.M) {
panic(err)
}
fmt.Printf("INFO: Creating virtcontainers test directory %s\n", testDir)
err = os.MkdirAll(testDir, dirMode)
if err != nil {
fmt.Println("Could not create test directories:", err)
os.Exit(1)
}
_, err = os.Create(filepath.Join(testDir, testKernel))
testQemuKernelPath = filepath.Join(testDir, testKernel)
testQemuInitrdPath = filepath.Join(testDir, testInitrd)
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)
}
_, err = os.Create(filepath.Join(testDir, testImage))
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)
}
_, err = os.Create(filepath.Join(testDir, testHypervisor))
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)
@ -127,11 +136,6 @@ func TestMain(m *testing.M) {
sandboxFileState = filepath.Join(runStoragePath, testSandboxID, stateFile)
sandboxFileLock = filepath.Join(runStoragePath, testSandboxID, lockFileName)
testQemuKernelPath = filepath.Join(testDir, testKernel)
testQemuInitrdPath = filepath.Join(testDir, testInitrd)
testQemuImagePath = filepath.Join(testDir, testImage)
testQemuPath = filepath.Join(testDir, testHypervisor)
testHyperstartCtlSocket = filepath.Join(testDir, "test_hyper.sock")
testHyperstartTtySocket = filepath.Join(testDir, "test_tty.sock")