Skip to content

Commit

Permalink
set config/test.exs as a 'bare-bones' config file and import ddb_loca…
Browse files Browse the repository at this point in the history
…l_test.exs only if it has been provided.
  • Loading branch information
darrenklein committed Oct 27, 2019
1 parent 462c133 commit 8d13332
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

/config/ddb_local_test.exs
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Documentation can be found at [https://hexdocs.pm/ex_aws_dynamo](https://hexdocs

### DynamoDB Local

If you are running this module against a local version of DynamoDB, you'll want to make sure that you have installed the latest version, currently `1.11.477` (released 2019-02-06). You can find links to download the latest version [here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html)
If you are running this module against a local version of DynamoDB, you'll want to make sure that you have installed the latest version, currently `1.11.477` (released 2019-02-06). You can find links to download the latest version [here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html).

## Configuration

Expand All @@ -52,11 +52,27 @@ This application supports three test commands:

### Integration tests (optional)

The tests in `test/lib/dynamo/integration_test.exs` will attempt to run against a local instance of DynamoDB - in order to run these tests, you will need a running local instance of DynamoDB and will need to uncomment the contents of `config/test.exs`, setting the value of `:port` to match Dynamo's port.
The tests in `test/lib/dynamo/integration_test.exs` will attempt to run against a local instance of DynamoDB - in order to run these tests, you will need both a running local instance of DynamoDB as well as a `config/ddb_local_test.exs` file (.gitignored) formatted like so:

Before setting the `:port`, be aware that `integration_test.exs` will create and delete tables with the names `"TestUsers"`, `"Test.User"`, `"TestSeveralUsers"`, `"TestFoo"`, `"test_books"`, `"TestUsersWithRange"`, `"TestTransactions"`, `"TestTransactions2"` - be careful when setting the port, as these operations may affect your current tables if they share any of those names.
`config/ddb_local_test.exs`

If you do not have a running local instance of DynamoDB and/or you don't uncomment the contents of `config/test.exs`, the integration tests will be ignored.
```elixir
use Mix.Config

config :ex_aws,
debug_requests: false, # set to true to monitor the DDB requests
access_key_id: "abcd",
secret_access_key: "1234",
region: "us-east-1"

config :ex_aws, :dynamodb,
scheme: "http://",
host: "localhost",
port: SET_YOUR_PORT,
region: "us-east-1"
```

Before setting the `:port`, be aware that `test/lib/dynamo/integration_test.exs` will create and delete tables with the names `"TestUsers"`, `"Test.User"`, `"TestSeveralUsers"`, `"TestFoo"`, `"test_books"`, `"TestUsersWithRange"`, `"TestTransactions"`, `"TestTransactions2"` - be careful when setting the port, as these operations may affect your current tables if they share any of those names.

## License

Expand Down
13 changes: 13 additions & 0 deletions config/ddb_local_test.exs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use Mix.Config

config :ex_aws,
debug_requests: false, # set to true to monitor the DDB requests
access_key_id: "abcd",
secret_access_key: "1234",
region: "us-east-1"

config :ex_aws, :dynamodb,
scheme: "http://",
host: "localhost",
port: SET_YOUR_PORT,
region: "us-east-1"
21 changes: 5 additions & 16 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
use Mix.Config

###################################################################
# Uncomment the configuration below and set the value for :port
# in order to run the tests in test/lib/dynamo/integration_test.exs
###################################################################

# config :ex_aws,
# debug_requests: false, # set to true to monitor the DDB requests
# access_key_id: "abcd",
# secret_access_key: "1234",
# region: "us-east-1"

# config :ex_aws, :dynamodb,
# scheme: "http://",
# host: "localhost",
# port: SET_YOUR_TEST_PORT,
# region: "us-east-1"
# Only attempt to load config for DDB local if
# a config has been explicitly provided. See README.
if File.exists?("config/ddb_local_test.exs") do
import_config "ddb_local_test.exs"
end
2 changes: 1 addition & 1 deletion test/support/ddb_local.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule DDBLocal do
{:error, error} -> {:error, error}
end
else
{:error, "No value provided for :port in config/test.exs."}
{:error, "No value provided for :port in config/ddb_local_test.exs."}
end
end

Expand Down

0 comments on commit 8d13332

Please sign in to comment.