11package awsdbe
22
33import (
4- "errors"
5- "strings"
64 "testing"
75
86 "github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/migration/PlaintextToAWSDBE/plaintext"
97 "github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/utils"
10- "github.com/aws/smithy-go"
118 "github.com/google/uuid"
129)
1310
@@ -18,41 +15,26 @@ func TestMigrationStep3(t *testing.T) {
1815 sortKeys := []string {"0" , "1" , "2" , "3" }
1916
2017 // Successfully executes Step 3
21- MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [3 ])
18+ utils . HandleError ( MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [3 ]) )
2219
2320 // Given: Step 0 has succeeded
24- plaintext .MigrationStep0 (tableName , partitionKey , sortKeys [0 ])
21+ utils . HandleError ( plaintext .MigrationStep0 (tableName , partitionKey , sortKeys [0 ]) )
2522 // When: Execute Step 3 with sortReadValue=0, Then: should panic (cannot read plaintext values)
2623 // MigrationStep3(kmsKeyID, tableName, partitionKey, sortKeys[0])
27- assertError (MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [0 ]))
24+ utils . AssertServiceError (MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [0 ]), "DynamoDB" , "GetItem" , "Encrypted item missing expected header and footer attributes" )
2825
2926 // Given: Step 1 has succeeded
30- MigrationStep1 (kmsKeyID , tableName , partitionKey , sortKeys [1 ])
27+ utils . HandleError ( MigrationStep1 (kmsKeyID , tableName , partitionKey , sortKeys [1 ]) )
3128 // When: Execute Step 3 with sortReadValue=1, Then: should panic (cannot read plaintext values)
32- assertError (MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [1 ]))
29+ utils . AssertServiceError (MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [1 ]), "DynamoDB" , "GetItem" , "Encrypted item missing expected header and footer attributes" )
3330
3431 // Given: Step 2 has succeeded
35- MigrationStep2 (kmsKeyID , tableName , partitionKey , sortKeys [2 ])
32+ utils . HandleError ( MigrationStep2 (kmsKeyID , tableName , partitionKey , sortKeys [2 ]) )
3633 // When: Execute Step 3 with sortReadValue=2, Then: Success (can read encrypted values)
37- MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [2 ])
34+ utils . HandleError ( MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [2 ]) )
3835
3936 // Cleanup
4037 for _ , sortKey := range sortKeys {
4138 utils .DeleteItem (tableName , "partition_key" , partitionKey , "sort_key" , sortKey )
4239 }
4340}
44-
45- func assertError (err error ) {
46- var oe * smithy.OperationError
47- if errors .As (err , & oe ) {
48- if oe .Service () != "DynamoDB" {
49- panic ("Expected service to be DynamoDB" )
50- }
51- if oe .Operation () != "GetItem" {
52- panic ("Expected Operation to be GetItem" )
53- }
54- if ! strings .Contains (oe .Unwrap ().Error (), "Encrypted item missing expected header and footer attributes" ) {
55- panic ("Expected message to contain Encrypted item missing expected header and footer attributes" )
56- }
57- }
58- }
0 commit comments