diff --git a/mod/repo_test.go b/mod/repo_test.go index 1f107506..efd6c747 100644 --- a/mod/repo_test.go +++ b/mod/repo_test.go @@ -83,3 +83,36 @@ func TestListTags(t *testing.T) { t.Errorf("could not list repo tags") } } + +func TestVersionConstraint(t *testing.T) { + tmpDir, err := ioutil.TempDir("", "clone") + if err != nil { + t.Fatal("error creating tmp dir") + } + defer os.Remove(tmpDir) + + r, err := clone(&Require{ + cloneRepo: "github.com/dagger/universe", + clonePath: "stdlib", + version: "", + }, tmpDir, "", "") + if err != nil { + t.Fatal(err) + } + + tagVersion, err := r.latestTag("<= 0.1.0") + if err != nil { + t.Error(err) + } + + // Make sure we select the right version based on constraint + if tagVersion != "v0.1.0" { + t.Errorf("wrong version: expected 0.1.0, got %v", tagVersion) + } + + // Make sure an invalid constraint (version out of range) returns an error + _, err = r.latestTag("> 99999") + if err == nil { + t.Error("selected wrong version based on constraint") + } +}