mod: added unit tests for version constraint support

Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
Sam Alba 2021-10-22 10:00:21 -07:00
parent cee8c91e50
commit d34bd86d99

View File

@ -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")
}
}