2021-12-25 02:16:58 +01:00
|
|
|
package store
|
2021-12-19 23:24:43 +01:00
|
|
|
|
|
|
|
import (
|
2022-06-27 17:28:39 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2021-12-19 23:24:43 +01:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2022-06-27 17:28:39 +02:00
|
|
|
func StoreTestInit(t *testing.T) (s Store, tmpFile *os.File) {
|
|
|
|
s = Store{}
|
2021-12-19 23:24:43 +01:00
|
|
|
|
2022-06-27 17:28:39 +02:00
|
|
|
tmpFile, err := ioutil.TempFile(os.TempDir(), "sqlite-test-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("DB setup failure: %+v", err)
|
|
|
|
return
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
2022-06-27 17:28:39 +02:00
|
|
|
s.Init(tmpFile.Name())
|
2022-06-07 19:25:14 +02:00
|
|
|
|
2022-06-27 17:28:39 +02:00
|
|
|
err = s.Migrate()
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
2022-06-27 17:28:39 +02:00
|
|
|
t.Fatalf("DB setup failure: %+v", err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
2022-06-27 17:28:39 +02:00
|
|
|
return
|
|
|
|
}
|
2021-12-19 23:24:43 +01:00
|
|
|
|
2022-06-27 17:28:39 +02:00
|
|
|
func StoreTestCleanup(tmpFile *os.File) {
|
|
|
|
if tmpFile != nil {
|
|
|
|
os.Remove(tmpFile.Name())
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
}
|