Sometimes you want to run unit tests that require credentials to AWS, you may not have those off hand, or may just want to run the unit tests in question without AWS. This allows you to run mock credentials for key AWS functionalities, let’s see how we can set this up in Travis.
Some pre-requesites we need to tell Travis to fetch in our
.travis.yml file, things like MongoDB, and Node, here’s my
.travis.yml file for your usage:
language: node_js env: - EC2_REGION=eu-west-1 - AWS_S3_BUCKET="mock-montana-build" - AWS_S3_BUCKET=ecs-refarch-cloudformation - SERVER_USER=ec2-user - SERVER_USER=ec2-user SERVER_DNS=ec2-x-x-69-65.eu-west-3.compute.amazonaws.com sudo: required node_js: - '8' - '6' services: - mongodb
As you can tell I’ve added
When your build is successful you should see in your build log something like this:
This means the mock AWS credentials have worked and you can run your unit tests using mock AWS credentials.
You can now run unit tests when you sometimes don’t have those AWS environment variables off hand. As always, if you have any questions, please email me firstname.lastname@example.org for help/and or if you need assistance with this tutorial.