Skip to content
Permalink
Browse files

storagetest factory now takes domainID (#1353)

* storagetest factory now takes domainID

* nit

* Increase timeout
  • Loading branch information...
gdbelvin committed Sep 11, 2019
1 parent 3a6f4dc commit 8df8fd20203eed2d76952e1797773a22fdc42da8
Showing with 16 additions and 11 deletions.
  1. +14 −10 core/integration/storagetest/batch.go
  2. +1 −1 impl/sql/mutationstorage/mutations_test.go
  3. +1 −0 scripts/integration.sh
@@ -16,12 +16,12 @@ import (
// Batcher writes batch definitions to storage.
type Batcher = sequencer.Batcher

type BatchStorageFactory func(ctx context.Context, t *testing.T) Batcher
type BatchStorageFactory func(ctx context.Context, t *testing.T, dirID string) Batcher

type BatchStorageTest func(ctx context.Context, t *testing.T, b Batcher)
type BatchStorageTest func(ctx context.Context, t *testing.T, f BatchStorageFactory)

// RunBatchStorageTests runs all the batch storage tests against the provided map storage implementation.
func RunBatchStorageTests(t *testing.T, storageFactory BatchStorageFactory) {
func RunBatchStorageTests(t *testing.T, factory BatchStorageFactory) {
ctx := context.Background()
b := &BatchTests{}
for name, f := range map[string]BatchStorageTest{
@@ -31,24 +31,26 @@ func RunBatchStorageTests(t *testing.T, storageFactory BatchStorageFactory) {
"TestReadBatch": b.TestReadBatch,
"TestHighestRev": b.TestHighestRev,
} {
ms := storageFactory(ctx, t)
t.Run(name, func(t *testing.T) { f(ctx, t, ms) })
t.Run(name, func(t *testing.T) { f(ctx, t, factory) })
}
}

// BatchTests is a suite of tests to run against
type BatchTests struct{}

func (*BatchTests) TestNotFound(ctx context.Context, t *testing.T, b Batcher) {
_, err := b.ReadBatch(ctx, "nodir", 0)
func (*BatchTests) TestNotFound(ctx context.Context, t *testing.T, f BatchStorageFactory) {
domainID := "testnotfounddir"
b := f(ctx, t, domainID)
_, err := b.ReadBatch(ctx, domainID, 0)
st := status.Convert(err)
if got, want := st.Code(), codes.NotFound; got != want {
t.Errorf("ReadBatch(): %v, want %v", err, want)
}
}

func (*BatchTests) TestWriteBatch(ctx context.Context, t *testing.T, b Batcher) {
func (*BatchTests) TestWriteBatch(ctx context.Context, t *testing.T, f BatchStorageFactory) {
domainID := "writebatchtest"
b := f(ctx, t, domainID)
for _, tc := range []struct {
rev int64
wantErr bool
@@ -70,8 +72,9 @@ func (*BatchTests) TestWriteBatch(ctx context.Context, t *testing.T, b Batcher)
}
}

func (*BatchTests) TestReadBatch(ctx context.Context, t *testing.T, b Batcher) {
func (*BatchTests) TestReadBatch(ctx context.Context, t *testing.T, f BatchStorageFactory) {
domainID := "readbatchtest"
b := f(ctx, t, domainID)
for _, tc := range []struct {
rev int64
want *spb.MapMetadata
@@ -98,8 +101,9 @@ func (*BatchTests) TestReadBatch(ctx context.Context, t *testing.T, b Batcher) {
}
}

func (*BatchTests) TestHighestRev(ctx context.Context, t *testing.T, b Batcher) {
func (*BatchTests) TestHighestRev(ctx context.Context, t *testing.T, f BatchStorageFactory) {
domainID := "writebatchtest"
b := f(ctx, t, domainID)
for _, tc := range []struct {
rev int64
sources []*spb.MapMetadata_SourceSlice
@@ -32,7 +32,7 @@ func newDB(t testing.TB) *sql.DB {
}

func TestBatchIntegration(t *testing.T) {
storageFactory := func(context.Context, *testing.T) storagetest.Batcher {
storageFactory := func(context.Context, *testing.T, string) storagetest.Batcher {
m, err := New(newDB(t))
if err != nil {
t.Fatalf("Failed to create mutations: %v", err)
@@ -23,4 +23,5 @@ go run ./cmd/keytransparency-client post foo@bar.com \
--password=${PASSWORD} \
--kt-url=localhost:443 \
--verbose \
--timeout=2m \
--logtostderr

0 comments on commit 8df8fd2

Please sign in to comment.
You can’t perform that action at this time.