tests: Update test code to use test constraints

Updated the test code to use the new test constraints feature.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2019-04-25 17:38:52 +01:00
parent 8e144e08e6
commit 23f7cfa9f4
20 changed files with 124 additions and 89 deletions

View File

@ -15,6 +15,7 @@ import (
"regexp"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
@ -70,9 +71,9 @@ func TestCreatePIDFileEmptyPathSuccessful(t *testing.T) {
}
func TestCreatePIDFileUnableToRemove(t *testing.T) {
if os.Geteuid() == 0 {
if tc.NotValid(ktu.NeedNonRoot()) {
// The os.FileMode(0000) trick doesn't work for root.
t.Skip(testDisabledNeedNonRoot)
t.Skip(ktu.TestDisabledNeedNonRoot)
}
assert := assert.New(t)
@ -387,8 +388,8 @@ func TestCreateContainerInvalid(t *testing.T) {
}
func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
@ -489,9 +490,9 @@ func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
}
func TestCreateCreateCgroupsFilesFail(t *testing.T) {
if os.Geteuid() == 0 {
if tc.NotValid(ktu.NeedNonRoot()) {
// The os.FileMode(0000) trick doesn't work for root.
t.Skip(testDisabledNeedNonRoot)
t.Skip(ktu.TestDisabledNeedNonRoot)
}
assert := assert.New(t)
@ -575,9 +576,9 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) {
}
func TestCreateCreateCreatePidFileFail(t *testing.T) {
if os.Geteuid() == 0 {
if tc.NotValid(ktu.NeedNonRoot()) {
// The os.FileMode(0000) trick doesn't work for root.
t.Skip(testDisabledNeedNonRoot)
t.Skip(ktu.TestDisabledNeedNonRoot)
}
assert := assert.New(t)
@ -652,8 +653,8 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) {
}
func TestCreate(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)

View File

@ -13,6 +13,7 @@ import (
"path/filepath"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
@ -597,8 +598,8 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
}
func TestRemoveCGroupsPath(t *testing.T) {
if os.Geteuid() == 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedNonRoot()) {
t.Skip(ktu.TestDisabledNeedNonRoot)
}
assert := assert.New(t)

View File

@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vc "github.com/kata-containers/runtime/virtcontainers"
)
@ -65,7 +66,7 @@ func TestFactoryCLIFunctionInit(t *testing.T) {
assert.Nil(err)
// With template
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}

View File

@ -15,6 +15,7 @@ import (
"path/filepath"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/kata-containers/runtime/pkg/katautils"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
@ -553,8 +554,8 @@ func TestCheckCheckKernelModules(t *testing.T) {
func TestCheckCheckKernelModulesUnreadableFile(t *testing.T) {
assert := assert.New(t)
if os.Geteuid() == 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedNonRoot()) {
t.Skip(ktu.TestDisabledNeedNonRoot)
}
dir, err := ioutil.TempDir("", "")

View File

@ -22,6 +22,7 @@ import (
"testing"
"github.com/dlespiau/covertool/pkg/cover"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
@ -34,10 +35,9 @@ import (
)
const (
testDisabledNeedNonRoot = "Test disabled as requires non-root user"
testDirMode = os.FileMode(0750)
testFileMode = os.FileMode(0640)
testExeFileMode = os.FileMode(0750)
testDirMode = os.FileMode(0750)
testFileMode = os.FileMode(0640)
testExeFileMode = os.FileMode(0750)
// small docker image used to create root filesystems from
testDockerImage = "busybox"
@ -51,6 +51,7 @@ var (
// package variables set by calling TestMain()
testDir = ""
testBundleDir = ""
tc ktu.TestConstraint
)
// testingImpl is a concrete mock RVC implementation used for testing
@ -122,6 +123,8 @@ func init() {
if err != nil {
panic(fmt.Sprintf("ERROR: failed to create OCI bundle: %v", err))
}
tc = ktu.NewTestConstraint(false)
}
// resetCLIGlobals undoes the effects of setCLIGlobals(), restoring the original values

View File

@ -16,6 +16,7 @@ import (
"regexp"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vc "github.com/kata-containers/runtime/virtcontainers"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
@ -223,8 +224,8 @@ func testRunContainerSetup(t *testing.T) runContainerData {
}
func TestRunContainerSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
@ -332,8 +333,8 @@ func TestRunContainerSuccessful(t *testing.T) {
}
func TestRunContainerDetachSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)

View File

@ -19,14 +19,15 @@ import (
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/kata-containers/runtime/pkg/katautils"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
)
func TestCreateSandboxSuccess(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
@ -97,9 +98,10 @@ func TestCreateSandboxSuccess(t *testing.T) {
}
func TestCreateSandboxFail(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
tmpdir, err := ioutil.TempDir("", "")
@ -142,8 +144,8 @@ func TestCreateSandboxFail(t *testing.T) {
}
func TestCreateSandboxConfigFail(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)

View File

@ -17,6 +17,7 @@ import (
"path/filepath"
"strings"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
@ -41,8 +42,6 @@ const (
testBundle = "bundle"
testConsole = "/dev/pts/888"
testDisabledNeedRoot = "Test disabled as requires root user"
testContainerTypeAnnotation = "io.kubernetes.cri.container-type"
testSandboxIDAnnotation = "io.kubernetes.cri.sandbox-id"
testContainerTypeSandbox = "sandbox"
@ -53,6 +52,7 @@ var (
// package variables set by calling TestMain()
testDir = ""
testBundleDir = ""
tc ktu.TestConstraint
)
// testingImpl is a concrete mock RVC implementation used for testing
@ -108,6 +108,8 @@ func init() {
if err != nil {
panic(fmt.Sprintf("ERROR: failed to create OCI bundle: %v", err))
}
tc = ktu.NewTestConstraint(false)
}
// createOCIConfig creates an OCI configuration (spec) file in

View File

@ -16,6 +16,7 @@ import (
"runtime"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
@ -42,7 +43,9 @@ const (
)
func skipUnlessRoot(t *testing.T) {
if os.Getuid() != 0 {
tc := ktu.NewTestConstraint(false)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip("Test disabled as requires root user")
}
}

View File

@ -19,7 +19,7 @@ import (
"syscall"
"testing"
"github.com/kata-containers/runtime/pkg/katatestutils"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/utils"
@ -84,7 +84,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
hotplugVFIOOnRootBus := true
disableNewNetNs := false
configFileOptions := katatestutils.RuntimeConfigOptions{
configFileOptions := ktu.RuntimeConfigOptions{
Hypervisor: "qemu",
HypervisorPath: hypervisorPath,
KernelPath: kernelPath,
@ -115,7 +115,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
AgentTrace: agentTrace,
}
runtimeConfigFileData := katatestutils.MakeRuntimeConfigFileData(configFileOptions)
runtimeConfigFileData := ktu.MakeRuntimeConfigFileData(configFileOptions)
configPath := path.Join(dir, "runtime.toml")
err = createConfig(configPath, runtimeConfigFileData)
@ -422,8 +422,8 @@ func TestConfigLoadConfigurationFailMissingShim(t *testing.T) {
}
func TestConfigLoadConfigurationFailUnreadableConfig(t *testing.T) {
if os.Geteuid() == 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedNonRoot()) {
t.Skip(ktu.TestDisabledNeedNonRoot)
}
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
@ -445,8 +445,8 @@ func TestConfigLoadConfigurationFailUnreadableConfig(t *testing.T) {
}
func TestConfigLoadConfigurationFailTOMLConfigFileInvalidContents(t *testing.T) {
if os.Geteuid() == 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedNonRoot()) {
t.Skip(ktu.TestDisabledNeedNonRoot)
}
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
@ -471,8 +471,8 @@ func TestConfigLoadConfigurationFailTOMLConfigFileInvalidContents(t *testing.T)
}
func TestConfigLoadConfigurationFailTOMLConfigFileDuplicatedData(t *testing.T) {
if os.Geteuid() == 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedNonRoot()) {
t.Skip(ktu.TestDisabledNeedNonRoot)
}
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")

View File

@ -19,6 +19,7 @@ import (
"syscall"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
@ -38,8 +39,14 @@ var (
// testingImpl is a concrete mock RVC implementation used for testing
testingImpl = &vcmock.VCMock{}
tc ktu.TestConstraint
)
func init() {
tc = ktu.NewTestConstraint(false)
}
// readOCIConfig returns an OCI spec.
func readOCIConfigFile(configPath string) (oci.CompatOCISpec, error) {
if configPath == "" {
@ -178,8 +185,8 @@ func findLastParam(key string, params []vc.Param) (string, error) {
}
func TestSetEphemeralStorageType(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
@ -313,8 +320,8 @@ func TestCreateSandboxConfigFail(t *testing.T) {
}
func TestCreateSandboxFail(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)

View File

@ -11,6 +11,7 @@ import (
"os"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
. "github.com/kata-containers/runtime/virtcontainers/pkg/mock"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/opencontainers/runtime-spec/specs-go"
@ -55,8 +56,8 @@ func createWrongHook() specs.Hook {
}
func TestRunHook(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
@ -86,8 +87,8 @@ func TestRunHook(t *testing.T) {
}
func TestPreStartHooks(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
@ -134,8 +135,8 @@ func TestPreStartHooks(t *testing.T) {
}
func TestPostStartHooks(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)
@ -182,8 +183,8 @@ func TestPostStartHooks(t *testing.T) {
}
func TestPostStopHooks(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)

View File

@ -14,6 +14,7 @@ import (
"testing"
"github.com/containernetworking/plugins/pkg/ns"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/stretchr/testify/assert"
"golang.org/x/sys/unix"
@ -64,8 +65,8 @@ func TestGetNetNsFromBindMount(t *testing.T) {
func TestHostNetworkingRequested(t *testing.T) {
assert := assert.New(t)
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
// Network namespace same as the host
@ -101,8 +102,8 @@ func TestHostNetworkingRequested(t *testing.T) {
}
func TestSetupNetworkNamespace(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
assert := assert.New(t)

View File

@ -26,9 +26,6 @@ const (
testDirMode = os.FileMode(0750)
testFileMode = os.FileMode(0640)
testDisabledNeedRoot = "Test disabled as requires root user"
testDisabledNeedNonRoot = "Test disabled as requires non-root user"
// small docker image used to create root filesystems from
testDockerImage = "busybox"
@ -38,7 +35,9 @@ const (
specConfig = "config.json"
)
var testDir = ""
var (
testDir = ""
)
func init() {
var err error

View File

@ -15,6 +15,7 @@ import (
"syscall"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
@ -132,7 +133,7 @@ func TestCreateSandboxNoopAgentSuccessful(t *testing.T) {
}
func TestCreateSandboxKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -212,7 +213,7 @@ func TestDeleteSandboxNoopAgentSuccessful(t *testing.T) {
}
func TestDeleteSandboxKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -287,7 +288,7 @@ func TestStartSandboxNoopAgentSuccessful(t *testing.T) {
}
func TestStartSandboxKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -421,7 +422,7 @@ func TestPauseThenResumeSandboxNoopAgentSuccessful(t *testing.T) {
}
func TestStopSandboxKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -491,7 +492,7 @@ func TestRunSandboxNoopAgentSuccessful(t *testing.T) {
}
func TestRunSandboxKataAgentSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -1705,7 +1706,7 @@ func TestReleaseSandbox(t *testing.T) {
}
func TestUpdateContainer(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -1758,7 +1759,7 @@ func TestUpdateContainer(t *testing.T) {
}
func TestPauseResumeContainer(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -1800,7 +1801,7 @@ func TestPauseResumeContainer(t *testing.T) {
}
func TestNetworkOperation(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}

View File

@ -16,6 +16,7 @@ import (
"syscall"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
@ -138,7 +139,7 @@ func TestContainerRemoveDrive(t *testing.T) {
}
func testSetupFakeRootfs(t *testing.T) (testRawFile, loopDev, mntDir string, err error) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -206,7 +207,7 @@ func cleanupFakeRootfsSetup(testRawFile, loopDev, mntDir string) {
}
func TestContainerAddDriveDir(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}

View File

@ -9,7 +9,6 @@ import (
"bytes"
"context"
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"os/exec"
@ -18,13 +17,21 @@ import (
"strings"
"syscall"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/stretchr/testify/assert"
)
const (
testDisabledNeedRoot = "Test disabled as requires root user"
testDirMode = os.FileMode(0750)
testDirMode = os.FileMode(0750)
)
var tc ktu.TestConstraint
func init() {
tc = ktu.NewTestConstraint(false)
}
func TestIsSystemMount(t *testing.T) {
tests := []struct {
mnt string
@ -70,8 +77,8 @@ func TestIsHostDevice(t *testing.T) {
}
func TestIsHostDeviceCreateFile(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
// Create regular file in /dev
@ -196,8 +203,8 @@ func TestGetDeviceForPath(t *testing.T) {
}
func TestGetDeviceForPathBindMount(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
source := filepath.Join(testDir, "testDeviceDirSrc")
@ -301,8 +308,8 @@ func TestIsDockerVolume(t *testing.T) {
}
func TestIsEphemeralStorage(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledNeedRoot)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(ktu.TestDisabledNeedRoot)
}
dir, err := ioutil.TempDir(testDir, "foo")

View File

@ -11,13 +11,14 @@ import (
"reflect"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
)
func TestCreateDeleteNetNS(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -175,7 +176,7 @@ func TestGenerateRandomPrivateMacAdd(t *testing.T) {
}
func TestCreateGetBridgeLink(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -199,7 +200,7 @@ func TestCreateGetBridgeLink(t *testing.T) {
}
func TestCreateGetTunTapLink(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -224,7 +225,7 @@ func TestCreateGetTunTapLink(t *testing.T) {
}
func TestCreateMacVtap(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -268,7 +269,7 @@ func TestCreateMacVtap(t *testing.T) {
}
func TestTcRedirectNetwork(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}

View File

@ -7,10 +7,10 @@ package virtcontainers
import (
"net"
"os"
"testing"
"github.com/containernetworking/plugins/pkg/ns"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
"github.com/vishvananda/netns"
@ -43,7 +43,7 @@ func TestPhysicalEndpoint_HotDetach(t *testing.T) {
}
func TestIsPhysicalIface(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}

View File

@ -12,6 +12,8 @@ import (
"path/filepath"
"syscall"
"testing"
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
)
func TestBindMountInvalidSourceSymlink(t *testing.T) {
@ -47,7 +49,7 @@ func TestBindMountFailingMount(t *testing.T) {
}
func TestBindMountSuccessful(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
@ -76,7 +78,7 @@ func TestBindMountSuccessful(t *testing.T) {
}
func TestBindMountReadonlySuccessful(t *testing.T) {
if os.Geteuid() != 0 {
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}