@@ -30,7 +30,7 @@ primary key configuration:
30
30
- Partition key is named "partition_key" with type (S)
31
31
- Sort key is named "sort_key" with type (S)
32
32
*/
33
- func MigrationStep0 (ddbTableName , partitionKeyValue , sortKeyValue string ) {
33
+ func MigrationStep0 (ddbTableName , partitionKeyValue , sortKeyValue string ) error {
34
34
// 1. Create a standard DynamoDB client
35
35
cfg , err := config .LoadDefaultConfig (context .TODO ())
36
36
utils .HandleError (err )
@@ -79,15 +79,26 @@ func MigrationStep0(ddbTableName, partitionKeyValue, sortKeyValue string) {
79
79
panic ("No item found" )
80
80
}
81
81
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
+ }
84
94
85
- if returnedPartitionKey != partitionKeyValue {
95
+ if returnedPartitionKey . Value != partitionKeyValue {
86
96
panic (fmt .Sprintf ("Expected partition key %s, got %s" , partitionKeyValue , returnedPartitionKey ))
87
97
}
88
- if returnedAttribute1 != "this will be encrypted and signed" {
98
+ if returnedAttribute1 . Value != "this will be encrypted and signed" {
89
99
panic (fmt .Sprintf ("Expected attribute1 value, got %s" , returnedAttribute1 ))
90
100
}
91
101
92
102
fmt .Println ("MigrationStep0 completed successfully" )
103
+ return nil
93
104
}
0 commit comments