mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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
This commit is contained in:
parent
ce2e59f835
commit
a720409ded
@ -1,6 +1,7 @@
|
|||||||
package terraform
|
package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"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