package client import ( "context" "fmt" "net/http/httptest" "net/url" "os" "testing" "time" "forge.cadoles.com/arcad/edge/pkg/storage/rpc/server" "forge.cadoles.com/arcad/edge/pkg/storage/sqlite" "forge.cadoles.com/arcad/edge/pkg/storage/testsuite" "github.com/pkg/errors" "gitlab.com/wpetit/goweb/logger" ) func TestDocumentStore(t *testing.T) { t.Parallel() if testing.Verbose() { logger.SetLevel(logger.LevelDebug) } httpServer, err := startNewDocumentStoreServer() if err != nil { t.Fatalf("%+v", errors.WithStack(err)) } defer httpServer.Close() serverAddr := httpServer.Listener.Addr() serverURL := &url.URL{ Host: serverAddr.String(), } store := NewDocumentStore(serverURL) testsuite.TestDocumentStore(context.Background(), t, store) } func getSQLiteDocumentStore() (*sqlite.DocumentStore, error) { file := "./testdata/documentstore_test.sqlite" 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()) store := sqlite.NewDocumentStore(dsn) return store, nil } func startNewDocumentStoreServer() (*httptest.Server, error) { store, err := getSQLiteDocumentStore() if err != nil { return nil, errors.WithStack(err) } server := server.NewDocumentStoreServer(store) httpServer := httptest.NewServer(server) return httpServer, nil }