MCPcopy Index your code
hub / github.com/coder/coder / Test_OutputFormatter

Function Test_OutputFormatter

cli/cliui/output_test.go:41–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func Test_OutputFormatter(t *testing.T) {
42 t.Parallel()
43
44 t.Run("RequiresTwoFormatters", func(t *testing.T) {
45 t.Parallel()
46
47 require.Panics(t, func() {
48 cliui.NewOutputFormatter()
49 })
50 require.Panics(t, func() {
51 cliui.NewOutputFormatter(cliui.JSONFormat())
52 })
53 require.NotPanics(t, func() {
54 cliui.NewOutputFormatter(cliui.JSONFormat(), cliui.TextFormat())
55 })
56 })
57
58 t.Run("NoMissingFormatID", func(t *testing.T) {
59 t.Parallel()
60
61 require.Panics(t, func() {
62 cliui.NewOutputFormatter(
63 cliui.JSONFormat(),
64 &format{id: ""},
65 )
66 })
67 })
68
69 t.Run("NoDuplicateFormats", func(t *testing.T) {
70 t.Parallel()
71
72 require.Panics(t, func() {
73 cliui.NewOutputFormatter(
74 cliui.JSONFormat(),
75 cliui.JSONFormat(),
76 )
77 })
78 })
79
80 t.Run("OK", func(t *testing.T) {
81 t.Parallel()
82
83 var called atomic.Int64
84 f := cliui.NewOutputFormatter(
85 cliui.JSONFormat(),
86 &format{
87 id: "foo",
88 attachOptionsFn: func(opts *serpent.OptionSet) {
89 opts.Add(serpent.Option{
90 Name: "foo",
91 Flag: "foo",
92 FlagShorthand: "f",
93 Value: serpent.DiscardValue,
94 Description: "foo flag 1234",
95 })
96 },
97 formatFn: func(_ context.Context, _ any) (string, error) {
98 called.Add(1)

Callers

nothing calls this directly

Calls 14

AttachOptionsMethod · 0.95
FormatMethod · 0.95
NewOutputFormatterFunction · 0.92
JSONFormatFunction · 0.92
TextFormatFunction · 0.92
RunMethod · 0.65
AddMethod · 0.65
SetMethod · 0.65
EqualMethod · 0.45
StringMethod · 0.45
ContainsMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected