Skip to content

Commit

Permalink
test harness cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayan Samanta committed Mar 26, 2020
1 parent 70248b8 commit 0b8068c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
47 changes: 27 additions & 20 deletions dynamodb/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,35 @@ import (
"github.com/stretchr/testify/require"
)

func setupTestTable(t *testing.T, table string, s *session.Session) {
ddb := dynamodb.New(s)
db := &bucketDB{
ddb: ddb,
tableName: table,
func testRequiredEnv(t *testing.T, key string) string {
val, ok := os.LookupEnv(key)
if !ok {
t.Logf("required test env var %s not set", key)
t.FailNow()
}
deleteTable(db)
err := createTable(db)
require.NoError(t, err)

return val
}

func getLocalStorage(t *testing.T) *Storage {
testTable := "test-table"
session, err := session.NewSession(&aws.Config{
func testStorage(t *testing.T) *Storage {
table := "test-table"
s, err := session.NewSession(&aws.Config{
Region: aws.String("doesntmatter"),
Endpoint: aws.String(os.Getenv("AWS_DYNAMO_ENDPOINT")),
Endpoint: aws.String(testRequiredEnv(t, "AWS_DYNAMO_ENDPOINT")),
Credentials: credentials.NewStaticCredentials("id", "secret", "token"),
})
ddb := dynamodb.New(s)
db := bucketDB{
ddb: ddb,
tableName: table,
}
// ensure we're working with a clean table
deleteTable(db)
err = createTable(db)
require.NoError(t, err)
setupTestTable(t, testTable, session)
storage, err := New(testTable, session)
storage, err := New(table, s)
require.NoError(t, err)

return storage
}

Expand All @@ -49,25 +56,25 @@ func TestNoTable(t *testing.T) {
}

func TestCreate(t *testing.T) {
test.CreateTest(getLocalStorage(t))(t)
test.CreateTest(testStorage(t))(t)
}

func TestAdd(t *testing.T) {
test.AddTest(getLocalStorage(t))(t)
test.AddTest(testStorage(t))(t)
}

func TestThreadSafeAdd(t *testing.T) {
test.ThreadSafeAddTest(getLocalStorage(t))(t)
test.ThreadSafeAddTest(testStorage(t))(t)
}

func TestReset(t *testing.T) {
test.AddResetTest(getLocalStorage(t))(t)
test.AddResetTest(testStorage(t))(t)
}

func TestFindOrCreate(t *testing.T) {
test.FindOrCreateTest(getLocalStorage(t))(t)
test.FindOrCreateTest(testStorage(t))(t)
}

func TestBucketInstanceConsistencyTest(t *testing.T) {
test.BucketInstanceConsistencyTest(getLocalStorage(t))(t)
test.BucketInstanceConsistencyTest(testStorage(t))(t)
}
4 changes: 2 additions & 2 deletions dynamodb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/aws/aws-sdk-go/service/dynamodb"
)

func createTable(db *bucketDB) error {
func createTable(db bucketDB) error {
input := &dynamodb.CreateTableInput{
TableName: aws.String(db.tableName),
BillingMode: aws.String(dynamodb.BillingModePayPerRequest),
Expand All @@ -20,7 +20,7 @@ func createTable(db *bucketDB) error {
})
}

func deleteTable(db *bucketDB) error {
func deleteTable(db bucketDB) error {
if _, err := db.ddb.DeleteTable(&dynamodb.DeleteTableInput{
TableName: aws.String(db.tableName),
}); err != nil {
Expand Down

0 comments on commit 0b8068c

Please sign in to comment.