Skip to content

Commit

Permalink
Add DynamoDB marshaling update test (#4746)
Browse files Browse the repository at this point in the history
This test fails before the d360428 update.
  • Loading branch information
kalafut authored Jun 12, 2018
1 parent d360428 commit 1b5b204
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions physical/dynamodb/dynamodb_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dynamodb

import (
"context"
"fmt"
"math/rand"
"net/http"
"os"
"reflect"
"testing"
"time"

Expand All @@ -17,6 +19,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)

func TestDynamoDBBackend(t *testing.T) {
Expand Down Expand Up @@ -69,6 +72,44 @@ func TestDynamoDBBackend(t *testing.T) {

physical.ExerciseBackend(t, b)
physical.ExerciseBackend_ListPrefix(t, b)

t.Run("Marshalling upgrade", func(t *testing.T) {
path := "test_key"

// Manually write to DynamoDB using the old ConvertTo function
// for marshalling data
inputEntry := &physical.Entry{
Key: path,
Value: []byte{0x0f, 0xcf, 0x4a, 0x0f, 0xba, 0x2b, 0x15, 0xf0, 0xaa, 0x75, 0x09},
}

record := DynamoDBRecord{
Path: recordPathForVaultKey(inputEntry.Key),
Key: recordKeyForVaultKey(inputEntry.Key),
Value: inputEntry.Value,
}

item, err := dynamodbattribute.ConvertToMap(record)
if err != nil {
t.Fatalf("err: %s", err)
}

request := &dynamodb.PutItemInput{
Item: item,
TableName: &table,
}
conn.PutItem(request)

// Read back the data using the normal interface which should
// handle the old marshalling format gracefully
entry, err := b.Get(context.Background(), path)
if err != nil {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(inputEntry, entry) {
t.Fatalf("exp: %#v, act: %#v", inputEntry, entry)
}
})
}

func TestDynamoDBHABackend(t *testing.T) {
Expand Down

0 comments on commit 1b5b204

Please sign in to comment.