From a720409ded395bd52176267000e0c2063b1d487c Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Tue, 22 Sep 2020 16:24:57 -0400 Subject: [PATCH] Add test for GetInputVariable, with sensitive config This adds a test for GetInputVariable, and includes a variable with a "sensitive" attribute in configuration, to test that that value is marked as sensitive --- terraform/evaluate_test.go | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/terraform/evaluate_test.go b/terraform/evaluate_test.go index 18b2d65f7..d5b13893e 100644 --- a/terraform/evaluate_test.go +++ b/terraform/evaluate_test.go @@ -1,6 +1,7 @@ package terraform import ( + "sync" "testing" "github.com/davecgh/go-spew/spew" @@ -78,3 +79,45 @@ func TestEvaluatorGetPathAttr(t *testing.T) { } }) } + +// This particularly tests that a sensitive attribute in config +// results in a value that has a "sensitive" cty Mark +func TestEvaluatorGetInputVariable(t *testing.T) { + evaluator := &Evaluator{ + Meta: &ContextMeta{ + Env: "foo", + }, + Config: &configs.Config{ + Module: &configs.Module{ + Variables: map[string]*configs.Variable{ + "some_var": { + Name: "some_var", + Sensitive: true, + Default: cty.StringVal("foo"), + }, + }, + }, + }, + VariableValues: map[string]map[string]cty.Value{ + "": {"some_var": cty.StringVal("bar")}, + }, + VariableValuesLock: &sync.Mutex{}, + } + + data := &evaluationStateData{ + Evaluator: evaluator, + } + scope := evaluator.Scope(data, nil) + + want := cty.StringVal("bar").Mark("sensitive") + got, diags := scope.Data.GetInputVariable(addrs.InputVariable{ + Name: "some_var", + }, tfdiags.SourceRange{}) + + if len(diags) != 0 { + t.Errorf("unexpected diagnostics %s", spew.Sdump(diags)) + } + if !got.RawEquals(want) { + t.Errorf("wrong result %#v; want %#v", got, want) + } +}