-
Notifications
You must be signed in to change notification settings - Fork 159
add CheckSemVer, CheckRootfsPath, CheckPlatform unit test #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add
.gotesthere as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I miss this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still missing a
.PHONYentry for.gotest?