Skip to content

Commit

Permalink
terraform: some more test cases for sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Oct 17, 2014
1 parent 82bf4f4 commit 35352a2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions terraform/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,45 @@ func TestContextApply_provisionerCreateFail(t *testing.T) {
}
}

func TestContextApply_provisionerCreateFailNoId(t *testing.T) {
m := testModule(t, "apply-provisioner-fail-create")
p := testProvider("aws")
pr := testProvisioner()
p.DiffFn = testDiffFn

p.ApplyFn = func(
info *InstanceInfo,
is *InstanceState,
id *InstanceDiff) (*InstanceState, error) {
return nil, fmt.Errorf("error")
}

ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Provisioners: map[string]ResourceProvisionerFactory{
"shell": testProvisionerFuncFixed(pr),
},
})

if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err)
}

state, err := ctx.Apply()
if err == nil {
t.Fatal("should error")
}

actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyProvisionerFailCreateNoIdStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}

func TestContextApply_provisionerFail(t *testing.T) {
m := testModule(t, "apply-provisioner-fail")
p := testProvider("aws")
Expand Down
4 changes: 4 additions & 0 deletions terraform/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ aws_instance.bar: (1 tainted)
Tainted ID 1 = foo
`

const testTerraformApplyProvisionerFailCreateNoIdStr = `
<no state>
`

const testTerraformApplyProvisionerFailCreateBeforeDestroyStr = `
aws_instance.bar: (1 tainted)
ID = bar
Expand Down

0 comments on commit 35352a2

Please sign in to comment.