sq/libsq/query_unique_test.go

46 lines
1.1 KiB
Go
Raw Normal View History

package libsq_test
2023-04-01 11:38:32 +03:00
import (
"testing"
"github.com/neilotoole/sq/testh/sakila"
"github.com/neilotoole/sq/drivers/mysql"
_ "github.com/mattn/go-sqlite3"
)
//nolint:exhaustive
func TestQuery_unique(t *testing.T) {
testCases := []queryTestCase{
{
name: "unique/single-col",
in: `@sakila | .actor | .first_name | unique`,
wantSQL: `SELECT DISTINCT "first_name" FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT `first_name` FROM `actor`"},
wantRecCount: 128,
2023-04-01 11:38:32 +03:00
},
{
name: "unique/no-col",
in: `@sakila | .actor | unique`,
wantSQL: `SELECT DISTINCT * FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
wantRecCount: sakila.TblActorCount,
2023-04-01 11:38:32 +03:00
},
{
name: "unique/no-col",
in: `@sakila | .actor | unique`,
wantSQL: `SELECT DISTINCT * FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
wantRecCount: sakila.TblActorCount,
2023-04-01 11:38:32 +03:00
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
execQueryTestCase(t, tc)
})
}
}