rename package name + test factory

This commit is contained in:
nkanaev
2026-06-14 14:33:59 +01:00
parent a5b8e62ca7
commit 32cfc3bc1a
6 changed files with 20 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
package sqlite
package tests
import (
"reflect"

View File

@@ -1,4 +1,4 @@
package sqlite
package tests
import (
"testing"

View File

@@ -1,4 +1,4 @@
package sqlite
package tests
import (
"testing"

View File

@@ -1,4 +1,4 @@
package sqlite
package tests
import (
"database/sql"

View File

@@ -1,4 +1,4 @@
package sqlite
package tests
import (
"reflect"

View File

@@ -1,28 +1,26 @@
package sqlite
package tests
import (
"io"
"log"
"os"
"testing"
"github.com/nkanaev/yarr/src/storage"
)
func testDB() *SQLiteStorage {
log.SetOutput(io.Discard)
db, err := New(":memory:")
if err != nil {
panic(err)
func dbtest(t *testing.T, testcase func(t *testing.T, db storage.Storage)) {
testurls := map[string]string {
"sqlite": ":memory:",
"postgres": "postgres://postgres:postgres@localhost:5432/yarr_test",
}
log.SetOutput(os.Stderr)
return db
}
func TestStorage(t *testing.T) {
db, err := New(":memory:")
for testname, url := range testurls {
db, err := storage.New(url)
if err != nil {
t.Fatal(err)
t.Fatalf("failed to init storage for %s: %v", url, err)
}
if db == nil {
t.Fatal("no db")
t.Run(testname, func(t *testing.T) {
testcase(t, db)
})
}
}