mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
helper/resource: basic tests
This commit is contained in:
parent
cc9ef7a0d3
commit
6b42d3d9a5
@ -2,6 +2,7 @@ package resource
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
@ -87,8 +88,14 @@ func (m *Map) Refresh(
|
|||||||
// resource map and can be used to satisfy the Resources method of
|
// resource map and can be used to satisfy the Resources method of
|
||||||
// a ResourceProvider.
|
// a ResourceProvider.
|
||||||
func (m *Map) Resources() []terraform.ResourceType {
|
func (m *Map) Resources() []terraform.ResourceType {
|
||||||
rs := make([]terraform.ResourceType, 0, len(m.Mapping))
|
ks := make([]string, 0, len(m.Mapping))
|
||||||
for k, _ := range m.Mapping {
|
for k, _ := range m.Mapping {
|
||||||
|
ks = append(ks, k)
|
||||||
|
}
|
||||||
|
sort.Strings(ks)
|
||||||
|
|
||||||
|
rs := make([]terraform.ResourceType, 0, len(m.Mapping))
|
||||||
|
for _, k := range ks {
|
||||||
rs = append(rs, terraform.ResourceType{
|
rs = append(rs, terraform.ResourceType{
|
||||||
Name: k,
|
Name: k,
|
||||||
})
|
})
|
||||||
|
@ -1 +1,32 @@
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMapResources(t *testing.T) {
|
||||||
|
m := &Map{
|
||||||
|
Mapping: map[string]Resource{
|
||||||
|
"aws_elb": Resource{},
|
||||||
|
"aws_instance": Resource{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rts := m.Resources()
|
||||||
|
|
||||||
|
expected := []terraform.ResourceType{
|
||||||
|
terraform.ResourceType{
|
||||||
|
Name: "aws_elb",
|
||||||
|
},
|
||||||
|
terraform.ResourceType{
|
||||||
|
Name: "aws_instance",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(rts, expected) {
|
||||||
|
t.Fatalf("bad: %#v", rts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user