Unit testing DynamoDB SDK in Go?

Viewed 404

I'm using the AWS SDK in Go, but I'm having trouble unit testing my DynamoDB updates. Basically, I'm using gomock to set the expected UpdateItemInput like so:

return m.EXPECT().UpdateItemWithContext(
            gomock.Any(),
            &dynamodb.UpdateItemInput {
                ConditionExpression: aws.String("(#0 = :0) AND (#1 = :1)"),
                ExpressionAttributeNames: map[string]*string{
                    "#0": aws.String("PK"),
                    "#1": aws.String("SK"),
                    "#2": aws.String("SomeAttrName"),
                },
                ExpressionAttributeValues: map[string]*dynamodb.AttributeValue {
                    ":0": {S: aws.String(primaryKey)},
                    ":1": {S: aws.String(secondaryKey)},
                    ":2": {S: aws.String(ValueToUpdate)},
                },
                Key: map[string]*dynamodb.AttributeValue{
                    "PK": {S: aws.String(primaryKey)},
                    "SK": {S: aws.String(secondaryKey)},
                },
                ReturnValues:     aws.String(dynamodb.ReturnValueAllNew),
                TableName:        aws.String(dynamo.TableName),
                UpdateExpression: aws.String("SET #2 = :2\n"),
            }

However, when I run the test, it fails because it seems there is a mismatch between what gomock expected and what it got. The positions of the values in the UpdateItemInput from the business logic are different every time I run the test, which I think is what's messing this up.

Is there a better way to test things like this in Go? Or if not, is there a way to enforce the same order every time, or ignore the order?

1 Answers
Related