2017-10-06 18:20:52 +02:00
|
|
|
package habitat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResourceProvisioner_impl(t *testing.T) {
|
|
|
|
var _ terraform.ResourceProvisioner = Provisioner()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvisioner(t *testing.T) {
|
|
|
|
if err := Provisioner().(*schema.Provisioner).InternalValidate(); err != nil {
|
|
|
|
t.Fatalf("error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResourceProvisioner_Validate_good(t *testing.T) {
|
|
|
|
c := testConfig(t, map[string]interface{}{
|
2019-08-05 18:43:55 +02:00
|
|
|
"peer": "1.2.3.4",
|
|
|
|
"version": "0.32.0",
|
|
|
|
"service_type": "systemd",
|
2017-10-06 18:20:52 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("Errors: %v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResourceProvisioner_Validate_bad(t *testing.T) {
|
|
|
|
c := testConfig(t, map[string]interface{}{
|
|
|
|
"service_type": "invalidtype",
|
|
|
|
})
|
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
2019-08-05 18:43:55 +02:00
|
|
|
if len(errs) != 1 {
|
|
|
|
t.Fatalf("Should have one error")
|
2017-10-06 18:20:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResourceProvisioner_Validate_bad_service_config(t *testing.T) {
|
|
|
|
c := testConfig(t, map[string]interface{}{
|
2019-07-31 06:05:09 +02:00
|
|
|
"service": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": "core/foo",
|
|
|
|
"strategy": "bar",
|
|
|
|
"topology": "baz",
|
|
|
|
"url": "badurl",
|
|
|
|
},
|
2017-10-06 18:20:52 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) != 3 {
|
|
|
|
t.Fatalf("Should have three errors")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testConfig(t *testing.T, c map[string]interface{}) *terraform.ResourceConfig {
|
2019-07-31 06:05:09 +02:00
|
|
|
return terraform.NewResourceConfigRaw(c)
|
2017-10-06 18:20:52 +02:00
|
|
|
}
|