sq/libsq/libsq_test.go
Neil O'Toole 915e01fdda
added Go dependency cache to go.yml workflow, and go test now covers the full codebase (#53)
* added Go dependency cache to go.yml workflow

* more windows path issues

* docs

* restricting workflow triggers to master

* wrong cleanup order for downloaded files

* de-restricting workflow triggers, for now

* more out-of-order cleanup issues that only manifested on windows

* more out-of-order cleanup issues

* removed mediatype check from TestFetchFile; FetchFile is deprecated and not worth fixing

* tracked down out-of-sequence close/remove issue with sqlite

* probably long-running test failure

* disabling long-running tests that are breaking CI

* switching to go test -short because tests seem to be taking too long in CI
2020-08-08 15:23:30 -06:00

117 lines
2.7 KiB
Go

package libsq_test
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
"github.com/neilotoole/sq/libsq/source"
"github.com/neilotoole/sq/libsq/sqlz"
"github.com/neilotoole/sq/testh"
"github.com/neilotoole/sq/testh/sakila"
)
// TestQuerySQL_Smoke is a smoke test of testh.QuerySQL.
func TestQuerySQL_Smoke(t *testing.T) {
t.Parallel()
wantActorFieldTypes := []reflect.Type{
sqlz.RTypeInt64P,
sqlz.RTypeStringP,
sqlz.RTypeStringP,
sqlz.RTypeTimeP,
}
testCases := []struct {
handle string
fieldTypes []reflect.Type
}{
{
handle: sakila.SL3,
fieldTypes: wantActorFieldTypes,
},
{
handle: sakila.My,
fieldTypes: wantActorFieldTypes,
},
{
handle: sakila.Pg,
fieldTypes: wantActorFieldTypes,
},
{
handle: sakila.MS,
fieldTypes: wantActorFieldTypes,
},
{
handle: sakila.CSVActor,
fieldTypes: []reflect.Type{
// FIXME: change to wantActorFieldTypes when CSV driver detects field types automagically
sqlz.RTypeInt64P,
sqlz.RTypeStringP,
sqlz.RTypeStringP,
sqlz.RTypeStringP,
},
},
{
handle: sakila.XLSX,
fieldTypes: []reflect.Type{
// FIXME: change to wantActorFieldTypes when CSV driver detects field types automagically
sqlz.RTypeInt64P,
sqlz.RTypeStringP,
sqlz.RTypeStringP,
sqlz.RTypeStringP,
},
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.handle, func(t *testing.T) {
testh.SkipShort(t, tc.handle == sakila.XLSX)
t.Parallel()
th := testh.New(t)
src := th.Source(tc.handle)
tblName := sakila.TblActor
if th.IsMonotable(src) {
tblName = source.MonotableName
}
sink, err := th.QuerySQL(src, "SELECT * FROM "+tblName)
require.NoError(t, err)
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
require.Equal(t, len(tc.fieldTypes), len(sink.Recs[0]))
for i := range sink.Recs[0] {
require.Equal(t, tc.fieldTypes[i], reflect.TypeOf(sink.Recs[0][i]),
"expected field[%d] to have type %s but got %s", i, tc.fieldTypes[i], reflect.TypeOf(sink.Recs[0][i]))
}
})
}
}
func TestQuerySQL_Count(t *testing.T) {
testCases := sakila.SQLAll
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 "+sakila.TblActor)
require.NoError(t, err)
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
sink, err = th.QuerySQL(src, "SELECT COUNT(*) FROM "+sakila.TblActor)
require.NoError(t, err)
count, ok := sink.Recs[0][0].(*int64)
require.True(t, ok)
require.Equal(t, int64(sakila.TblActorCount), *count)
})
}
}