From 98350f48f999f69495e0b07c812cce8c5b7ae971 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Tue, 8 Jan 2019 16:33:49 +0100 Subject: [PATCH] accessor test stub --- db/accessor.go | 1 - db/sqlite.go | 7 +++---- db/sqlite_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 db/sqlite_test.go diff --git a/db/accessor.go b/db/accessor.go index 50e8f08..cef75b8 100644 --- a/db/accessor.go +++ b/db/accessor.go @@ -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) diff --git a/db/sqlite.go b/db/sqlite.go index 9c61c75..4c5cef6 100644 --- a/db/sqlite.go +++ b/db/sqlite.go @@ -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 } diff --git a/db/sqlite_test.go b/db/sqlite_test.go new file mode 100644 index 0000000..a322499 --- /dev/null +++ b/db/sqlite_test.go @@ -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()) +}