sq/libsq/engine_test.go
Neil O'Toole c778c8ced5
Linting of _test.go files (#121)
* test linting

* test linting

* test linting

* test linting
2022-12-18 00:18:35 -07:00

49 lines
1.1 KiB
Go

package libsq_test
import (
"testing"
"github.com/neilotoole/sq/testh/tutil"
"github.com/stretchr/testify/require"
"github.com/neilotoole/sq/libsq"
"github.com/neilotoole/sq/testh"
"github.com/neilotoole/sq/testh/sakila"
)
func TestSLQ2SQL(t *testing.T) {
testCases := []struct {
handles []string
slq string
wantSQL string
wantErr bool
}{
// Obviously we could use about 1,000 additional test cases.
{
handles: []string{sakila.SL3},
slq: `@sakila_sl3 | .actor, .film_actor | join(.film_actor.actor_id == .actor.actor_id)`,
wantSQL: `SELECT * FROM "actor" INNER JOIN "film_actor" ON "film_actor"."actor_id" = "actor"."actor_id"`,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tutil.Name(tc.slq), func(t *testing.T) {
th := testh.New(t)
srcs := th.NewSourceSet(tc.handles...)
gotSQL, gotErr := libsq.EngineSLQ2SQL(th.Context, th.Log, th.Databases(), th.Databases(), srcs, tc.slq)
if tc.wantErr {
require.Error(t, gotErr)
return
}
require.NoError(t, gotErr)
require.Equal(t, tc.wantSQL, gotSQL)
})
}
}