core: fix test for buildProviderConfig
This was incorrectly comparing a cty.Value to an hcl.Body. Now we decode the body first so we can compare two of cty.Value. Also includes a fix to a stale comment in buildProviderConfig that was no longer accurate.
This commit is contained in:
parent
0a59da418a
commit
39a83b2fd1
|
@ -17,8 +17,7 @@ func buildProviderConfig(ctx EvalContext, addr addrs.ProviderConfig, body hcl.Bo
|
||||||
// "input" is a map of the subset of config values that were known
|
// "input" is a map of the subset of config values that were known
|
||||||
// during the input walk, set by EvalInputProvider. Note that
|
// during the input walk, set by EvalInputProvider. Note that
|
||||||
// in particular it does *not* include attributes that had
|
// in particular it does *not* include attributes that had
|
||||||
// computed values at input time; those appear *only* in
|
// computed values at input time.
|
||||||
// "cfg" here.
|
|
||||||
|
|
||||||
inputBody := configs.SynthBody("<input prompt>", input)
|
inputBody := configs.SynthBody("<input prompt>", input)
|
||||||
body = configs.MergeBodies(body, inputBody)
|
body = configs.MergeBodies(body, inputBody)
|
||||||
|
|
|
@ -4,19 +4,19 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/configs"
|
"github.com/hashicorp/hcl2/hcldec"
|
||||||
"github.com/zclconf/go-cty/cty"
|
"github.com/zclconf/go-cty/cty"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/addrs"
|
"github.com/hashicorp/terraform/addrs"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
|
"github.com/hashicorp/terraform/config/configschema"
|
||||||
|
"github.com/hashicorp/terraform/configs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildProviderConfig(t *testing.T) {
|
func TestBuildProviderConfig(t *testing.T) {
|
||||||
configBody := configs.SynthBody("", map[string]cty.Value{
|
configBody := configs.SynthBody("", map[string]cty.Value{
|
||||||
"set_in_config": cty.StringVal("config"),
|
"set_in_config": cty.StringVal("config"),
|
||||||
"set_in_config_and_parent": cty.StringVal("config"),
|
"set_in_config_and_input": cty.StringVal("config"),
|
||||||
"computed_in_config": cty.StringVal("config"),
|
|
||||||
})
|
})
|
||||||
providerAddr := addrs.ProviderConfig{
|
providerAddr := addrs.ProviderConfig{
|
||||||
Type: "foo",
|
Type: "foo",
|
||||||
|
@ -24,21 +24,32 @@ func TestBuildProviderConfig(t *testing.T) {
|
||||||
|
|
||||||
ctx := &MockEvalContext{
|
ctx := &MockEvalContext{
|
||||||
ProviderInputValues: map[string]cty.Value{
|
ProviderInputValues: map[string]cty.Value{
|
||||||
"set_in_config": cty.StringVal("input"),
|
"set_in_config_and_input": cty.StringVal("input"),
|
||||||
"set_by_input": cty.StringVal("input"),
|
"set_by_input": cty.StringVal("input"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
got := buildProviderConfig(ctx, providerAddr, configBody)
|
gotBody := buildProviderConfig(ctx, providerAddr, configBody)
|
||||||
|
|
||||||
|
schema := &configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"set_in_config": {Type: cty.String, Optional: true},
|
||||||
|
"set_in_config_and_input": {Type: cty.String, Optional: true},
|
||||||
|
"set_by_input": {Type: cty.String, Optional: true},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
got, diags := hcldec.Decode(gotBody, schema.DecoderSpec(), nil)
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatalf("body decode failed: %s", diags.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// We expect the provider config with the added input value
|
// We expect the provider config with the added input value
|
||||||
want := map[string]cty.Value{
|
want := cty.ObjectVal(map[string]cty.Value{
|
||||||
"set_in_config": cty.StringVal("config"),
|
"set_in_config": cty.StringVal("config"),
|
||||||
"set_in_config_and_parent": cty.StringVal("config"),
|
"set_in_config_and_input": cty.StringVal("input"),
|
||||||
"computed_in_config": cty.StringVal("config"),
|
|
||||||
"set_by_input": cty.StringVal("input"),
|
"set_by_input": cty.StringVal("input"),
|
||||||
}
|
})
|
||||||
if !reflect.DeepEqual(got, want) {
|
if !got.RawEquals(want) {
|
||||||
t.Fatalf("incorrect merged config\ngot: %#v\nwant: \n%#v", got, want)
|
t.Fatalf("incorrect merged config\ngot: %#v\nwant: %#v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue