@@ -30,7 +30,7 @@ primary key configuration:
3030 - Partition key is named "partition_key" with type (S)
3131 - Sort key is named "sort_key" with type (S)
3232*/
33- func MigrationStep0 (ddbTableName , partitionKeyValue , sortKeyValue string ) {
33+ func MigrationStep0 (ddbTableName , partitionKeyValue , sortKeyValue string ) error {
3434 // 1. Create a standard DynamoDB client
3535 cfg , err := config .LoadDefaultConfig (context .TODO ())
3636 utils .HandleError (err )
@@ -79,15 +79,26 @@ func MigrationStep0(ddbTableName, partitionKeyValue, sortKeyValue string) {
7979 panic ("No item found" )
8080 }
8181
82- returnedPartitionKey := result .Item ["partition_key" ].(* types.AttributeValueMemberS ).Value
83- returnedAttribute1 := result .Item ["attribute1" ].(* types.AttributeValueMemberS ).Value
82+ returnedPartitionKey , ok := result .Item ["partition_key" ].(* types.AttributeValueMemberS )
83+ if ! ok {
84+ // We return this error because we run test against the error.
85+ // When used in production code, you can decide how you want to handle errors.
86+ return fmt .Errorf ("partition_key is not a string attribute" )
87+ }
88+ returnedAttribute1 , ok := result .Item ["attribute1" ].(* types.AttributeValueMemberS )
89+ if ! ok {
90+ // We return this error because we run test against the error.
91+ // When used in production code, you can decide how you want to handle errors.
92+ return fmt .Errorf ("partition_key is not a string attribute" )
93+ }
8494
85- if returnedPartitionKey != partitionKeyValue {
95+ if returnedPartitionKey . Value != partitionKeyValue {
8696 panic (fmt .Sprintf ("Expected partition key %s, got %s" , partitionKeyValue , returnedPartitionKey ))
8797 }
88- if returnedAttribute1 != "this will be encrypted and signed" {
98+ if returnedAttribute1 . Value != "this will be encrypted and signed" {
8999 panic (fmt .Sprintf ("Expected attribute1 value, got %s" , returnedAttribute1 ))
90100 }
91101
92102 fmt .Println ("MigrationStep0 completed successfully" )
103+ return nil
93104}
0 commit comments