mirror of
https://github.com/neilotoole/sq.git
synced 2024-11-24 11:54:37 +03:00
Switched pkg sakila "const" slices to functions (#57)
* replaced sakila source slices with funcs * missed some pkg sakila slices to refactor
This commit is contained in:
parent
8b1bd4c03a
commit
3e10868a29
@ -34,7 +34,7 @@ func TestCmdInspect(t *testing.T) {
|
||||
require.Equal(t, sqlite3.Type, md.SourceType)
|
||||
require.Equal(t, sakila.SL3, md.Handle)
|
||||
require.Equal(t, src.Location, md.Location)
|
||||
require.Equal(t, sakila.AllTbls, md.TableNames())
|
||||
require.Equal(t, sakila.AllTbls(), md.TableNames())
|
||||
|
||||
// Try one more source for good measure
|
||||
ru = newRun(t)
|
||||
|
@ -50,7 +50,7 @@ func TestCmdSLQ_Insert(t *testing.T) {
|
||||
}
|
||||
|
||||
insertTo := fmt.Sprintf("%s.%s", destSrc.Handle, actualDestTbl)
|
||||
cols := stringz.PrefixSlice(sakila.TblActorCols, ".")
|
||||
cols := stringz.PrefixSlice(sakila.TblActorCols(), ".")
|
||||
query := fmt.Sprintf("%s.%s | %s", originSrc.Handle, srcTbl, strings.Join(cols, ", "))
|
||||
|
||||
err := ru.exec("slq", "--insert="+insertTo, query)
|
||||
|
@ -49,7 +49,7 @@ func TestCmdSQL_Insert(t *testing.T) {
|
||||
}
|
||||
|
||||
insertTo := fmt.Sprintf("%s.%s", destSrc.Handle, actualDestTbl)
|
||||
query := fmt.Sprintf("SELECT %s FROM %s", strings.Join(sakila.TblActorCols, ", "), originTbl)
|
||||
query := fmt.Sprintf("SELECT %s FROM %s", strings.Join(sakila.TblActorCols(), ", "), originTbl)
|
||||
|
||||
err := ru.exec("sql", "--insert="+insertTo, query)
|
||||
require.NoError(t, err)
|
||||
|
@ -31,13 +31,13 @@ func TestRecordWriterAdapter(t *testing.T) {
|
||||
handle: sakila.SL3,
|
||||
sqlQuery: "SELECT * FROM actor",
|
||||
wantRowCount: sakila.TblActorCount,
|
||||
wantColCount: len(sakila.TblActorCols),
|
||||
wantColCount: len(sakila.TblActorCols()),
|
||||
},
|
||||
{
|
||||
handle: testsrc.CSVPersonBig,
|
||||
sqlQuery: "SELECT * FROM data",
|
||||
wantRowCount: 10000,
|
||||
wantColCount: len(sakila.TblActorCols),
|
||||
wantColCount: len(sakila.TblActorCols()),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ func TestSmoke(t *testing.T) {
|
||||
|
||||
sink, err := th.QuerySQL(src, "SELECT * FROM data")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(sakila.TblActorCols), len(sink.RecMeta))
|
||||
require.Equal(t, len(sakila.TblActorCols()), len(sink.RecMeta))
|
||||
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
|
||||
})
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func TestSmoke(t *testing.T) {
|
||||
th, src, _, _ := testh.NewWith(t, handle)
|
||||
sink, err := th.QuerySQL(src, "SELECT * FROM actor")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(sakila.TblActorCols), len(sink.RecMeta))
|
||||
require.Equal(t, len(sakila.TblActorCols()), len(sink.RecMeta))
|
||||
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
|
||||
})
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func TestSmoke(t *testing.T) {
|
||||
th, src, _, _ := testh.NewWith(t, handle)
|
||||
sink, err := th.QuerySQL(src, "SELECT * FROM actor")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(sakila.TblActorCols), len(sink.RecMeta))
|
||||
require.Equal(t, len(sakila.TblActorCols()), len(sink.RecMeta))
|
||||
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
|
||||
})
|
||||
}
|
||||
@ -135,7 +135,7 @@ func TestGetTableColumnNames(t *testing.T) {
|
||||
|
||||
colNames, err := postgres.GetTableColumnNames(th.Context, th.Log, th.Open(src).DB(), sakila.TblActor)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sakila.TblActorCols, colNames)
|
||||
require.Equal(t, sakila.TblActorCols(), colNames)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func TestRecordMetadata(t *testing.T) {
|
||||
{
|
||||
tbl: sakila.TblActor,
|
||||
rowCount: sakila.TblActorCount,
|
||||
colNames: sakila.TblActorCols,
|
||||
colNames: sakila.TblActorCols(),
|
||||
colKinds: []sqlz.Kind{sqlz.KindInt, sqlz.KindText, sqlz.KindText, sqlz.KindDatetime},
|
||||
scanTypes: []reflect.Type{sqlz.RTypeNullInt64, sqlz.RTypeNullString, sqlz.RTypeNullString, sqlz.RTypeNullTime},
|
||||
colsMeta: []*source.ColMetadata{
|
||||
@ -86,7 +86,7 @@ func TestRecordMetadata(t *testing.T) {
|
||||
{
|
||||
tbl: sakila.TblFilmActor,
|
||||
rowCount: sakila.TblFilmActorCount,
|
||||
colNames: sakila.TblFilmActorCols,
|
||||
colNames: sakila.TblFilmActorCols(),
|
||||
colKinds: []sqlz.Kind{sqlz.KindInt, sqlz.KindInt, sqlz.KindDatetime},
|
||||
scanTypes: []reflect.Type{sqlz.RTypeNullInt64, sqlz.RTypeNullInt64, sqlz.RTypeNullTime},
|
||||
colsMeta: []*source.ColMetadata{
|
||||
@ -98,7 +98,7 @@ func TestRecordMetadata(t *testing.T) {
|
||||
{
|
||||
tbl: sakila.TblPayment,
|
||||
rowCount: sakila.TblPaymentCount,
|
||||
colNames: sakila.TblPaymentCols,
|
||||
colNames: sakila.TblPaymentCols(),
|
||||
colKinds: []sqlz.Kind{sqlz.KindInt, sqlz.KindInt, sqlz.KindInt, sqlz.KindInt, sqlz.KindDecimal, sqlz.KindDatetime, sqlz.KindDatetime},
|
||||
scanTypes: []reflect.Type{sqlz.RTypeNullInt64, sqlz.RTypeNullInt64, sqlz.RTypeNullInt64, sqlz.RTypeNullInt64, sqlz.RTypeNullString, sqlz.RTypeNullTime, sqlz.RTypeNullTime},
|
||||
colsMeta: []*source.ColMetadata{
|
||||
|
@ -27,7 +27,7 @@ func TestSmoke(t *testing.T) {
|
||||
th, src, _, _ := testh.NewWith(t, handle)
|
||||
sink, err := th.QuerySQL(src, "SELECT * FROM actor")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(sakila.TblActorCols), len(sink.RecMeta))
|
||||
require.Equal(t, len(sakila.TblActorCols()), len(sink.RecMeta))
|
||||
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
|
||||
})
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ func Test_Smoke_Subset(t *testing.T) {
|
||||
|
||||
sink, err := th.QuerySQL(src, "SELECT * FROM actor")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(sakila.TblActorCols), len(sink.RecMeta))
|
||||
require.Equal(t, len(sakila.TblActorCols()), len(sink.RecMeta))
|
||||
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ func Test_Smoke_Full(t *testing.T) {
|
||||
|
||||
sink, err := th.QuerySQL(src, "SELECT * FROM actor")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(sakila.TblActorCols), len(sink.RecMeta))
|
||||
require.Equal(t, len(sakila.TblActorCols()), len(sink.RecMeta))
|
||||
require.Equal(t, sakila.TblActorCount, len(sink.Recs))
|
||||
}
|
||||
|
||||
|
@ -148,13 +148,13 @@ func TestDriver_TableColumnTypes(t *testing.T) {
|
||||
// as if the query was (SELECT * FROM actualTblName)
|
||||
colTypes, err := drvr.TableColumnTypes(th.Context, db, actualTblName, nil)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(sakila.TblActorCols), len(colTypes))
|
||||
require.Equal(t, len(sakila.TblActorCols()), len(colTypes))
|
||||
for i := range colTypes {
|
||||
require.Equal(t, sakila.TblActorCols[i], colTypes[i].Name())
|
||||
require.Equal(t, sakila.TblActorCols()[i], colTypes[i].Name())
|
||||
}
|
||||
|
||||
// Try again, but requesting specific col names
|
||||
wantColNames := []string{sakila.TblActorCols[0], sakila.TblActorCols[2]}
|
||||
wantColNames := []string{sakila.TblActorCols()[0], sakila.TblActorCols()[2]}
|
||||
colTypes, err = drvr.TableColumnTypes(th.Context, db, actualTblName, wantColNames)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(wantColNames), len(colTypes))
|
||||
|
@ -87,18 +87,38 @@ const (
|
||||
)
|
||||
|
||||
// Facts regarding the sakila database.
|
||||
var (
|
||||
TblActorCols = []string{"actor_id", "first_name", "last_name", "last_update"}
|
||||
TblActorColKinds = []sqlz.Kind{sqlz.KindInt, sqlz.KindText, sqlz.KindText, sqlz.KindDatetime}
|
||||
TblFilmActorCols = []string{"actor_id", "film_id", "last_update"}
|
||||
TblPaymentCols = []string{"payment_id", "customer_id", "staff_id", "rental_id", "amount", "payment_date", "last_update"}
|
||||
AllTbls = []string{"actor", "address", "category", "city", "country", "customer", "film", "film_actor", "film_category", "film_text", "inventory", "language", "payment", "rental", "staff", "store"}
|
||||
|
||||
// AllTblsExceptFilmText exists because our current postgres image is different
|
||||
// from the others in that it doesn't have the film_text table.
|
||||
// FIXME: delete AllTblsExceptFilmText when postgres image is updated to include film_text.
|
||||
AllTblsExceptFilmText = []string{"actor", "address", "category", "city", "country", "customer", "film", "film_actor", "film_category", "inventory", "language", "payment", "rental", "staff", "store"}
|
||||
)
|
||||
// TblActorCols returns table "actor" column names.
|
||||
func TblActorCols() []string {
|
||||
return []string{"actor_id", "first_name", "last_name", "last_update"}
|
||||
}
|
||||
|
||||
// TblActorColKinds returns the kinds of the columns from table actor.
|
||||
func TblActorColKinds() []sqlz.Kind {
|
||||
return []sqlz.Kind{sqlz.KindInt, sqlz.KindText, sqlz.KindText, sqlz.KindDatetime}
|
||||
}
|
||||
|
||||
// TblFilmActorCols returns table "film" column names.
|
||||
func TblFilmActorCols() []string {
|
||||
return []string{"actor_id", "film_id", "last_update"}
|
||||
}
|
||||
|
||||
// TblPaymentCols returns table "payment" column names.
|
||||
func TblPaymentCols() []string {
|
||||
return []string{"payment_id", "customer_id", "staff_id", "rental_id", "amount", "payment_date", "last_update"}
|
||||
}
|
||||
|
||||
// AllTbls returns all table names.
|
||||
func AllTbls() []string {
|
||||
return []string{"actor", "address", "category", "city", "country", "customer", "film", "film_actor", "film_category", "film_text", "inventory", "language", "payment", "rental", "staff", "store"}
|
||||
}
|
||||
|
||||
// AllTblsExceptFilmText exists because our current postgres image is different
|
||||
// from the others in that it doesn't have the film_text table.
|
||||
func AllTblsExceptFilmText() []string {
|
||||
// TODO: delete AllTblsExceptFilmText when postgres image is updated to include film_text.
|
||||
return []string{"actor", "address", "category", "city", "country", "customer", "film", "film_actor", "film_category", "inventory", "language", "payment", "rental", "staff", "store"}
|
||||
}
|
||||
|
||||
// URLs for sakila resources.
|
||||
const (
|
||||
|
@ -115,7 +115,7 @@ func TestCopyRecords(t *testing.T) {
|
||||
|
||||
func TestRecordsFromTbl(t *testing.T) {
|
||||
recMeta1, recs1 := testh.RecordsFromTbl(t, sakila.SL3, sakila.TblActor)
|
||||
require.Equal(t, sakila.TblActorColKinds, recMeta1.Kinds())
|
||||
require.Equal(t, sakila.TblActorColKinds(), recMeta1.Kinds())
|
||||
|
||||
recs1[0][0] = t.Name()
|
||||
|
||||
@ -149,7 +149,7 @@ func TestHelper_Files(t *testing.T) {
|
||||
r, err := fs.NewReader(gctx, src)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer func() {require.NoError(t, r.Close())}()
|
||||
defer func() { require.NoError(t, r.Close()) }()
|
||||
|
||||
b, err := ioutil.ReadAll(r)
|
||||
require.NoError(t, err)
|
||||
|
Loading…
Reference in New Issue
Block a user