ensure that provisioners are not used after Close
This commit is contained in:
parent
fe7635f438
commit
63a9ab4944
|
@ -9801,14 +9801,17 @@ func TestContext2Apply_plannedConnectionRefs(t *testing.T) {
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
pr := testProvisioner()
|
provisionerFactory := func() (provisioners.Interface, error) {
|
||||||
pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
|
pr := testProvisioner()
|
||||||
host := req.Connection.GetAttr("host")
|
pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
|
||||||
if host.IsNull() || !host.IsKnown() {
|
host := req.Connection.GetAttr("host")
|
||||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("invalid host value: %#v", 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{
|
Providers := map[addrs.Provider]providers.Factory{
|
||||||
|
@ -9816,7 +9819,7 @@ func TestContext2Apply_plannedConnectionRefs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioners := map[string]provisioners.Factory{
|
provisioners := map[string]provisioners.Factory{
|
||||||
"shell": testProvisionerFuncFixed(pr),
|
"shell": provisionerFactory,
|
||||||
}
|
}
|
||||||
|
|
||||||
hook := &testHook{}
|
hook := &testHook{}
|
||||||
|
@ -12163,6 +12166,7 @@ output "out" {
|
||||||
func TestContext2Apply_provisionerSensitive(t *testing.T) {
|
func TestContext2Apply_provisionerSensitive(t *testing.T) {
|
||||||
m := testModule(t, "apply-provisioner-sensitive")
|
m := testModule(t, "apply-provisioner-sensitive")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
||||||
pr := testProvisioner()
|
pr := testProvisioner()
|
||||||
pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
|
pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
|
||||||
if req.Config.ContainsMarked() {
|
if req.Config.ContainsMarked() {
|
||||||
|
@ -12201,6 +12205,9 @@ func TestContext2Apply_provisionerSensitive(t *testing.T) {
|
||||||
t.Fatal("plan failed")
|
t.Fatal("plan failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "restart" provisioner
|
||||||
|
pr.CloseCalled = false
|
||||||
|
|
||||||
state, diags := ctx.Apply()
|
state, diags := ctx.Apply()
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
logDiagnostics(t, diags)
|
logDiagnostics(t, diags)
|
||||||
|
|
|
@ -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) {
|
return func() (provisioners.Interface, error) {
|
||||||
|
// make sure this provisioner has has not been closed
|
||||||
|
rp.CloseCalled = false
|
||||||
return rp, nil
|
return rp, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue