-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: liang chenye <liangchenye@huawei.com>
- Loading branch information
1 parent
66950fa
commit 687c61c
Showing
3 changed files
with
119 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |