This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Julio Montes
committed
Feb 12, 2020
1 parent
dd2762f
commit 71f48a3
Showing
2 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,57 @@ | ||
// 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 TestGetDriver(t *testing.T) { | ||
nonexist, err := GetDriver("non-exist") | ||
func TestGetDriverByName(t *testing.T) { | ||
nonexist, err := GetDriverByName("non-exist") | ||
assert.NotNil(t, err) | ||
assert.Nil(t, nonexist) | ||
|
||
fsDriver, err := GetDriver("fs") | ||
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) | ||
} |