Skip to content

Commit 8b7ba22

Browse files
committed
add CheckSemVer unit test
Signed-off-by: liang chenye <[email protected]>
1 parent 82d0b38 commit 8b7ba22

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

validate/validate_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package validate
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
rspec "github.com/opencontainers/runtime-spec/specs-go"
8+
)
9+
10+
func checkErrors(t *testing.T, title string, msgs []string, valid bool) {
11+
if valid && len(msgs) > 0 {
12+
t.Fatalf("%s: expected not to get error, but get %d errors:\n%s", title, len(msgs), strings.Join(msgs, "\n"))
13+
} else if !valid && len(msgs) == 0 {
14+
t.Fatalf("%s: expected to get error, but actually not", title)
15+
}
16+
}
17+
18+
func TestCheckSemVer(t *testing.T) {
19+
cases := []struct {
20+
val string
21+
expected bool
22+
}{
23+
{rspec.Version, true},
24+
{"0.0.1", false},
25+
{"invalid", false},
26+
}
27+
28+
for _, c := range cases {
29+
v := NewValidator(rspec.Spec{Version: c.val}, "", false)
30+
checkErrors(t, "checkSemVer "+c.val, v.CheckSemVer(), c.expected)
31+
}
32+
}

0 commit comments

Comments
 (0)