MCPcopy
hub / github.com/opentofu/opentofu / TestOutput_sensitive

Function TestOutput_sensitive

internal/command/views/output_test.go:81–112  ·  view source on GitHub ↗

Sensitive output values are rendered to the console intentionally when requesting a single output.

(t *testing.T)

Source from the content-addressed store, hash-verified

79// Sensitive output values are rendered to the console intentionally when
80// requesting a single output.
81func TestOutput_sensitive(t *testing.T) {
82 testCases := map[string]arguments.ViewType{
83 "human": arguments.ViewHuman,
84 "json": arguments.ViewJSON,
85 "raw": arguments.ViewRaw,
86 }
87 for name, vt := range testCases {
88 t.Run(name, func(t *testing.T) {
89 streams, done := terminal.StreamsForTesting(t)
90 v := NewOutput(arguments.ViewOptions{ViewType: vt}, NewView(streams))
91
92 outputs := map[string]*states.OutputValue{
93 "foo": {
94 Value: cty.StringVal("secret"),
95 Sensitive: true,
96 },
97 }
98 diags := v.Output("foo", outputs)
99
100 if diags.HasErrors() {
101 t.Fatalf("unexpected diagnostics: %s", diags)
102 }
103
104 // Test for substring match here because we don't care about exact
105 // output format in this test, just the presence of the sensitive
106 // value.
107 if got, want := done(t).Stdout(), "secret"; !strings.Contains(got, want) {
108 t.Errorf("wrong result\ngot: %q\nwant: %q", got, want)
109 }
110 })
111 }
112}
113
114// Showing all outputs is supported by human and JSON output format.
115func TestOutput_all(t *testing.T) {

Callers

nothing calls this directly

Calls 8

OutputMethod · 0.95
StreamsForTestingFunction · 0.92
NewOutputFunction · 0.85
NewViewFunction · 0.85
HasErrorsMethod · 0.80
StdoutMethod · 0.80
RunMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected