mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
|
10 years ago
|
package sql
|
||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestTranslate(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
testCase string
|
||
|
|
flavor flavor
|
||
|
|
query string
|
||
|
|
exp string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
"sqlite3 query bind replacement",
|
||
|
|
flavorSQLite3,
|
||
|
|
`select foo from bar where foo.zam = $1;`,
|
||
|
|
`select foo from bar where foo.zam = ?;`,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"sqlite3 query bind replacement at newline",
|
||
|
|
flavorSQLite3,
|
||
|
|
`select foo from bar where foo.zam = $1`,
|
||
|
|
`select foo from bar where foo.zam = ?`,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"sqlite3 query true",
|
||
|
|
flavorSQLite3,
|
||
|
|
`select foo from bar where foo.zam = true`,
|
||
|
|
`select foo from bar where foo.zam = 1`,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"sqlite3 query false",
|
||
|
|
flavorSQLite3,
|
||
|
|
`select foo from bar where foo.zam = false`,
|
||
|
|
`select foo from bar where foo.zam = 0`,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"sqlite3 bytea",
|
||
|
|
flavorSQLite3,
|
||
|
|
`"connector_data" bytea not null,`,
|
||
|
|
`"connector_data" blob not null,`,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"sqlite3 now",
|
||
|
|
flavorSQLite3,
|
||
|
|
`now(),`,
|
||
|
|
`date('now'),`,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tc := range tests {
|
||
|
|
if got := tc.flavor.translate(tc.query); got != tc.exp {
|
||
|
|
t.Errorf("%s: want=%q, got=%q", tc.testCase, tc.exp, got)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|