Files
kata-containers/virtcontainers/persist/manager_test.go
Julio Montes 71f48a3364 virtcontainers/persist: update GetDriver to support rootless fs
GetDriver returns new PersistDriver according to current needs, a mock fs
driver is returned when mockTesting is enabled, a rootless fs is returned when
rootless is detected, otherwise a fs driver is used.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-02-12 19:09:32 +00:00

58 lines
1.1 KiB
Go

// Copyright (c) 2019 Huawei Corporation
// Copyright (c) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package persist
import (
"os"
"testing"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
"github.com/stretchr/testify/assert"
)
func TestGetDriverByName(t *testing.T) {
nonexist, err := GetDriverByName("non-exist")
assert.NotNil(t, err)
assert.Nil(t, nonexist)
fsDriver, err := GetDriverByName("fs")
assert.Nil(t, err)
assert.NotNil(t, fsDriver)
}
func TestGetDriver(t *testing.T) {
assert := assert.New(t)
orgMockTesting := mockTesting
defer func() {
mockTesting = orgMockTesting
}()
mockTesting = false
fsd, err := GetDriver()
assert.NoError(err)
var expectedFS persistapi.PersistDriver
if os.Getuid() != 0 {
expectedFS, err = fs.RootlessInit()
} else {
expectedFS, err = fs.Init()
}
assert.NoError(err)
assert.Equal(expectedFS, fsd)
// Testing mock driver
mockTesting = true
fsd, err = GetDriver()
assert.NoError(err)
expectedFS, err = fs.MockFSInit()
assert.NoError(err)
assert.Equal(expectedFS, fsd)
}