package database

import (
	"testing"

	"git.xeserv.us/xena/route/internal/routecrypto"
	"github.com/Xe/uuid"
	"golang.org/x/net/context"
)

func newTestBoltStorage(t *testing.T) (Storage, string, context.Context, context.CancelFunc) {
	k, err := routecrypto.ParseKey(cryptoKey)
	if err != nil {
		t.Fatal(err)
	}

	p := uuid.New()

	st, err := NewBoltStorage(p, k)
	if err != nil {
		t.Fatal(err)
	}

	ctx, cancel := context.WithCancel(context.Background())

	return st, p, ctx, cancel
}

func newTestPostgresStorage(t *testing.T, url string) (Storage, context.Context, context.CancelFunc) {
	k, err := routecrypto.ParseKey(cryptoKey)
	if err != nil {
		t.Fatal(err)
	}

	st, err := NewPostgresStorage(url, k)
	if err != nil {
		t.Fatal(err)
	}

	ctx, cancel := context.WithCancel(context.Background())

	return st, ctx, cancel
}
