mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-25 17:24:38 +01:00
virtcontainers/persist/fs/mockfs.go defines a mock filesystem type for testing. A global variable in virtcontainers/persist/manager.go is used to force use of the mock fs rather than a normal one. This patch moves the global, and the EnableMockTesting() function which sets it into mockfs.go. This is slightly cleaner to begin with, and will allow some further enhancements. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
44 lines
928 B
Go
44 lines
928 B
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/kata-containers/src/runtime/virtcontainers/persist/api"
|
|
"github.com/kata-containers/kata-containers/src/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)
|
|
|
|
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)
|
|
}
|