From 0da8fe2087415d93ebd8928cdaf24ddbdd6f9535 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 10 May 2018 17:57:02 -0700 Subject: [PATCH] core: Fix EvalValidateSelfRef tests We must provide a schema for the synthetic body we use for testing so that the references can be found within it. --- terraform/eval_validate_selfref_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/terraform/eval_validate_selfref_test.go b/terraform/eval_validate_selfref_test.go index c44cf9086..f828e990b 100644 --- a/terraform/eval_validate_selfref_test.go +++ b/terraform/eval_validate_selfref_test.go @@ -4,6 +4,9 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform/config/configschema" + "github.com/hashicorp/terraform/tfdiags" + "github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcltest" "github.com/hashicorp/terraform/addrs" @@ -80,13 +83,26 @@ func TestEvalValidateSelfRef(t *testing.T) { n := &EvalValidateSelfRef{ Addr: test.Addr, Config: body, + Schema: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": { + Type: cty.String, + Required: true, + }, + }, + }, } result, err := n.Eval(nil) if result != nil { t.Fatal("result should always be nil") } - if (err != nil) != test.Err { - t.Fatalf("err: %s", err) + diags := tfdiags.Diagnostics(nil).Append(err) + if diags.HasErrors() != test.Err { + if test.Err { + t.Errorf("unexpected success; want error") + } else { + t.Errorf("unexpected error\n\n%s", diags.Err()) + } } }) }