File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
internal/backend/backendbase Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -214,3 +214,41 @@ func TestBase_deprecatedArg(t *testing.T) {
214214 }
215215 })
216216}
217+
218+ func TestBase_nullCrash (t * testing.T ) {
219+ // This test ensures that we don't crash while applying defaults to
220+ // a null value
221+
222+ b := Base {
223+ Schema : & configschema.Block {
224+ Attributes : map [string ]* configschema.Attribute {
225+ "foo" : {
226+ Type : cty .String ,
227+ Required : true ,
228+ },
229+ },
230+ },
231+ SDKLikeDefaults : SDKLikeDefaults {
232+ "foo" : {
233+ Fallback : "fallback" ,
234+ },
235+ },
236+ }
237+
238+ t .Run ("error" , func (t * testing.T ) {
239+ // We pass an explicit null value here to simulate an interrupt
240+ _ , gotDiags := b .PrepareConfig (cty .NullVal (cty .Object (map [string ]cty.Type {
241+ "foo" : cty .String ,
242+ })))
243+ var wantDiags tfdiags.Diagnostics
244+ wantDiags = wantDiags .Append (
245+ & hcl.Diagnostic {
246+ Severity : hcl .DiagError ,
247+ Summary : "Invalid backend configuration" ,
248+ Detail : "The backend configuration is incorrect: attribute \" foo\" is required." ,
249+ })
250+ if diff := cmp .Diff (wantDiags .ForRPC (), gotDiags .ForRPC ()); diff != "" {
251+ t .Errorf ("wrong diagnostics\n %s" , diff )
252+ }
253+ })
254+ }
You can’t perform that action at this time.
0 commit comments