Files
kata-containers/src/runtime/virtcontainers/persist/manager_test.go
David Gibson 5d8438e939 runtime: Move mockfs control global into mockfs.go
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>
2022-04-22 14:23:36 +10:00

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)
}