mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-20 08:18:24 +00:00
Merge pull request #1526 from bergwolf/ut-non-root
fix ut failure due to incorrect cleanup and make it runnable with non-root
This commit is contained in:
@@ -137,6 +137,10 @@ func TestContainerRemoveDrive(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testSetupFakeRootfs(t *testing.T) (testRawFile, loopDev, mntDir string, err error) {
|
func testSetupFakeRootfs(t *testing.T) (testRawFile, loopDev, mntDir string, err error) {
|
||||||
|
if os.Geteuid() != 0 {
|
||||||
|
t.Skip(testDisabledAsNonRoot)
|
||||||
|
}
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "")
|
tmpDir, err := ioutil.TempDir("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@@ -282,6 +282,12 @@ func TestHyperCopyFile(t *testing.T) {
|
|||||||
func TestHyperCleanupSandbox(t *testing.T) {
|
func TestHyperCleanupSandbox(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
defaultSharedDirSaved := defaultSharedDir
|
||||||
|
defaultSharedDir, _ = ioutil.TempDir("", "hyper-cleanup")
|
||||||
|
defer func() {
|
||||||
|
defaultSharedDir = defaultSharedDirSaved
|
||||||
|
}()
|
||||||
|
|
||||||
s := Sandbox{
|
s := Sandbox{
|
||||||
id: "testFoo",
|
id: "testFoo",
|
||||||
}
|
}
|
||||||
|
@@ -920,6 +920,12 @@ func TestKataCopyFile(t *testing.T) {
|
|||||||
func TestKataCleanupSandbox(t *testing.T) {
|
func TestKataCleanupSandbox(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
kataHostSharedDirSaved := kataHostSharedDir
|
||||||
|
kataHostSharedDir, _ = ioutil.TempDir("", "kata-cleanup")
|
||||||
|
defer func() {
|
||||||
|
kataHostSharedDir = kataHostSharedDirSaved
|
||||||
|
}()
|
||||||
|
|
||||||
s := Sandbox{
|
s := Sandbox{
|
||||||
id: "testFoo",
|
id: "testFoo",
|
||||||
}
|
}
|
||||||
|
@@ -53,12 +53,18 @@ func cleanUp() {
|
|||||||
os.MkdirAll(dir, store.DirMode)
|
os.MkdirAll(dir, store.DirMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setup() {
|
||||||
os.Mkdir(filepath.Join(testDir, testBundle), store.DirMode)
|
os.Mkdir(filepath.Join(testDir, testBundle), store.DirMode)
|
||||||
|
|
||||||
_, err := os.Create(filepath.Join(testDir, testImage))
|
for _, filename := range []string{testQemuKernelPath, testQemuInitrdPath, testQemuImagePath, testQemuPath} {
|
||||||
if err != nil {
|
_, err := os.Create(filename)
|
||||||
fmt.Println("Could not recreate test image:", err)
|
if err != nil {
|
||||||
os.Exit(1)
|
fmt.Printf("Could not recreate %s:%v", filename, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,36 +101,7 @@ func TestMain(m *testing.M) {
|
|||||||
testQemuImagePath = filepath.Join(testDir, testImage)
|
testQemuImagePath = filepath.Join(testDir, testImage)
|
||||||
testQemuPath = filepath.Join(testDir, testHypervisor)
|
testQemuPath = filepath.Join(testDir, testHypervisor)
|
||||||
|
|
||||||
fmt.Printf("INFO: Creating virtcontainers test kernel %s\n", testQemuKernelPath)
|
setup()
|
||||||
_, 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// allow the tests to run without affecting the host system.
|
// allow the tests to run without affecting the host system.
|
||||||
store.ConfigStoragePath = filepath.Join(testDir, store.StoragePathSuffix, "config")
|
store.ConfigStoragePath = filepath.Join(testDir, store.StoragePathSuffix, "config")
|
||||||
|
Reference in New Issue
Block a user