2014-07-15 23:37:55 +02:00
|
|
|
package file
|
2014-07-16 20:41:56 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-07-18 04:41:24 +02:00
|
|
|
"github.com/hashicorp/terraform/config/hcl2shim"
|
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",
|
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
2014-07-16 20:41:56 +02:00
|
|
|
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",
|
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
2015-11-13 12:50:31 +01:00
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("Errors: %v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:57:04 +02:00
|
|
|
func TestResourceProvider_Validate_good_unknown_variable_value(t *testing.T) {
|
|
|
|
c := testConfig(t, map[string]interface{}{
|
2019-07-18 04:41:24 +02:00
|
|
|
"content": hcl2shim.UnknownVariableValue,
|
2017-06-15 19:57:04 +02:00
|
|
|
"destination": "/tmp/bar",
|
|
|
|
})
|
|
|
|
|
|
|
|
warn, errs := Provisioner().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_bad_not_destination(t *testing.T) {
|
2014-07-16 20:41:56 +02:00
|
|
|
c := testConfig(t, map[string]interface{}{
|
|
|
|
"source": "nope",
|
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
2014-07-16 20:41:56 +02:00
|
|
|
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",
|
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
2016-11-29 21:00:26 +01:00
|
|
|
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",
|
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
|
|
|
warn, errs := Provisioner().Validate(c)
|
2015-11-13 12:50:31 +01:00
|
|
|
if len(warn) > 0 {
|
|
|
|
t.Fatalf("Warnings: %v", warn)
|
|
|
|
}
|
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatalf("Should have errors")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 20:42:14 +02:00
|
|
|
func testConfig(t *testing.T, c map[string]interface{}) *terraform.ResourceConfig {
|
2019-07-31 06:05:09 +02:00
|
|
|
return terraform.NewResourceConfigRaw(c)
|
2014-07-16 20:41:56 +02:00
|
|
|
}
|