ensure that provisioners are not used after Close

This commit is contained in:
James Bardin 2021-01-19 16:59:22 -05:00
parent fe7635f438
commit 63a9ab4944
2 changed files with 18 additions and 9 deletions

View File

@ -9801,14 +9801,17 @@ func TestContext2Apply_plannedConnectionRefs(t *testing.T) {
return resp
}
pr := testProvisioner()
pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
host := req.Connection.GetAttr("host")
if host.IsNull() || !host.IsKnown() {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("invalid host value: %#v", host))
}
provisionerFactory := func() (provisioners.Interface, error) {
pr := testProvisioner()
pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
host := req.Connection.GetAttr("host")
if host.IsNull() || !host.IsKnown() {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("invalid host value: %#v", host))
}
return resp
return resp
}
return pr, nil
}
Providers := map[addrs.Provider]providers.Factory{
@ -9816,7 +9819,7 @@ func TestContext2Apply_plannedConnectionRefs(t *testing.T) {
}
provisioners := map[string]provisioners.Factory{
"shell": testProvisionerFuncFixed(pr),
"shell": provisionerFactory,
}
hook := &testHook{}
@ -12163,6 +12166,7 @@ output "out" {
func TestContext2Apply_provisionerSensitive(t *testing.T) {
m := testModule(t, "apply-provisioner-sensitive")
p := testProvider("aws")
pr := testProvisioner()
pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
if req.Config.ContainsMarked() {
@ -12201,6 +12205,9 @@ func TestContext2Apply_provisionerSensitive(t *testing.T) {
t.Fatal("plan failed")
}
// "restart" provisioner
pr.CloseCalled = false
state, diags := ctx.Apply()
if diags.HasErrors() {
logDiagnostics(t, diags)

View File

@ -170,8 +170,10 @@ func testProviderFuncFixed(rp providers.Interface) providers.Factory {
}
}
func testProvisionerFuncFixed(rp provisioners.Interface) provisioners.Factory {
func testProvisionerFuncFixed(rp *MockProvisioner) provisioners.Factory {
return func() (provisioners.Interface, error) {
// make sure this provisioner has has not been closed
rp.CloseCalled = false
return rp, nil
}
}