2023-04-13 10:16:48 +02:00
|
|
|
package sqlite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage/share/testsuite"
|
2023-04-13 10:16:48 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepository(t *testing.T) {
|
|
|
|
logger.SetLevel(logger.LevelDebug)
|
2023-09-13 06:03:25 +02:00
|
|
|
testsuite.TestStore(t, newTestStore)
|
2023-04-13 10:16:48 +02:00
|
|
|
}
|
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
func newTestStore(testName string) (share.Store, error) {
|
2023-04-13 10:16:48 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-01-11 19:30:30 +01:00
|
|
|
dsn := fmt.Sprintf("%s?_pragma=foreign_keys(1)&_pragma=busy_timeout=%d&_pragma=journal_mode=wal", file, (60 * time.Second).Milliseconds())
|
2023-09-13 06:03:25 +02:00
|
|
|
store := NewShareStore(dsn)
|
2023-04-13 10:16:48 +02:00
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
return store, nil
|
2023-04-13 10:16:48 +02:00
|
|
|
}
|