opentofu/internal/collections/set_test.go
Janos fa638907f1
Fixes #1169: AES-GCM implementation (#1291)
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com>
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: James Humphries <James@james-humphries.co.uk>
Co-authored-by: James Humphries <jamesh@spacelift.io>
Co-authored-by: Serdar Dalgıç <serdardalgic@users.noreply.github.com>
Co-authored-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-07 10:24:37 +00:00

96 lines
1.9 KiB
Go

package collections_test
import (
"testing"
"github.com/opentofu/opentofu/internal/collections"
)
type hasTestCase struct {
name string
set collections.Set[string]
testValueResults map[string]bool
}
func TestSet_NewSet(t *testing.T) {
testCases := []struct {
name string
constructed collections.Set[int]
expected collections.Set[int]
}{
{
name: "empty",
constructed: collections.NewSet[int](),
expected: collections.Set[int]{},
}, {
name: "items",
constructed: collections.NewSet[int](1, 54, 284),
expected: collections.Set[int]{1: {}, 54: {}, 284: {}},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if len(tc.constructed) != len(tc.expected) {
t.Fatal("Set length mismatch")
}
for k := range tc.expected {
if _, ok := tc.constructed[k]; !ok {
t.Fatalf("Expected to find key %v in constructed set", k)
}
}
})
}
}
func TestSet_has(t *testing.T) {
testCases := []hasTestCase{
{
name: "string",
set: collections.Set[string]{
"a": {},
"b": {},
"c": {},
},
testValueResults: map[string]bool{
"a": true,
"b": true,
"c": true,
"d": false,
"e": false,
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
for value, has := range testCase.testValueResults {
t.Run(value, func(t *testing.T) {
if has {
if !testCase.set.Has(value) {
t.Fatalf("Set does not have expected value of %s", value)
}
} else {
if testCase.set.Has(value) {
t.Fatalf("Set has unexpected value of %s", value)
}
}
})
}
})
}
}
func TestSet_string(t *testing.T) {
testSet := collections.Set[string]{
"a": {},
"b": {},
"c": {},
}
if str := testSet.String(); str != "a, b, c" {
t.Fatalf("Incorrect string concatenation: %s", str)
}
}