Deniz Eren An ordinary person

Writing Tests for Dynamodb Application

While developing my side project I needed to write tests for my backend which was using Dynamodb. So connecting to Amazon in my test code was not the solution (obviously), but what was the right way to write tests? I looked at goamz library, which I used for dynamodb interaction in my project.


launch: DynamoDBLocal.jar
    cd dynamodb_local_$(DYNAMODB_LOCAL_VERSION) && java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar

DynamoDBLocal.jar: dynamodb_local_$(DYNAMODB_LOCAL_VERSION).tar.gz
    mkdir -p dynamodb_local_$(DYNAMODB_LOCAL_VERSION)
    [ -f dynamodb_local_$(DYNAMODB_LOCAL_VERSION)/DynamoDBLocal.jar ] || tar -C dynamodb_local_$(DYNAMODB_LOCAL_VERSION) -zxf dynamodb_local_$(DYNAMODB_LOCAL_VERSION).tar.gz

    curl -O$(DYNAMODB_LOCAL_VERSION).tar.gz

    rm -rf dynamodb_local_$(DYNAMODB_LOCAL_VERSION)*

Voila! This was the trick. Guys at Amazon build a small client-side version of dynamodb using Java so that people like me can test their applications without connecting to Amazon.

Using this local dynamodb application I was able to write a small dynamodb backend for gorilla sessions and write tests for my side project.

Happy hacking.