Пример #1
0
func (sqliteTester) test(t *testing.T, tfn func(*testing.T, func() *index.Index)) {
	once.Do(checkDB)
	f, err := ioutil.TempFile("", "sqlite-test")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(f.Name())
	makeIndex := func() *index.Index {
		db, err := sql.Open("sqlite3", f.Name())
		if err != nil {
			t.Fatalf("opening test database: %v", err)
			return nil
		}
		for _, tableSql := range sqlite.SQLCreateTables() {
			do(db, tableSql)
		}
		do(db, fmt.Sprintf(`REPLACE INTO meta VALUES ('version', '%d')`, sqlite.SchemaVersion()))
		s, err := sqlite.NewStorage(f.Name())
		if err != nil {
			panic(err)
		}
		return index.New(s)
	}
	tfn(t, makeIndex)
}
Пример #2
0
func makeStorage(t *testing.T) (s index.Storage, clean func()) {
	f, err := ioutil.TempFile("", "sqlite-test")
	if err != nil {
		t.Fatal(err)
	}
	clean = func() {
		os.Remove(f.Name())
	}
	db, err := sql.Open("sqlite3", f.Name())
	if err != nil {
		t.Fatalf("opening test database: %v", err)
	}
	for _, tableSql := range sqlite.SQLCreateTables() {
		do(db, tableSql)
	}
	do(db, fmt.Sprintf(`REPLACE INTO meta VALUES ('version', '%d')`, sqlite.SchemaVersion()))
	s, err = sqlite.NewStorage(f.Name())
	if err != nil {
		panic(err)
	}
	return s, clean
}