Input validation for Version strings (#148)

* code

* tests
This commit is contained in:
Chris O'Haver 2019-04-12 09:30:35 -04:00 committed by GitHub
parent 626e32c427
commit 5fe683c057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 2 deletions

View file

@ -241,7 +241,6 @@ stubzone.org:53 {
}
`}
for _, d := range defaultCorefiles {
if !Default("", d) {
t.Errorf("expected config to be identified as a default: %v", d)
@ -253,3 +252,28 @@ stubzone.org:53 {
}
}
}
func TestValidateVersions(t *testing.T) {
testCases := []struct {
from string
to string
shouldErr bool
}{
{"1.3.1", "1.5.0", false},
{"1.5.0", "1.3.1", true},
{"banana", "1.5.0", true},
{"1.3.1", "apple", true},
{"banana", "apple", true},
}
for _, tc := range testCases {
err := validateVersions(tc.from, tc.to)
if !tc.shouldErr && err != nil {
t.Errorf("expected '%v' to '%v' to be valid versions.", tc.from, tc.to)
}
if tc.shouldErr && err == nil {
t.Errorf("expected '%v' to '%v' to be invalid versions.", tc.from, tc.to)
}
}
}