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

Commit

Permalink
virtcontainers: Remove code duplication in the test setup
Browse files Browse the repository at this point in the history
And add some additional log output for displaying the directories and
files created when kicking the virtcontainers tests.

Signed-off-by: Samuel Ortiz <[email protected]>
  • Loading branch information
Samuel Ortiz committed Jan 8, 2019
1 parent cf22f40 commit a02fd59
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions virtcontainers/virtcontainers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

Expand Down

0 comments on commit a02fd59

Please sign in to comment.