67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
|
package client
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http/httptest"
|
||
|
"os"
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
|
"github.com/keegancsmith/rpc"
|
||
|
|
||
|
"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 TestBlobStore(t *testing.T) {
|
||
|
t.Parallel()
|
||
|
logger.SetLevel(logger.LevelDebug)
|
||
|
|
||
|
httpServer := startNewServer(t)
|
||
|
defer httpServer.Close()
|
||
|
|
||
|
serverAddr := httpServer.Listener.Addr()
|
||
|
|
||
|
client, err := rpc.DialHTTPPath(
|
||
|
serverAddr.Network(),
|
||
|
serverAddr.String(),
|
||
|
"",
|
||
|
)
|
||
|
if err != nil {
|
||
|
t.Fatalf("%+v", errors.WithStack(err))
|
||
|
}
|
||
|
defer client.Close()
|
||
|
|
||
|
store := NewBlobStore(client)
|
||
|
|
||
|
testsuite.TestBlobStore(t, store)
|
||
|
}
|
||
|
|
||
|
func getSQLiteBlobstore(t *testing.T) *sqlite.BlobStore {
|
||
|
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 := sqlite.NewBlobStore(dsn)
|
||
|
|
||
|
return store
|
||
|
}
|
||
|
|
||
|
func startNewServer(t *testing.T) *httptest.Server {
|
||
|
store := getSQLiteBlobstore(t)
|
||
|
server := server.NewBlobStoreServer(store)
|
||
|
|
||
|
httpServer := httptest.NewServer(server)
|
||
|
httpServerAddr := httpServer.Listener.Addr().String()
|
||
|
|
||
|
t.Logf("Test HTTP RPC server listening on %s", httpServerAddr)
|
||
|
|
||
|
return httpServer
|
||
|
}
|