Skip to content
Snippets Groups Projects
Commit c86d9387 authored by Christian Pointner's avatar Christian Pointner
Browse files

fix store tests

parent 9d04b23e
No related branches found
No related tags found
No related merge requests found
......@@ -39,9 +39,12 @@ var (
testBasePath = "run/aura-tank_testing"
testPublicDirPath = filepath.Join(testBasePath, publicGroupName)
testDBType = "mysql"
testDBConnection = "tank:aura@tcp(127.0.0.1:3306)/tank?charset=utf8&parseTime=True&loc=Local"
// testDBType = "postgres"
// testDBConnection = "host=127.0.0.1 port=5432 user=tank dbname=tank password=aura sslmode=disable"
testDBHost = "127.0.0.1"
testDBPort = uint16(0)
testDBUsername = "tank"
testDBPassword = "aura"
testDBDB = "tank"
testGroup1 = "test1"
testGroup2 = "test2"
testUser1 = "user1"
......@@ -56,11 +59,20 @@ var (
testFileTitle2 = "this is not two title's"
)
func testDBConfig() (cfg DBConfig) {
cfg.Type = testDBType
cfg.Host = testDBHost
cfg.Port = testDBPort
cfg.Username = testDBUsername
cfg.Password = testDBPassword
cfg.DB = testDBDB
return
}
func newTestStore(t *testing.T) *Store {
cfg := Config{}
cfg.BasePath = testBasePath
cfg.DB.Type = testDBType
cfg.DB.Connection = testDBConnection
cfg.DB = testDBConfig()
// TODO: drop database (all tables and constrains)
......@@ -79,7 +91,6 @@ func TestMain(m *testing.M) {
testBasePath = fmt.Sprintf("/run/user/%s/aura-tank_testing", u.Uid)
os.RemoveAll(testBasePath)
testPublicDirPath = filepath.Join(testBasePath, publicGroupName)
// testDBConnection = filepath.Join(testBasePath, ".db.sqlite")
os.Exit(m.Run())
}
......@@ -91,8 +102,7 @@ func TestOpen(t *testing.T) {
// base-path is non-existing directory
cfg := Config{}
cfg.BasePath = "/nonexistend/"
cfg.DB.Type = testDBType
cfg.DB.Connection = testDBConnection
cfg.DB = testDBConfig()
if _, err := NewStore(cfg); err == nil {
t.Fatalf("opening store in nonexisting directory should throw an error")
}
......@@ -101,19 +111,6 @@ func TestOpen(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
/// exisiting but non-database file (only possible with sqlite...)
// if f, err := os.Create(testDBConnection); err != nil {
// t.Fatalf("unexpected error: %v", err)
// } else {
// io.WriteString(f, "this is not a sqlite db.")
// f.Close()
// }
// if _, err := NewStore(cfg); err == nil {
// t.Fatalf("opening store using a invalid database should throw an error")
// }
/// create new db and reopen it
// os.Remove(testDBConnection)
store, err := NewStore(cfg)
if err != nil {
t.Fatalf("creating new store failed: %v", err)
......@@ -145,8 +142,7 @@ func TestOpen(t *testing.T) {
func TestMigrations(t *testing.T) {
cfg := Config{}
cfg.BasePath = testBasePath
cfg.DB.Type = testDBType
cfg.DB.Connection = testDBConnection
cfg.DB = testDBConfig()
// os.Remove(testDBConnection)
store, err := NewStore(cfg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment