Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Add test skip utils #1587

Merged
merged 2 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions cli/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cli/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions cli/kata-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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("", "")
Expand Down
11 changes: 7 additions & 4 deletions cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions containerd-shim-v2/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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("", "")
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions containerd-shim-v2/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion netmon/netmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
}
}
Expand Down
44 changes: 44 additions & 0 deletions pkg/katatestutils/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions pkg/katatestutils/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Gopkg.toml example
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woot! , is this correct? I thought that there should only be one vendor directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem to be required, yes:

INFO: Running 'go test' as current user on package 'github.com/kata-containers/runtime/cli' with flags '-v -race -timeout 30s -outputdir "/tmp/tmp.RnuwUOlXss"'
# github.com/kata-containers/runtime/cli
package github.com/kata-containers/runtime/cli (test)
        imports github.com/kata-containers/runtime/pkg/katatestutils
        imports github.com/blang/semver: cannot find package "github.com/blang/semver" in any of:
        /home/james/go/src/github.com/kata-containers/runtime/vendor/github.com/blang/semver (vendor tree)
        /usr/local/go/src/github.com/blang/semver (from $GOROOT)
        /home/james/go/src/github.com/blang/semver (from $GOPATH)
FAIL    github.com/kata-containers/runtime/cli [setup failed]

... but:

$ dep ensure -add github.com/blang/semver
Fetching sources...

Failed to add the dependencies:

  ✗ github.com/blang/semver is already imported or required, so -add is only valid with a constraint

adding dependencies failed
$ grep -c semver Gopkg.*                
Gopkg.lock:0
Gopkg.toml:0
$

We do have other packages with their own vendoring, for example:

#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/blang/semver"
version = "3.6.1"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.3.0"

[prune]
go-tests = true
unused-packages = true
Loading