From bfd497fdf94cd3b3c330216f02ab7c09b03cd9e4 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 19 Mar 2018 19:59:12 +0000 Subject: [PATCH] virtcontainers/tests: Disable selected tests for uid != 0 Skip a number of virtcontainers tests if not running as `root.` Fixes #70. Signed-off-by: James O. D. Hunt --- virtcontainers/api_test.go | 28 ++++++++++++++++++++++++++++ virtcontainers/container_test.go | 4 ++++ virtcontainers/network_test.go | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/virtcontainers/api_test.go b/virtcontainers/api_test.go index 714586d4f..3601b69ce 100644 --- a/virtcontainers/api_test.go +++ b/virtcontainers/api_test.go @@ -279,6 +279,10 @@ func testGenerateCCProxySockDir() (string, error) { } func TestCreatePodHyperstartAgentSuccessful(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + cleanUp() config := newTestPodConfigHyperstartAgent() @@ -308,6 +312,10 @@ func TestCreatePodHyperstartAgentSuccessful(t *testing.T) { } func TestCreatePodKataAgentSuccessful(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + cleanUp() config := newTestPodConfigKataAgent() @@ -383,6 +391,10 @@ func TestDeletePodNoopAgentSuccessful(t *testing.T) { } func TestDeletePodHyperstartAgentSuccessful(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + cleanUp() config := newTestPodConfigHyperstartAgent() @@ -422,6 +434,10 @@ func TestDeletePodHyperstartAgentSuccessful(t *testing.T) { } func TestDeletePodKataAgentSuccessful(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + cleanUp() config := newTestPodConfigKataAgent() @@ -527,6 +543,10 @@ func TestStartPodHyperstartAgentSuccessful(t *testing.T) { } func TestStartPodKataAgentSuccessful(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + cleanUp() config := newTestPodConfigKataAgent() @@ -685,6 +705,10 @@ func TestStopPodHyperstartAgentSuccessful(t *testing.T) { } func TestStopPodKataAgentSuccessful(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + cleanUp() config := newTestPodConfigKataAgent() @@ -791,6 +815,10 @@ func TestRunPodHyperstartAgentSuccessful(t *testing.T) { } func TestRunPodKataAgentSuccessful(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + cleanUp() config := newTestPodConfigKataAgent() diff --git a/virtcontainers/container_test.go b/virtcontainers/container_test.go index a2e7a063f..1fac1c207 100644 --- a/virtcontainers/container_test.go +++ b/virtcontainers/container_test.go @@ -193,6 +193,10 @@ func cleanupFakeRootfsSetup(testRawFile, loopDev, mntDir string) { } func TestContainerAddDriveDir(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + testRawFile, loopDev, fakeRootfs, err := testSetupFakeRootfs(t) defer cleanupFakeRootfsSetup(testRawFile, loopDev, fakeRootfs) diff --git a/virtcontainers/network_test.go b/virtcontainers/network_test.go index db63de80b..1cb04b835 100644 --- a/virtcontainers/network_test.go +++ b/virtcontainers/network_test.go @@ -309,6 +309,10 @@ func TestCreateVirtualNetworkEndpointInvalidArgs(t *testing.T) { } func TestIsPhysicalIface(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } + testNetIface := "testIface0" testMTU := 1500 testMACAddr := "00:00:00:00:00:01"