1
1
package awsdbe
2
2
3
3
import (
4
- "errors"
5
- "strings"
6
4
"testing"
7
5
8
6
"github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/migration/PlaintextToAWSDBE/plaintext"
9
7
"github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/utils"
10
- "github.com/aws/smithy-go"
11
8
"github.com/google/uuid"
12
9
)
13
10
@@ -18,41 +15,26 @@ func TestMigrationStep3(t *testing.T) {
18
15
sortKeys := []string {"0" , "1" , "2" , "3" }
19
16
20
17
// Successfully executes Step 3
21
- MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [3 ])
18
+ utils . HandleError ( MigrationStep3 (kmsKeyID , tableName , partitionKey , sortKeys [3 ]) )
22
19
23
20
// Given: Step 0 has succeeded
24
- plaintext .MigrationStep0 (tableName , partitionKey , sortKeys [0 ])
21
+ utils . HandleError ( plaintext .MigrationStep0 (tableName , partitionKey , sortKeys [0 ]) )
25
22
// When: Execute Step 3 with sortReadValue=0, Then: should panic (cannot read plaintext values)
26
23
// 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" )
28
25
29
26
// Given: Step 1 has succeeded
30
- MigrationStep1 (kmsKeyID , tableName , partitionKey , sortKeys [1 ])
27
+ utils . HandleError ( MigrationStep1 (kmsKeyID , tableName , partitionKey , sortKeys [1 ]) )
31
28
// 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" )
33
30
34
31
// Given: Step 2 has succeeded
35
- MigrationStep2 (kmsKeyID , tableName , partitionKey , sortKeys [2 ])
32
+ utils . HandleError ( MigrationStep2 (kmsKeyID , tableName , partitionKey , sortKeys [2 ]) )
36
33
// 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 ]) )
38
35
39
36
// Cleanup
40
37
for _ , sortKey := range sortKeys {
41
38
utils .DeleteItem (tableName , "partition_key" , partitionKey , "sort_key" , sortKey )
42
39
}
43
40
}
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