accessor test stub
This commit is contained in:
parent
34bf2c5df9
commit
98350f48f9
@ -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)
|
||||
|
@ -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
39
db/sqlite_test.go
Normal 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())
|
||||
}
|
Loading…
Reference in New Issue
Block a user