2023-02-09 12:16:36 +01:00
|
|
|
package sqlite
|
|
|
|
|
|
|
|
import (
|
2023-09-13 06:03:25 +02:00
|
|
|
"context"
|
2023-04-06 14:45:50 +02:00
|
|
|
"fmt"
|
2023-02-09 12:16:36 +01:00
|
|
|
"os"
|
|
|
|
"testing"
|
2023-04-06 14:45:50 +02:00
|
|
|
"time"
|
2023-02-09 12:16:36 +01:00
|
|
|
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage/testsuite"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBlobStore(t *testing.T) {
|
|
|
|
t.Parallel()
|
2023-09-13 06:03:25 +02:00
|
|
|
if testing.Verbose() {
|
|
|
|
logger.SetLevel(logger.LevelDebug)
|
|
|
|
}
|
|
|
|
|
|
|
|
file := "./testdata/blobstore_test.sqlite"
|
|
|
|
|
|
|
|
if err := os.Remove(file); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
dsn := fmt.Sprintf("%s?_pragma=foreign_keys(1)&_pragma=busy_timeout=%d", file, (60 * time.Second).Milliseconds())
|
|
|
|
store := NewBlobStore(dsn)
|
|
|
|
|
|
|
|
testsuite.TestBlobStore(context.Background(), t, store)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkBlobStore(t *testing.B) {
|
|
|
|
logger.SetLevel(logger.LevelError)
|
2023-02-09 12:16:36 +01:00
|
|
|
|
|
|
|
file := "./testdata/blobstore_test.sqlite"
|
|
|
|
|
|
|
|
if err := os.Remove(file); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-04-06 14:45:50 +02:00
|
|
|
dsn := fmt.Sprintf("%s?_pragma=foreign_keys(1)&_pragma=busy_timeout=%d", file, (60 * time.Second).Milliseconds())
|
|
|
|
store := NewBlobStore(dsn)
|
2023-02-09 12:16:36 +01:00
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
testsuite.BenchmarkBlobStore(t, store)
|
2023-02-09 12:16:36 +01:00
|
|
|
}
|