mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -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.
94 lines
1.8 KiB
Go
94 lines
1.8 KiB
Go
package discovery
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestPluginConstraintsAllows(t *testing.T) {
|
|
tests := []struct {
|
|
Constraints *PluginConstraints
|
|
Version string
|
|
Want bool
|
|
}{
|
|
{
|
|
&PluginConstraints{
|
|
Versions: AllVersions,
|
|
},
|
|
"1.0.0",
|
|
true,
|
|
},
|
|
{
|
|
&PluginConstraints{
|
|
Versions: ConstraintStr(">1.0.0").MustParse(),
|
|
},
|
|
"1.0.0",
|
|
false,
|
|
},
|
|
// This is not an exhaustive test because the callees
|
|
// already have plentiful tests of their own.
|
|
}
|
|
|
|
for i, test := range tests {
|
|
t.Run(fmt.Sprintf("%02d", i), func(t *testing.T) {
|
|
version := VersionStr(test.Version).MustParse()
|
|
got := test.Constraints.Allows(version)
|
|
if got != test.Want {
|
|
t.Logf("looking for %s in %#v", test.Version, test.Constraints)
|
|
t.Errorf("wrong result %#v; want %#v", got, test.Want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPluginConstraintsAcceptsSHA256(t *testing.T) {
|
|
mustUnhex := func(hex string) (ret []byte) {
|
|
_, err := fmt.Sscanf(hex, "%x", &ret)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return ret
|
|
}
|
|
|
|
tests := []struct {
|
|
Constraints *PluginConstraints
|
|
Digest []byte
|
|
Want bool
|
|
}{
|
|
{
|
|
&PluginConstraints{
|
|
Versions: AllVersions,
|
|
SHA256: mustUnhex("0123456789abcdef"),
|
|
},
|
|
mustUnhex("0123456789abcdef"),
|
|
true,
|
|
},
|
|
{
|
|
&PluginConstraints{
|
|
Versions: AllVersions,
|
|
SHA256: mustUnhex("0123456789abcdef"),
|
|
},
|
|
mustUnhex("f00dface"),
|
|
false,
|
|
},
|
|
{
|
|
&PluginConstraints{
|
|
Versions: AllVersions,
|
|
SHA256: nil,
|
|
},
|
|
mustUnhex("f00dface"),
|
|
true,
|
|
},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
t.Run(fmt.Sprintf("%02d", i), func(t *testing.T) {
|
|
got := test.Constraints.AcceptsSHA256(test.Digest)
|
|
if got != test.Want {
|
|
t.Logf("%#v.AcceptsSHA256(%#v)", test.Constraints, test.Digest)
|
|
t.Errorf("wrong result %#v; want %#v", got, test.Want)
|
|
}
|
|
})
|
|
}
|
|
}
|