2014-07-15 23:37:55 +02:00
|
|
|
package file
|
2014-07-16 20:41:56 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
"github.com/hashicorp/terraform/provisioners"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
2014-07-16 20:41:56 +02:00
|
|
|
)
|
|
|
|
|
2015-11-13 12:50:31 +01:00
|
|
|
func TestResourceProvider_Validate_good_source(t *testing.T) {
|
2020-11-25 23:06:17 +01:00
|
|
|
v := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"source": cty.StringVal("/tmp/foo"),
|
|
|
|
"destination": cty.StringVal("/tmp/bar"),
|
2014-07-16 20:41:56 +02:00
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
resp := New().ValidateProvisionerConfig(provisioners.ValidateProvisionerConfigRequest{
|
|
|
|
Config: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(resp.Diagnostics) > 0 {
|
|
|
|
t.Fatal(resp.Diagnostics.ErrWithWarnings())
|
2014-07-16 20:41:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:50:31 +01:00
|
|
|
func TestResourceProvider_Validate_good_content(t *testing.T) {
|
2020-11-25 23:06:17 +01:00
|
|
|
v := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"content": cty.StringVal("value to copy"),
|
|
|
|
"destination": cty.StringVal("/tmp/bar"),
|
2015-11-13 12:50:31 +01:00
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
resp := New().ValidateProvisionerConfig(provisioners.ValidateProvisionerConfigRequest{
|
|
|
|
Config: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(resp.Diagnostics) > 0 {
|
|
|
|
t.Fatal(resp.Diagnostics.ErrWithWarnings())
|
2015-11-13 12:50:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:57:04 +02:00
|
|
|
func TestResourceProvider_Validate_good_unknown_variable_value(t *testing.T) {
|
2020-11-25 23:06:17 +01:00
|
|
|
v := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"content": cty.UnknownVal(cty.String),
|
|
|
|
"destination": cty.StringVal("/tmp/bar"),
|
2017-06-15 19:57:04 +02:00
|
|
|
})
|
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
resp := New().ValidateProvisionerConfig(provisioners.ValidateProvisionerConfigRequest{
|
|
|
|
Config: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(resp.Diagnostics) > 0 {
|
|
|
|
t.Fatal(resp.Diagnostics.ErrWithWarnings())
|
2017-06-15 19:57:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:50:31 +01:00
|
|
|
func TestResourceProvider_Validate_bad_not_destination(t *testing.T) {
|
2020-11-25 23:06:17 +01:00
|
|
|
v := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"source": cty.StringVal("nope"),
|
2014-07-16 20:41:56 +02:00
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
resp := New().ValidateProvisionerConfig(provisioners.ValidateProvisionerConfigRequest{
|
|
|
|
Config: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
if !resp.Diagnostics.HasErrors() {
|
|
|
|
t.Fatal("Should have errors")
|
2014-07-16 20:41:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 21:00:26 +01:00
|
|
|
func TestResourceProvider_Validate_bad_no_source(t *testing.T) {
|
2020-11-25 23:06:17 +01:00
|
|
|
v := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"destination": cty.StringVal("/tmp/bar"),
|
2016-11-29 21:00:26 +01:00
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
resp := New().ValidateProvisionerConfig(provisioners.ValidateProvisionerConfigRequest{
|
|
|
|
Config: v,
|
|
|
|
})
|
|
|
|
|
|
|
|
if !resp.Diagnostics.HasErrors() {
|
|
|
|
t.Fatal("Should have errors")
|
2016-11-29 21:00:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:50:31 +01:00
|
|
|
func TestResourceProvider_Validate_bad_to_many_src(t *testing.T) {
|
2020-11-25 23:06:17 +01:00
|
|
|
v := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"source": cty.StringVal("nope"),
|
|
|
|
"content": cty.StringVal("vlue to copy"),
|
|
|
|
"destination": cty.StringVal("/tmp/bar"),
|
2015-11-13 12:50:31 +01:00
|
|
|
})
|
2017-05-19 20:42:14 +02:00
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
resp := New().ValidateProvisionerConfig(provisioners.ValidateProvisionerConfigRequest{
|
|
|
|
Config: v,
|
|
|
|
})
|
2015-11-13 12:50:31 +01:00
|
|
|
|
2020-11-25 23:06:17 +01:00
|
|
|
if !resp.Diagnostics.HasErrors() {
|
|
|
|
t.Fatal("Should have errors")
|
|
|
|
}
|
2014-07-16 20:41:56 +02:00
|
|
|
}
|