summaryrefslogtreecommitdiffhomepage
path: root/runsc/specutils/specutils_test.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-06-28 09:56:23 -0700
committerShentubot <shentubot@google.com>2018-06-28 09:57:27 -0700
commit8459390cdd81ef1c8180948566e893b06233923c (patch)
tree62966e8519bf3176a0fd1d4e0a4594e640e193e2 /runsc/specutils/specutils_test.go
parent1f207de315430fb178b7025a5afd419afdc31449 (diff)
Error out if spec is invalid
Closes #66 PiperOrigin-RevId: 202496258 Change-Id: Ib9287c5bf1279ffba1db21ebd9e6b59305cddf34
Diffstat (limited to 'runsc/specutils/specutils_test.go')
-rw-r--r--runsc/specutils/specutils_test.go113
1 files changed, 113 insertions, 0 deletions
diff --git a/runsc/specutils/specutils_test.go b/runsc/specutils/specutils_test.go
index ef293e608..959be3af3 100644
--- a/runsc/specutils/specutils_test.go
+++ b/runsc/specutils/specutils_test.go
@@ -20,6 +20,8 @@ import (
"strings"
"testing"
"time"
+
+ specs "github.com/opencontainers/runtime-spec/specs-go"
)
func TestWaitForReadyHappy(t *testing.T) {
@@ -94,3 +96,114 @@ func TestWaitForReadyTimeout(t *testing.T) {
}
cmd.Process.Kill()
}
+
+func TestSpecInvalid(t *testing.T) {
+ for _, test := range []struct {
+ name string
+ spec specs.Spec
+ error string
+ }{
+ {
+ name: "valid",
+ spec: specs.Spec{
+ Root: &specs.Root{Path: "/"},
+ Process: &specs.Process{
+ Args: []string{"/bin/true"},
+ },
+ },
+ error: "",
+ },
+ {
+ name: "valid+warning",
+ spec: specs.Spec{
+ Root: &specs.Root{Path: "/"},
+ Process: &specs.Process{
+ Args: []string{"/bin/true"},
+ // This is normally set by docker and will just cause warnings to be logged.
+ ApparmorProfile: "someprofile",
+ },
+ // This is normally set by docker and will just cause warnings to be logged.
+ Linux: &specs.Linux{Seccomp: &specs.LinuxSeccomp{}},
+ },
+ error: "",
+ },
+ {
+ name: "no root",
+ spec: specs.Spec{
+ Process: &specs.Process{
+ Args: []string{"/bin/true"},
+ },
+ },
+ error: "must be defined",
+ },
+ {
+ name: "empty root",
+ spec: specs.Spec{
+ Root: &specs.Root{},
+ Process: &specs.Process{
+ Args: []string{"/bin/true"},
+ },
+ },
+ error: "must be defined",
+ },
+ {
+ name: "no process",
+ spec: specs.Spec{
+ Root: &specs.Root{Path: "/"},
+ },
+ error: "must be defined",
+ },
+ {
+ name: "empty args",
+ spec: specs.Spec{
+ Root: &specs.Root{Path: "/"},
+ Process: &specs.Process{},
+ },
+ error: "must be defined",
+ },
+ {
+ name: "selinux",
+ spec: specs.Spec{
+ Root: &specs.Root{Path: "/"},
+ Process: &specs.Process{
+ Args: []string{"/bin/true"},
+ SelinuxLabel: "somelabel",
+ },
+ },
+ error: "is not supported",
+ },
+ {
+ name: "solaris",
+ spec: specs.Spec{
+ Root: &specs.Root{Path: "/"},
+ Process: &specs.Process{
+ Args: []string{"/bin/true"},
+ },
+ Solaris: &specs.Solaris{},
+ },
+ error: "is not supported",
+ },
+ {
+ name: "windows",
+ spec: specs.Spec{
+ Root: &specs.Root{Path: "/"},
+ Process: &specs.Process{
+ Args: []string{"/bin/true"},
+ },
+ Windows: &specs.Windows{},
+ },
+ error: "is not supported",
+ },
+ } {
+ err := ValidateSpec(&test.spec)
+ if len(test.error) == 0 {
+ if err != nil {
+ t.Errorf("ValidateSpec(%q) failed, err: %v", test.name, err)
+ }
+ } else {
+ if err == nil || !strings.Contains(err.Error(), test.error) {
+ t.Errorf("ValidateSpec(%q) wrong error, got: %v, want: .*%s.*", test.name, err, test.error)
+ }
+ }
+ }
+}