MCPcopy Create free account
hub / github.com/basecamp/hey-cli / TestExitCodeFor

Function TestExitCodeFor

internal/output/writer_test.go:122–143  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120 w := New(Options{Format: FormatJSON, Stdout: &buf, JQFilter: ".data.name"})
121
122 if err := w.OK(map[string]any{"name": "Jane"}); err != nil {
123 t.Fatal(err)
124 }
125 if got := buf.String(); got != "Jane\n" {
126 t.Errorf("expected scalar text, got %q", got)
127 }
128}
129
130func TestWriterOK_JQFiltersQuietData(t *testing.T) {
131 var buf bytes.Buffer
132 w := New(Options{Format: FormatQuiet, Stdout: &buf, JQFilter: ".[0].id"})
133
134 if err := w.OK([]map[string]any{{"id": 42}}); err != nil {
135 t.Fatal(err)
136 }
137 if got := buf.String(); got != "42\n" {
138 t.Errorf("expected data-only result, got %q", got)
139 }
140}
141
142func TestWriterOK_JQFormatsObjectsAndArrays(t *testing.T) {
143 var buf bytes.Buffer
144 w := New(Options{Format: FormatJSON, Stdout: &buf, JQFilter: ".data"})
145
146 if err := w.OK(map[string]any{"names": []string{"Jane", "Lin"}}); err != nil {

Callers

nothing calls this directly

Calls 9

ErrUsageFunction · 0.85
ErrNotFoundFunction · 0.85
ErrAuthFunction · 0.85
ErrForbiddenFunction · 0.85
ErrRateLimitFunction · 0.85
ErrNetworkFunction · 0.85
ErrAPIFunction · 0.85
ErrAmbiguousFunction · 0.85
ExitCodeForFunction · 0.85

Tested by

no test coverage detected