(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func 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) |
nothing calls this directly
no test coverage detected