sq/drivers/csv/csv_test.go

56 lines
1.2 KiB
Go
Raw Normal View History

2020-08-06 20:58:47 +03:00
package csv_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/neilotoole/sq/testh"
"github.com/neilotoole/sq/testh/sakila"
)
func TestSmoke(t *testing.T) {
testCases := []string{sakila.CSVActor, sakila.TSVActor, sakila.CSVActorHTTP}
for _, handle := range testCases {
handle := handle
t.Run(handle, func(t *testing.T) {
t.Parallel()
th := testh.New(t)
src := th.Source(sakila.CSVActor)
sink, err := th.QuerySQL(src, "SELECT * FROM data")
require.NoError(t, err)
require.Equal(t, len(sakila.TblActorCols()), len(sink.RecMeta))
2020-08-06 20:58:47 +03:00
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
})
}
}
func TestQuerySQL_Count(t *testing.T) {
testCases := []string{sakila.CSVActor, sakila.TSVActor}
2020-08-06 20:58:47 +03:00
for _, handle := range testCases {
handle := handle
t.Run(handle, func(t *testing.T) {
t.Parallel()
th := testh.New(t)
src := th.Source(handle)
sink, err := th.QuerySQL(src, "SELECT * FROM data")
require.NoError(t, err)
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
sink, err = th.QuerySQL(src, "SELECT COUNT(*) FROM data")
require.NoError(t, err)
count, ok := sink.Recs[0][0].(*int64)
require.True(t, ok)
require.Equal(t, int64(sakila.TblActorCount), *count)
})
}
}