sq/libsq/query_args_test.go
Neil O'Toole 2ba633fc2a
#258: Alias can be an arbitrary string. (#259)
* Fixed space issues with expressions

* Alias can now be an arbitrary string

* Alias can now be an arbitrary string (fixed)

* Alias now automatically applied to expressions

* Ignore .run

* Fixed issue with TestRun not logging correctly to testing.T

* Fiddling with sqlite3 temp file closing

* Re-enable tests
2023-06-18 00:05:09 -06:00

48 lines
1.5 KiB
Go

package libsq_test
import (
"testing"
"github.com/neilotoole/sq/drivers/mysql"
_ "github.com/mattn/go-sqlite3"
)
//nolint:exhaustive
func TestQuery_args(t *testing.T) {
testCases := []queryTestCase{
{
name: "arg_value_string",
in: `@sakila | .actor | where(.first_name == $first)`,
args: map[string]string{"first": "TOM"},
wantSQL: `SELECT * FROM "actor" WHERE "first_name" = 'TOM'`,
override: driverMap{mysql.Type: "SELECT * FROM `actor` WHERE `first_name` = 'TOM'"},
wantRecCount: 2,
},
{
name: "arg_value_string_2",
in: `@sakila | .actor | where(.first_name == $first && .last_name == $last)`,
args: map[string]string{"first": "TOM", "last": "MIRANDA"},
wantSQL: `SELECT * FROM "actor" WHERE "first_name" = 'TOM' AND "last_name" = 'MIRANDA'`,
override: driverMap{mysql.Type: "SELECT * FROM `actor` WHERE `first_name` = 'TOM' AND `last_name` = 'MIRANDA'"},
wantRecCount: 1,
},
{
name: "arg_value_int",
in: `@sakila | .actor | where(.actor_id == int($id))`,
args: map[string]string{"id": "1"},
wantSQL: `SELECT * FROM "actor" WHERE "actor_id" = 1`,
override: driverMap{mysql.Type: "SELECT * FROM `actor` WHERE `actor_id` = 1"},
skip: true, // Skip until we implement casting, e.g. .actor_id == int($id)
wantRecCount: 1,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
execQueryTestCase(t, tc)
})
}
}