add test checking CloseProvider

There was no test checking that Close wsa called on the mock provider.
This fails now since the CloseProviderTransformer isn't using the fully
resolved provider name.
This commit is contained in:
James Bardin 2018-01-04 15:00:09 -05:00
parent 4700a86ee6
commit ba749db9ed
4 changed files with 39 additions and 2 deletions

View File

@ -2401,6 +2401,32 @@ func TestContext2Plan_hook(t *testing.T) {
} }
} }
func TestContext2Plan_closeProvider(t *testing.T) {
// this fixture only has an aliased provider located in the module, to make
// sure that the provier name contains a path more complex than
// "provider.aws".
m := testModule(t, "plan-close-module-provider")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
})
_, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
if !p.CloseCalled {
t.Fatal("provider not closed")
}
}
func TestContext2Plan_orphan(t *testing.T) { func TestContext2Plan_orphan(t *testing.T) {
m := testModule(t, "plan-orphan") m := testModule(t, "plan-orphan")
p := testProvider("aws") p := testProvider("aws")

View File

@ -90,7 +90,8 @@ func TestEvalInitProvider(t *testing.T) {
} }
func TestEvalCloseProvider(t *testing.T) { func TestEvalCloseProvider(t *testing.T) {
n := &EvalCloseProvider{Name: "foo"} providerName := ResolveProviderName("foo", nil)
n := &EvalCloseProvider{Name: providerName}
provider := &MockResourceProvider{} provider := &MockResourceProvider{}
ctx := &MockEvalContext{CloseProviderProvider: provider} ctx := &MockEvalContext{CloseProviderProvider: provider}
if _, err := n.Eval(ctx); err != nil { if _, err := n.Eval(ctx); err != nil {
@ -100,7 +101,7 @@ func TestEvalCloseProvider(t *testing.T) {
if !ctx.CloseProviderCalled { if !ctx.CloseProviderCalled {
t.Fatal("should be called") t.Fatal("should be called")
} }
if ctx.CloseProviderName != "foo" { if ctx.CloseProviderName != providerName {
t.Fatalf("bad: %#v", ctx.CloseProviderName) t.Fatalf("bad: %#v", ctx.CloseProviderName)
} }
} }

View File

@ -0,0 +1,3 @@
module "mod" {
source = "./mod"
}

View File

@ -0,0 +1,7 @@
provider "aws" {
alias = "mod"
}
resource "aws_instance" "bar" {
provider = "aws.mod"
}