Skip to content

Commit 8d13332

Browse files
committed
set config/test.exs as a 'bare-bones' config file and import ddb_local_test.exs only if it has been provided.
1 parent 462c133 commit 8d13332

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ erl_crash.dump
1818

1919
# Also ignore archive artifacts (built via "mix archive.build").
2020
*.ez
21+
22+
/config/ddb_local_test.exs

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Documentation can be found at [https://hexdocs.pm/ex_aws_dynamo](https://hexdocs
2727

2828
### DynamoDB Local
2929

30-
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)
30+
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).
3131

3232
## Configuration
3333

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

5353
### Integration tests (optional)
5454

55-
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.
55+
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:
5656

57-
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.
57+
`config/ddb_local_test.exs`
5858

59-
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.
59+
```elixir
60+
use Mix.Config
61+
62+
config :ex_aws,
63+
debug_requests: false, # set to true to monitor the DDB requests
64+
access_key_id: "abcd",
65+
secret_access_key: "1234",
66+
region: "us-east-1"
67+
68+
config :ex_aws, :dynamodb,
69+
scheme: "http://",
70+
host: "localhost",
71+
port: SET_YOUR_PORT,
72+
region: "us-east-1"
73+
```
74+
75+
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.
6076

6177
## License
6278

config/ddb_local_test.exs.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use Mix.Config
2+
3+
config :ex_aws,
4+
debug_requests: false, # set to true to monitor the DDB requests
5+
access_key_id: "abcd",
6+
secret_access_key: "1234",
7+
region: "us-east-1"
8+
9+
config :ex_aws, :dynamodb,
10+
scheme: "http://",
11+
host: "localhost",
12+
port: SET_YOUR_PORT,
13+
region: "us-east-1"

config/test.exs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
use Mix.Config
22

3-
###################################################################
4-
# Uncomment the configuration below and set the value for :port
5-
# in order to run the tests in test/lib/dynamo/integration_test.exs
6-
###################################################################
7-
8-
# config :ex_aws,
9-
# debug_requests: false, # set to true to monitor the DDB requests
10-
# access_key_id: "abcd",
11-
# secret_access_key: "1234",
12-
# region: "us-east-1"
13-
14-
# config :ex_aws, :dynamodb,
15-
# scheme: "http://",
16-
# host: "localhost",
17-
# port: SET_YOUR_TEST_PORT,
18-
# region: "us-east-1"
3+
# Only attempt to load config for DDB local if
4+
# a config has been explicitly provided. See README.
5+
if File.exists?("config/ddb_local_test.exs") do
6+
import_config "ddb_local_test.exs"
7+
end

test/support/ddb_local.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule DDBLocal do
2424
{:error, error} -> {:error, error}
2525
end
2626
else
27-
{:error, "No value provided for :port in config/test.exs."}
27+
{:error, "No value provided for :port in config/ddb_local_test.exs."}
2828
end
2929
end
3030

0 commit comments

Comments
 (0)