helper/resource: basic tests
This commit is contained in:
parent
cc9ef7a0d3
commit
6b42d3d9a5
|
@ -2,6 +2,7 @@ package resource
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"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
|
||||
// a ResourceProvider.
|
||||
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 {
|
||||
ks = append(ks, k)
|
||||
}
|
||||
sort.Strings(ks)
|
||||
|
||||
rs := make([]terraform.ResourceType, 0, len(m.Mapping))
|
||||
for _, k := range ks {
|
||||
rs = append(rs, terraform.ResourceType{
|
||||
Name: k,
|
||||
})
|
||||
|
|
|
@ -1 +1,32 @@
|
|||
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