2014-07-15 23:37:55 +02:00
|
|
|
package file
|
2014-07-16 20:41:56 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
2016-11-29 21:00:26 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-07-16 20:41:56 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2016-11-29 21:00:26 +01:00
|
|
|
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("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:50:31 +01:00
|
|
|
func TestResourceProvider_Validate_good_source(t *testing.T) {
|
2014-07-16 20:41:56 +02:00
|
|
|
c := testConfig(t, map[string]interface{}{
|
|
|
|
"source": "/tmp/foo",
|
|
|
|
"destination": "/tmp/bar",
|
|
|
|
})
|
2016-12-23 01:17:34 +01:00
|
|
|
p := Provisioner()
|
2014-07-16 20:41:56 +02:00
|
|
|
warn, errs := p.Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("Errors: %v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:50:31 +01:00
|
|
|
func TestResourceProvider_Validate_good_content(t *testing.T) {
|
|
|
|
c := testConfig(t, map[string]interface{}{
|
|
|
|
"content": "value to copy",
|
|
|
|
"destination": "/tmp/bar",
|
|
|
|
})
|
2016-12-23 01:17:34 +01:00
|
|
|
p := Provisioner()
|
2015-11-13 12:50:31 +01:00
|
|
|
warn, errs := p.Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("Errors: %v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResourceProvider_Validate_bad_not_destination(t *testing.T) {
|
2014-07-16 20:41:56 +02:00
|
|
|
c := testConfig(t, map[string]interface{}{
|
|
|
|
"source": "nope",
|
|
|
|
})
|
2016-12-23 01:17:34 +01:00
|
|
|
p := Provisioner()
|
2014-07-16 20:41:56 +02:00
|
|
|
warn, errs := p.Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatalf("Should have errors")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 21:00:26 +01:00
|
|
|
func TestResourceProvider_Validate_bad_no_source(t *testing.T) {
|
|
|
|
c := testConfig(t, map[string]interface{}{
|
|
|
|
"destination": "/tmp/bar",
|
|
|
|
})
|
|
|
|
p := Provisioner()
|
|
|
|
warn, errs := p.Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatalf("Should have errors")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:50:31 +01:00
|
|
|
func TestResourceProvider_Validate_bad_to_many_src(t *testing.T) {
|
|
|
|
c := testConfig(t, map[string]interface{}{
|
|
|
|
"source": "nope",
|
|
|
|
"content": "value to copy",
|
|
|
|
"destination": "/tmp/bar",
|
|
|
|
})
|
2016-12-23 01:17:34 +01:00
|
|
|
p := Provisioner()
|
2015-11-13 12:50:31 +01:00
|
|
|
warn, errs := p.Validate(c)
|
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatalf("Should have errors")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 20:41:56 +02:00
|
|
|
func testConfig(
|
|
|
|
t *testing.T,
|
|
|
|
c map[string]interface{}) *terraform.ResourceConfig {
|
|
|
|
r, err := config.NewRawConfig(c)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
return terraform.NewResourceConfig(r)
|
|
|
|
}
|