mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-18 04:32:59 -06:00
b40a4fb741
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package discovery
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestVersionSet(t *testing.T) {
|
|
tests := []struct {
|
|
ConstraintStr string
|
|
VersionStr string
|
|
ShouldHave bool
|
|
}{
|
|
// These test cases are not exhaustive since the underlying go-version
|
|
// library is well-tested. This is mainly here just to exercise our
|
|
// wrapper code, but also used as an opportunity to cover some basic
|
|
// but important cases such as the ~> constraint so that we'll be more
|
|
// likely to catch any accidental breaking behavior changes in the
|
|
// underlying library.
|
|
{
|
|
">=1.0.0",
|
|
"1.0.0",
|
|
true,
|
|
},
|
|
{
|
|
">=1.0.0",
|
|
"0.0.0",
|
|
false,
|
|
},
|
|
{
|
|
">=1.0.0",
|
|
"1.1.0-beta1",
|
|
false,
|
|
},
|
|
{
|
|
">=1.0.0",
|
|
"1.1.0",
|
|
true,
|
|
},
|
|
{
|
|
"~>1.1.0-a",
|
|
"1.1.0-beta1",
|
|
true,
|
|
},
|
|
{
|
|
"~>1.1.0",
|
|
"1.1.2",
|
|
true,
|
|
},
|
|
{
|
|
"~>1.1.0",
|
|
"1.2.0",
|
|
false,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(fmt.Sprintf("%s has %s", test.ConstraintStr, test.VersionStr), func(t *testing.T) {
|
|
accepted, err := ConstraintStr(test.ConstraintStr).Parse()
|
|
if err != nil {
|
|
t.Fatalf("unwanted error parsing constraints string %q: %s", test.ConstraintStr, err)
|
|
}
|
|
|
|
version, err := VersionStr(test.VersionStr).Parse()
|
|
if err != nil {
|
|
t.Fatalf("unwanted error parsing version string %q: %s", test.VersionStr, err)
|
|
}
|
|
|
|
if got, want := accepted.Allows(version), test.ShouldHave; got != want {
|
|
t.Errorf("Has returned %#v; want %#v", got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|