-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
893 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Go build and test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- v* | ||
pull_request: | ||
branches: | ||
- main | ||
- release/v* | ||
|
||
env: | ||
GO_VERSION: 1.18.1 | ||
|
||
jobs: | ||
build: | ||
name: Build and Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- run: go mod download | ||
- run: go vet . | ||
- run: go build ./... | ||
- run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Merge Gatekeeper | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- master | ||
|
||
jobs: | ||
merge-gatekeeper: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Run Merge Gatekeeper | ||
uses: upsidr/merge-gatekeeper@main | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,49 @@ | ||
# dynamotest | ||
# dynamotest | ||
|
||
Use the power of [DynamoDB Local][1] with [ory/dockertest][2], create your DynamoDB test cases with breeze. | ||
|
||
[1]: https://hub.docker.com/r/amazon/dynamodb-local/ | ||
[2]: https://github.com/ory/dockertest | ||
|
||
## 🌄 What is `dynamotest`? | ||
|
||
`dynamotest` is a package to help set up a DynamoDB Local Docker instance on your machine as a part of Go test code. It uses [`ory/dockertest`][2] to start the DynamoDB Local instance in your Go test code, and is configured so that each call to `dynamotest.NewDynamoDB(t)` will create a dedicated instance to allow parallel testing on multilpe Docker instances. The function returns a new DynamoDB client which is already connected to the instance, and thus you can simply start using the client straight away. Also, it provides the clean up function to ensure that the Docker instance gets deleted if clean-up is preferred. If you do not call the clean up function, the instance will keep running, which may be useful for debugging and investigation. | ||
|
||
`dynamotest` also provides a helper function `dynamotest.PrepTable(t, client, ...dynamotestInitialTableSetup)` to prepare tables and dataset for setting up the tabel before hand. | ||
|
||
It is also worth noting how this package uses only the v2 version of AWS SDK. | ||
|
||
**NOTE**: It is a prerequisite that you are able to start up Docker container for DynamoDB Local. | ||
|
||
## 🚀 Examples | ||
|
||
### Minimal Setup Overview | ||
|
||
```go | ||
func TestMinimalSetup(t *testing.T) { | ||
// Create a new DynamoDB Local instance. Second return value can be called | ||
// to delete the instance. | ||
client, clean := dynamotest.NewDynamoDB(t) | ||
defer clean() | ||
|
||
// Prepare table with some data. You can provide as many data set as you | ||
// need by providing `dynamotest.InitialTableSetup` structs. | ||
dynamotest.PrepTable(t, client, | ||
dynamotest.InitialTableSetup{ | ||
Table: &dynamodb.CreateTableInput{ | ||
// Table definition. | ||
}, | ||
InitialData: []*types.PutRequest{ | ||
// Initial data to populate the table with. | ||
}, | ||
}, | ||
// Provide as many initial data as you need | ||
) | ||
|
||
// Now the DynamoDB client, which is connected to the test instance, is | ||
// ready to be used. | ||
_ = client | ||
} | ||
``` | ||
|
||
Ref: [minimal_test.go](/minimal_test.go) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dynamotest | ||
|
||
var ( | ||
dynamoDBLocalRepo = "amazon/dynamodb-local" | ||
dynamoDBLocalTag = "1.18.0" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module github.com/upsidr/dynamotest | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go-v2 v1.16.3 | ||
github.com/aws/aws-sdk-go-v2/config v1.15.4 | ||
github.com/aws/aws-sdk-go-v2/credentials v1.12.0 | ||
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.9.1 | ||
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.4 | ||
github.com/google/go-cmp v0.5.8 | ||
github.com/ory/dockertest/v3 v3.8.1 | ||
) | ||
|
||
require ( | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/Microsoft/go-winio v0.5.2 // indirect | ||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect | ||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.10 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.11 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.13.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sso v1.11.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sts v1.16.4 // indirect | ||
github.com/aws/smithy-go v1.11.2 // indirect | ||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect | ||
github.com/containerd/continuity v0.3.0 // indirect | ||
github.com/docker/cli v20.10.14+incompatible // indirect | ||
github.com/docker/docker v20.10.14+incompatible // indirect | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.4.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect | ||
github.com/imdario/mergo v0.3.12 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.0.2 // indirect | ||
github.com/opencontainers/runc v1.1.1 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/sirupsen/logrus v1.8.1 // indirect | ||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect | ||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect | ||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect | ||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect | ||
golang.org/x/sys v0.0.0-20220429121018-84afa8d3f7b3 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
Oops, something went wrong.