add test for newestVersion

This commit is contained in:
James Bardin 2017-05-04 14:46:20 -04:00 committed by Martin Atkins
parent 46190590cb
commit 211f5b5d6e
1 changed files with 35 additions and 0 deletions

View File

@ -36,6 +36,41 @@ func TestVersionListing(t *testing.T) {
}
}
func TestNewestVersion(t *testing.T) {
var available []Version
for _, v := range []string{"1.2.3", "1.2.1", "1.2.4"} {
version, err := VersionStr(v).Parse()
if err != nil {
t.Fatal(err)
}
available = append(available, version)
}
reqd, err := ConstraintStr(">1.2.1").Parse()
if err != nil {
t.Fatal(err)
}
found, err := newestVersion(available, reqd)
if err != nil {
t.Fatal(err)
}
if found.String() != "1.2.4" {
t.Fatalf("expected newest version 1.2.4, got: %s", found)
}
reqd, err = ConstraintStr("> 1.2.4").Parse()
if err != nil {
t.Fatal(err)
}
found, err = newestVersion(available, reqd)
if err == nil {
t.Fatalf("expceted error, got version %s", found)
}
}
const versionList = `<!DOCTYPE html>
<html>
<body>