Skip to content
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ script:
- $HOME/gopath/bin/git-validation -run DCO,short-subject -v -range ${TRAVIS_COMMIT_RANGE}
- make
- make test

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PREFIX ?= $(DESTDIR)/usr

BINDIR ?= $(DESTDIR)/usr/bin

BUILDTAGS=
Expand Down Expand Up @@ -42,7 +42,7 @@ localvalidation:

.PHONY: test .gofmt .govet .golint
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add .gotest here as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I miss this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still missing a .PHONY entry for .gotest?


test: .gofmt .govet .golint
test: .gofmt .govet .golint .gotest

.gofmt:
OUT=$$(go fmt ./...); if test -n "$${OUT}"; then echo "$${OUT}" && exit 1; fi
Expand All @@ -53,3 +53,6 @@ test: .gofmt .govet .golint
.golint:
golint -set_exit_status ./...

UTDIRS = ./validate/...
.gotest:
go test $(UTDIRS)
70 changes: 70 additions & 0 deletions validate/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package validate

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

rspec "github.com/opencontainers/runtime-spec/specs-go"
)

func checkErrors(t *testing.T, title string, msgs []string, valid bool) {
if valid && len(msgs) > 0 {
t.Fatalf("%s: expected not to get error, but get %d errors:\n%s", title, len(msgs), strings.Join(msgs, "\n"))
} else if !valid && len(msgs) == 0 {
t.Fatalf("%s: expected to get error, but actually not", title)
}
}

func TestCheckRootfsPath(t *testing.T) {
tmpBundle, err := ioutil.TempDir("", "oci-check-rootfspath")
if err != nil {
t.Fatalf("Failed to create a TempDir in 'CheckRootfsPath'")
}
defer os.RemoveAll(tmpBundle)

rootfsDir := "rootfs"
rootfsNonDir := "rootfsfile"
rootfsNonExists := "rootfsnil"
if err := os.MkdirAll(filepath.Join(tmpBundle, rootfsDir), 0700); err != nil {
t.Fatalf("Failed to create a rootfs directory in 'CheckRootfsPath'")
}
if _, err := os.Create(filepath.Join(tmpBundle, rootfsNonDir)); err != nil {
t.Fatalf("Failed to create a non-directory rootfs in 'CheckRootfsPath'")
}

cases := []struct {
val string
expected bool
}{
{rootfsDir, true},
{rootfsNonDir, false},
{rootfsNonExists, false},
{filepath.Join(tmpBundle, rootfsDir), true},
{filepath.Join(tmpBundle, rootfsNonDir), false},
{filepath.Join(tmpBundle, rootfsNonExists), false},
}
for _, c := range cases {
v := NewValidator(&rspec.Spec{Root: rspec.Root{Path: c.val}}, tmpBundle, false)
checkErrors(t, "CheckRootfsPath "+c.val, v.CheckRootfsPath(), c.expected)
}
}

func TestCheckSemVer(t *testing.T) {
cases := []struct {
val string
expected bool
}{
{rspec.Version, true},
//FIXME: validate currently only handles rpsec.Version
Copy link
Contributor

Choose a reason for hiding this comment

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

CheckSemVer already has separate checks for “valid SemVer” and “recognized SemVer”. What we're missing is support for past versions of the spec, and that problem is more general than this single test.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have the 'official supported version', so I prefer to keep this and update this once the problem of supporting past version is fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to keep this and update this once the problem of supporting past version is fixed.

That's fine, although it seems like a repo-wide issue that would be better served by a GitHub issue ;).

{"0.0.1", false},
{"invalid", false},
}

for _, c := range cases {
v := NewValidator(&rspec.Spec{Version: c.val}, "", false)
checkErrors(t, "CheckSemVer "+c.val, v.CheckSemVer(), c.expected)
}
}