2014-07-03 02:31:58 +02:00
|
|
|
package resource
|
2014-07-03 02:36:07 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2014-07-08 19:17:36 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/config"
|
2014-07-03 02:36:07 +02:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
}
|
2014-07-08 19:17:36 +02:00
|
|
|
|
|
|
|
func TestMapValidate(t *testing.T) {
|
|
|
|
m := &Map{
|
|
|
|
Mapping: map[string]Resource{
|
|
|
|
"aws_elb": Resource{
|
|
|
|
ConfigValidator: &config.Validator{
|
|
|
|
Required: []string{"foo"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var c *terraform.ResourceConfig
|
|
|
|
var ws []string
|
|
|
|
var es []error
|
|
|
|
|
|
|
|
// Valid
|
2018-10-02 01:17:23 +02:00
|
|
|
c = testConfigForMap(t, map[string]interface{}{"foo": "bar"})
|
2014-07-08 19:17:36 +02:00
|
|
|
ws, es = m.Validate("aws_elb", c)
|
|
|
|
if len(ws) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", ws)
|
|
|
|
}
|
|
|
|
if len(es) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", es)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid
|
2018-10-02 01:17:23 +02:00
|
|
|
c = testConfigForMap(t, map[string]interface{}{})
|
2014-07-08 19:17:36 +02:00
|
|
|
ws, es = m.Validate("aws_elb", c)
|
|
|
|
if len(ws) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", ws)
|
|
|
|
}
|
|
|
|
if len(es) == 0 {
|
|
|
|
t.Fatalf("bad: %#v", es)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 01:17:23 +02:00
|
|
|
func testConfigForMap(t *testing.T, c map[string]interface{}) *terraform.ResourceConfig {
|
2019-07-31 06:05:09 +02:00
|
|
|
return terraform.NewResourceConfigRaw(c)
|
2014-07-08 19:17:36 +02:00
|
|
|
}
|