mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-21 07:01:41 +03:00
db55986980
- Support for ingest cache, download cache, and progress bars.
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package yamlw_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/neilotoole/sq/cli/output"
|
|
"github.com/neilotoole/sq/cli/output/yamlw"
|
|
"github.com/neilotoole/sq/testh"
|
|
"github.com/neilotoole/sq/testh/sakila"
|
|
)
|
|
|
|
func TestRecordWriter(t *testing.T) {
|
|
const want = `- last_update: 2020-06-11T02:50:54Z
|
|
actor_id: 1
|
|
last_name: GUINESS
|
|
first_name: PENELOPE
|
|
- last_update: 2020-06-11T02:50:54Z
|
|
actor_id: 2
|
|
last_name: WAHLBERG
|
|
first_name: NICK
|
|
`
|
|
|
|
th, src, _, _, _ := testh.NewWith(t, sakila.SL3)
|
|
query := src.Handle + ".actor | .last_update, .actor_id, .last_name, .first_name | .[0:2]"
|
|
|
|
sink, err := th.QuerySLQ(query, nil)
|
|
require.NoError(t, err)
|
|
t.Log(len(sink.Recs))
|
|
|
|
buf := &bytes.Buffer{}
|
|
pr := output.NewPrinting()
|
|
pr.EnableColor(false)
|
|
recw := yamlw.NewRecordWriter(buf, pr)
|
|
require.NoError(t, recw.Open(th.Context, sink.RecMeta))
|
|
|
|
err = recw.WriteRecords(th.Context, sink.Recs)
|
|
require.NoError(t, err)
|
|
require.NoError(t, recw.Flush(th.Context))
|
|
require.NoError(t, recw.Close(th.Context))
|
|
|
|
want2 := want
|
|
_ = want2
|
|
got := buf.String()
|
|
t.Log("\n" + got)
|
|
require.Equal(t, want, got)
|
|
}
|