Finish minimal feature set, start with tests

This commit is contained in:
Daniel 2018-09-10 19:01:28 +02:00
parent 3d60431376
commit 06a34f931e
34 changed files with 651 additions and 346 deletions

69
database/database_test.go Normal file
View file

@ -0,0 +1,69 @@
package database
import (
"io/ioutil"
"os"
"sync"
"testing"
"github.com/Safing/portbase/database/record"
)
type TestRecord struct {
record.Base
lock sync.Mutex
S string
I int
I8 int8
I16 int16
I32 int32
I64 int64
UI uint
UI8 uint8
UI16 uint16
UI32 uint32
UI64 uint64
F32 float32
F64 float64
B bool
}
func (tr *TestRecord) Lock() {
}
func (tr *TestRecord) Unlock() {
}
func TestDatabase(t *testing.T) {
testDir, err := ioutil.TempDir("", "testing-")
if err != nil {
t.Fatal(err)
}
err = Initialize(testDir)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(testDir) // clean up
err = RegisterDatabase(&RegisteredDatabase{
Name: "testing",
Description: "Unit Test Database",
StorageType: "badger",
PrimaryAPI: "",
})
if err != nil {
t.Fatal(err)
}
db := NewInterface(nil)
new := &TestRecord{}
new.SetKey("testing:A")
err = db.Put(new)
if err != nil {
t.Fatal(err)
}
}