From 211f5b5d6e3d32ec876de4dfe14c83b2bcada7f1 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 4 May 2017 14:46:20 -0400 Subject: [PATCH] add test for newestVersion --- plugin/discovery/get_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugin/discovery/get_test.go b/plugin/discovery/get_test.go index 21fd931d3..23ba4af6a 100644 --- a/plugin/discovery/get_test.go +++ b/plugin/discovery/get_test.go @@ -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 = `