Skip to content

Commit

Permalink
add CheckSemVer unit test
Browse files Browse the repository at this point in the history
Signed-off-by: liang chenye <liangchenye@huawei.com>
  • Loading branch information
liangchenye committed Sep 1, 2016
1 parent 82d0b38 commit 8b7ba22
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions validate/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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},
{"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)
}
}

0 comments on commit 8b7ba22

Please sign in to comment.