diff --git a/validate/validate_test.go b/validate/validate_test.go new file mode 100644 index 000000000..d1183bb3b --- /dev/null +++ b/validate/validate_test.go @@ -0,0 +1,33 @@ +package validate + +import ( + "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 TestCheckSemVer(t *testing.T) { + cases := []struct { + val string + expected bool + }{ + {rspec.Version, true}, + //FIXME: validate currently only handles rpsec.Version + {"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) + } +}