accessor test stub

This commit is contained in:
Thomas Rudin 2019-01-08 16:33:49 +01:00
parent 34bf2c5df9
commit 98350f48f9
3 changed files with 42 additions and 5 deletions

View File

@ -7,7 +7,6 @@ type Block struct {
}
type DBAccessor interface {
IsMigrated() (bool, error)
Migrate() error
FindLatestBlocks(mintime int64, limit int) ([]Block, error)
FindBlocks(posx int, posz int, posystart int, posyend int) ([]Block, error)

View File

@ -5,14 +5,13 @@ import (
_ "github.com/mattn/go-sqlite3"
)
const migrateScript = `
`
type Sqlite3Accessor struct {
db *sql.DB
}
func (db *Sqlite3Accessor) IsMigrated() (bool, error) {
return false, nil
}
func (db *Sqlite3Accessor) Migrate() error {
return nil
}

39
db/sqlite_test.go Normal file
View File

@ -0,0 +1,39 @@
package db
import (
"fmt"
"testing"
"io/ioutil"
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
const emptyBlocksScript = `
create table blocks (
pos int,
data blob
);
`
func createEmptyDatabase(filename string){
db, err := sql.Open("sqlite3", filename)
if err != nil {
panic(err)
}
rows, err := db.Query(emptyBlocksScript)
if err != nil {
panic(err)
}
rows.Next()
fmt.Println(rows)
db.Close()
}
func TestMigrate(t *testing.T){
tmpfile, err := ioutil.TempFile("", "example")
if err != nil {
panic(err)
}
createEmptyDatabase(tmpfile.Name())
}