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.
This commit is contained in:
Martin Atkins 2018-05-10 17:57:02 -07:00
parent 4a002bf10b
commit 0da8fe2087
1 changed files with 18 additions and 2 deletions

View File

@ -4,6 +4,9 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/hashicorp/terraform/config/configschema"
"github.com/hashicorp/terraform/tfdiags"
"github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcl"
"github.com/hashicorp/hcl2/hcltest" "github.com/hashicorp/hcl2/hcltest"
"github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/addrs"
@ -80,13 +83,26 @@ func TestEvalValidateSelfRef(t *testing.T) {
n := &EvalValidateSelfRef{ n := &EvalValidateSelfRef{
Addr: test.Addr, Addr: test.Addr,
Config: body, Config: body,
Schema: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"foo": {
Type: cty.String,
Required: true,
},
},
},
} }
result, err := n.Eval(nil) result, err := n.Eval(nil)
if result != nil { if result != nil {
t.Fatal("result should always be nil") t.Fatal("result should always be nil")
} }
if (err != nil) != test.Err { diags := tfdiags.Diagnostics(nil).Append(err)
t.Fatalf("err: %s", 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())
}
} }
}) })
} }