Merge pull request #26342 from hashicorp/pselle/evaluate_test

tests: Add test for GetInputVariable, with sensitive config
This commit is contained in:
Pam Selle 2020-09-23 11:25:47 -04:00 committed by GitHub
commit c8169950a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 0 deletions

View File

@ -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)
}
}