MCPcopy Create free account
hub / github.com/cloudspannerecosystem/spanner-cli / TestPrintResult

Function TestPrintResult

cli_test.go:191–267  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

189}
190
191func TestPrintResult(t *testing.T) {
192 t.Run("DisplayModeTable", func(t *testing.T) {
193 out := &bytes.Buffer{}
194 result := &Result{
195 ColumnNames: []string{"foo", "bar"},
196 Rows: []Row{
197 {[]string{"1", "2"}},
198 {[]string{"3", "4"}},
199 },
200 IsMutation: false,
201 }
202 printResult(out, result, DisplayModeTable, false, false)
203
204 expected := strings.TrimPrefix(`
205+-----+-----+
206| foo | bar |
207+-----+-----+
208| 1 | 2 |
209| 3 | 4 |
210+-----+-----+
211`, "\n")
212
213 got := out.String()
214 if got != expected {
215 t.Errorf("invalid print: expected = %s, but got = %s", expected, got)
216 }
217 })
218
219 t.Run("DisplayModeVertical", func(t *testing.T) {
220 out := &bytes.Buffer{}
221 result := &Result{
222 ColumnNames: []string{"foo", "bar"},
223 Rows: []Row{
224 {[]string{"1", "2"}},
225 {[]string{"3", "4"}},
226 },
227 IsMutation: false,
228 }
229 printResult(out, result, DisplayModeVertical, false, false)
230
231 expected := strings.TrimPrefix(`
232*************************** 1. row ***************************
233foo: 1
234bar: 2
235*************************** 2. row ***************************
236foo: 3
237bar: 4
238`, "\n")
239
240 got := out.String()
241 if got != expected {
242 t.Errorf("invalid print: expected = %s, but got = %s", expected, got)
243 }
244 })
245
246 t.Run("DisplayModeTab", func(t *testing.T) {
247 out := &bytes.Buffer{}
248 result := &Result{

Callers

nothing calls this directly

Calls 2

printResultFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected