34 lines
823 B
Go
34 lines
823 B
Go
|
package sqlite
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
|
"forge.cadoles.com/arcad/edge/pkg/module/share"
|
||
|
"forge.cadoles.com/arcad/edge/pkg/module/share/testsuite"
|
||
|
"github.com/pkg/errors"
|
||
|
"gitlab.com/wpetit/goweb/logger"
|
||
|
)
|
||
|
|
||
|
func TestRepository(t *testing.T) {
|
||
|
logger.SetLevel(logger.LevelDebug)
|
||
|
testsuite.TestRepository(t, newTestRepo)
|
||
|
}
|
||
|
|
||
|
func newTestRepo(testName string) (share.Repository, error) {
|
||
|
filename := strings.ToLower(strings.ReplaceAll(testName, " ", "_"))
|
||
|
file := fmt.Sprintf("./testdata/%s.sqlite", filename)
|
||
|
|
||
|
if err := os.Remove(file); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||
|
return nil, errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
dsn := fmt.Sprintf("%s?_pragma=foreign_keys(1)&_pragma=busy_timeout=%d", file, (60 * time.Second).Milliseconds())
|
||
|
repo := NewRepository(dsn)
|
||
|
|
||
|
return repo, nil
|
||
|
}
|