terraform: Test Validation of provisioners

This commit is contained in:
Armon Dadgar 2014-07-08 14:45:59 -07:00
parent 87c3423fd4
commit 03a20f072e
2 changed files with 60 additions and 0 deletions

View File

@ -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
}

View File

@ -0,0 +1,7 @@
provider "aws" {
foo = "bar"
}
resource "aws_instance" "test" {
provisioner "shell" {}
}