From 07c6fd6bf2bae70ab163688c02466da958d5b899 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Mon, 12 Dec 2016 14:07:35 -0800 Subject: [PATCH] add tests for deduceConstraint Signed-off-by: Jess Frazelle --- ensure_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ensure_test.go b/ensure_test.go index 043b7e7f..ee806984 100644 --- a/ensure_test.go +++ b/ensure_test.go @@ -5,6 +5,8 @@ import ( "os" "path/filepath" "testing" + + "github.com/sdboyer/gps" ) func TestEnsureOverrides(t *testing.T) { @@ -88,6 +90,26 @@ func main() { } } +func TestDeduceConstraint(t *testing.T) { + sv, err := gps.NewSemverConstraint("v1.2.3") + if err != nil { + t.Fatal(err) + } + + constraints := map[string]gps.Constraint{ + "v1.2.3": sv, + "5b3352dc16517996fb951394bcbbe913a2a616e3": gps.Revision("5b3352dc16517996fb951394bcbbe913a2a616e3"), + "g4@golang.org-20161116211307-wiuilyamo9ian0m7": gps.NewVersion("g4@golang.org-20161116211307-wiuilyamo9ian0m7"), + } + + for str, expected := range constraints { + c := deduceConstraint(str) + if c != expected { + t.Fatalf("expected: %#v, got %#v for %s", expected, c, str) + } + } +} + func TestCopyFolder(t *testing.T) { dir, err := ioutil.TempDir("", "dep") if err != nil {