mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #26342 from hashicorp/pselle/evaluate_test
tests: Add test for GetInputVariable, with sensitive config
This commit is contained in:
commit
c8169950a8
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user