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:
parent
4700a86ee6
commit
ba749db9ed
|
@ -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) {
|
||||
m := testModule(t, "plan-orphan")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -90,7 +90,8 @@ func TestEvalInitProvider(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestEvalCloseProvider(t *testing.T) {
|
||||
n := &EvalCloseProvider{Name: "foo"}
|
||||
providerName := ResolveProviderName("foo", nil)
|
||||
n := &EvalCloseProvider{Name: providerName}
|
||||
provider := &MockResourceProvider{}
|
||||
ctx := &MockEvalContext{CloseProviderProvider: provider}
|
||||
if _, err := n.Eval(ctx); err != nil {
|
||||
|
@ -100,7 +101,7 @@ func TestEvalCloseProvider(t *testing.T) {
|
|||
if !ctx.CloseProviderCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if ctx.CloseProviderName != "foo" {
|
||||
if ctx.CloseProviderName != providerName {
|
||||
t.Fatalf("bad: %#v", ctx.CloseProviderName)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module "mod" {
|
||||
source = "./mod"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
provider "aws" {
|
||||
alias = "mod"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
provider = "aws.mod"
|
||||
}
|
Loading…
Reference in New Issue