helper/resource: basic tests

This commit is contained in:
Mitchell Hashimoto 2014-07-02 17:36:07 -07:00
parent cc9ef7a0d3
commit 6b42d3d9a5
2 changed files with 39 additions and 1 deletions

View File

@ -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,
})

View File

@ -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)
}
}