mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
test for invalid nil value during apply
This commit is contained in:
parent
e075c8ab8b
commit
54523991a2
@ -12522,3 +12522,38 @@ resource "test_object" "a" {
|
|||||||
t.Fatalf("incorrect diagnostics, got %d values with %s", len(diags), diags.ErrWithWarnings())
|
t.Fatalf("incorrect diagnostics, got %d values with %s", len(diags), diags.ErrWithWarnings())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Apply_nilResponse(t *testing.T) {
|
||||||
|
// empty config to remove our resource
|
||||||
|
m := testModuleInline(t, map[string]string{
|
||||||
|
"main.tf": `
|
||||||
|
resource "test_object" "a" {
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
p := simpleMockProvider()
|
||||||
|
p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{}
|
||||||
|
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Config: m,
|
||||||
|
Providers: map[addrs.Provider]providers.Factory{
|
||||||
|
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
_, diags := ctx.Plan()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatal(diags.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, diags = ctx.Apply()
|
||||||
|
if !diags.HasErrors() {
|
||||||
|
t.Fatal("expected and error")
|
||||||
|
}
|
||||||
|
|
||||||
|
errString := diags.ErrWithWarnings().Error()
|
||||||
|
if !strings.Contains(errString, "invalid nil value") {
|
||||||
|
t.Fatalf("error missing expected info: %q", errString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1920,14 +1920,16 @@ func (n *NodeAbstractResourceInstance) apply(
|
|||||||
newVal = cty.NullVal(schema.ImpliedType())
|
newVal = cty.NullVal(schema.ImpliedType())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ideally we'd produce an error or warning here if newVal is nil and
|
if !diags.HasErrors() {
|
||||||
// there are no errors in diags, because that indicates a buggy
|
diags = diags.Append(tfdiags.Sourceless(
|
||||||
// provider not properly reporting its result, but unfortunately many
|
tfdiags.Error,
|
||||||
// of our historical test mocks behave in this way and so producing
|
"Provider produced invalid object",
|
||||||
// a diagnostic here fails hundreds of tests. Instead, we must just
|
fmt.Sprintf(
|
||||||
// silently retain the old value for now. Returning a nil value with
|
"Provider %q produced an invalid nil value after apply for %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.",
|
||||||
// no errors is still always considered a bug in the provider though,
|
n.ResolvedProvider.String(), n.Addr.String(),
|
||||||
// and should be fixed for any "real" providers that do it.
|
),
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var conformDiags tfdiags.Diagnostics
|
var conformDiags tfdiags.Diagnostics
|
||||||
|
Loading…
Reference in New Issue
Block a user