mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* add DateTime sans mgo * change all uses of strfmt.DateTime to common.DateTime, remove test strfmt usage * remove api tests, system-test dep on api test multiple reasons to remove the api tests: * awkward dependency with fn_go meant generating bindings on a branched fn to vendor those to test new stuff. this is at a minimum not at all intuitive, worth it, nor a fun way to spend the finite amount of time we have to live. * api tests only tested a subset of functionality that the server/ api tests already test, and we risk having tests where one tests some thing and the other doesn't. let's not. we have too many test suites as it is, and these pretty much only test that we updated the fn_go bindings, which is actually a hassle as noted above and the cli will pretty quickly figure out anyway. * fn_go relies on openapi, which relies on mgo, which is deprecated and we'd like to remove as a dependency. openapi is a _huge_ dep built in a NIH fashion, that cannot simply remove the mgo dep as users may be using it. we've now stolen their date time and otherwise killed usage of it in fn core, for fn_go it still exists but that's less of a problem. * update deps removals: * easyjson * mgo * go-openapi * mapstructure * fn_go * purell * go-validator also, had to lock docker. we shouldn't use docker on master anyway, they strongly advise against that. had no luck with latest version rev, so i locked it to what we were using before. until next time. the rest is just playing dep roulette, those end up removing a ton tho * fix exec test to work * account for john le cache
131 lines
3.2 KiB
Go
131 lines
3.2 KiB
Go
// Copyright (C) 2015 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
|
//
|
|
// Use of this source code is governed by an MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package sqlite3
|
|
|
|
import (
|
|
"database/sql"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestFTS3(t *testing.T) {
|
|
tempFilename := TempFilename(t)
|
|
defer os.Remove(tempFilename)
|
|
db, err := sql.Open("sqlite3", tempFilename)
|
|
if err != nil {
|
|
t.Fatal("Failed to open database:", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
_, err = db.Exec("DROP TABLE foo")
|
|
_, err = db.Exec("CREATE VIRTUAL TABLE foo USING fts3(id INTEGER PRIMARY KEY, value TEXT)")
|
|
if err != nil {
|
|
t.Fatal("Failed to create table:", err)
|
|
}
|
|
|
|
_, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 1, `今日の 晩御飯は 天麩羅よ`)
|
|
if err != nil {
|
|
t.Fatal("Failed to insert value:", err)
|
|
}
|
|
|
|
_, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 2, `今日は いい 天気だ`)
|
|
if err != nil {
|
|
t.Fatal("Failed to insert value:", err)
|
|
}
|
|
|
|
rows, err := db.Query("SELECT id, value FROM foo WHERE value MATCH '今日* 天*'")
|
|
if err != nil {
|
|
t.Fatal("Unable to query foo table:", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var id int
|
|
var value string
|
|
|
|
if err := rows.Scan(&id, &value); err != nil {
|
|
t.Error("Unable to scan results:", err)
|
|
continue
|
|
}
|
|
|
|
if id == 1 && value != `今日の 晩御飯は 天麩羅よ` {
|
|
t.Error("Value for id 1 should be `今日の 晩御飯は 天麩羅よ`, but:", value)
|
|
} else if id == 2 && value != `今日は いい 天気だ` {
|
|
t.Error("Value for id 2 should be `今日は いい 天気だ`, but:", value)
|
|
}
|
|
}
|
|
|
|
rows, err = db.Query("SELECT value FROM foo WHERE value MATCH '今日* 天麩羅*'")
|
|
if err != nil {
|
|
t.Fatal("Unable to query foo table:", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var value string
|
|
if !rows.Next() {
|
|
t.Fatal("Result should be only one")
|
|
}
|
|
|
|
if err := rows.Scan(&value); err != nil {
|
|
t.Fatal("Unable to scan results:", err)
|
|
}
|
|
|
|
if value != `今日の 晩御飯は 天麩羅よ` {
|
|
t.Fatal("Value should be `今日の 晩御飯は 天麩羅よ`, but:", value)
|
|
}
|
|
|
|
if rows.Next() {
|
|
t.Fatal("Result should be only one")
|
|
}
|
|
}
|
|
|
|
func TestFTS4(t *testing.T) {
|
|
tempFilename := TempFilename(t)
|
|
defer os.Remove(tempFilename)
|
|
db, err := sql.Open("sqlite3", tempFilename)
|
|
if err != nil {
|
|
t.Fatal("Failed to open database:", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
_, err = db.Exec("DROP TABLE foo")
|
|
_, err = db.Exec("CREATE VIRTUAL TABLE foo USING fts4(tokenize=unicode61, id INTEGER PRIMARY KEY, value TEXT)")
|
|
switch {
|
|
case err != nil && err.Error() == "unknown tokenizer: unicode61":
|
|
t.Skip("FTS4 not supported")
|
|
case err != nil:
|
|
t.Fatal("Failed to create table:", err)
|
|
}
|
|
|
|
_, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 1, `février`)
|
|
if err != nil {
|
|
t.Fatal("Failed to insert value:", err)
|
|
}
|
|
|
|
rows, err := db.Query("SELECT value FROM foo WHERE value MATCH 'fevrier'")
|
|
if err != nil {
|
|
t.Fatal("Unable to query foo table:", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var value string
|
|
if !rows.Next() {
|
|
t.Fatal("Result should be only one")
|
|
}
|
|
|
|
if err := rows.Scan(&value); err != nil {
|
|
t.Fatal("Unable to scan results:", err)
|
|
}
|
|
|
|
if value != `février` {
|
|
t.Fatal("Value should be `février`, but:", value)
|
|
}
|
|
|
|
if rows.Next() {
|
|
t.Fatal("Result should be only one")
|
|
}
|
|
}
|