mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 15:36:26 -06:00
terraform: Test Validation of provisioners
This commit is contained in:
parent
87c3423fd4
commit
03a20f072e
@ -132,6 +132,54 @@ func TestContextValidate_requiredVar(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_provisionerConfig_bad(t *testing.T) {
|
||||
config := testConfig(t, "validate-bad-prov-conf")
|
||||
p := testProvider("aws")
|
||||
pr := testProvisioner()
|
||||
c := testContext(t, &ContextOpts{
|
||||
Config: config,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ResourceProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
},
|
||||
})
|
||||
|
||||
pr.ValidateReturnErrors = []error{fmt.Errorf("bad")}
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) == 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_provisionerConfig_good(t *testing.T) {
|
||||
config := testConfig(t, "validate-bad-prov-conf")
|
||||
p := testProvider("aws")
|
||||
pr := testProvisioner()
|
||||
c := testContext(t, &ContextOpts{
|
||||
Config: config,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ResourceProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) > 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextApply(t *testing.T) {
|
||||
c := testConfig(t, "apply-good")
|
||||
p := testProvider("aws")
|
||||
@ -1406,3 +1454,8 @@ func testProvider(prefix string) *MockResourceProvider {
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func testProvisioner() *MockResourceProvisioner {
|
||||
p := new(MockResourceProvisioner)
|
||||
return p
|
||||
}
|
||||
|
7
terraform/test-fixtures/validate-bad-prov-conf/main.tf
Normal file
7
terraform/test-fixtures/validate-bad-prov-conf/main.tf
Normal file
@ -0,0 +1,7 @@
|
||||
provider "aws" {
|
||||
foo = "bar"
|
||||
}
|
||||
|
||||
resource "aws_instance" "test" {
|
||||
provisioner "shell" {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user