MCPcopy
hub / github.com/opentofu/opentofu / TestOutputHuman_single

Function TestOutputHuman_single

internal/command/views/output_test.go:21–77  ·  view source on GitHub ↗

Test various single output values for human-readable UI. Note that since OutputHuman defers to repl.FormatValue to render a single value, most of the test coverage should be in that package.

(t *testing.T)

Source from the content-addressed store, hash-verified

19// OutputHuman defers to repl.FormatValue to render a single value, most of the
20// test coverage should be in that package.
21func TestOutputHuman_single(t *testing.T) {
22 testCases := map[string]struct {
23 value cty.Value
24 want string
25 wantErr bool
26 }{
27 "string": {
28 value: cty.StringVal("hello"),
29 want: "\"hello\"\n",
30 },
31 "list of maps": {
32 value: cty.ListVal([]cty.Value{
33 cty.MapVal(map[string]cty.Value{
34 "key": cty.StringVal("value"),
35 "key2": cty.StringVal("value2"),
36 }),
37 cty.MapVal(map[string]cty.Value{
38 "key": cty.StringVal("value"),
39 }),
40 }),
41 want: `tolist([
42 tomap({
43 "key" = "value"
44 "key2" = "value2"
45 }),
46 tomap({
47 "key" = "value"
48 }),
49])
50`,
51 },
52 }
53
54 for name, tc := range testCases {
55 t.Run(name, func(t *testing.T) {
56 streams, done := terminal.StreamsForTesting(t)
57 v := NewOutput(arguments.ViewOptions{ViewType: arguments.ViewHuman}, NewView(streams))
58
59 outputs := map[string]*states.OutputValue{
60 "foo": {Value: tc.value},
61 }
62 diags := v.Output("foo", outputs)
63
64 if diags.HasErrors() {
65 if !tc.wantErr {
66 t.Fatalf("unexpected diagnostics: %s", diags)
67 }
68 } else if tc.wantErr {
69 t.Fatalf("succeeded, but want error")
70 }
71
72 if got, want := done(t).Stdout(), tc.want; got != want {
73 t.Errorf("wrong result\ngot: %q\nwant: %q", got, want)
74 }
75 })
76 }
77}
78

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected