chore(tests): improve integration tests; testing/localdb package#27
Merged
chore(tests): improve integration tests; testing/localdb package#27
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new testing/localdb package to centralize DynamoDB Local container lifecycle and table-creation logic, while refactoring existing integration tests to use random table names, remove duplication, and enable parallel execution.
- Introduce
testing/localdbwithStart()andTestDatabasefor spinning up/tearing down a local DynamoDB container. - Refactor all existing tests to use
getRandomTableNameandprepareTable(t)instead of passing endpoint/name and duplicating container logic. - Bump AWS SDK and
dynagoversions intests/go.modand wire in the new localdb dependency with a replace directive.
Reviewed Changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/transact_items_test.go | Switched to new prepareTable(t) helper and named struct fields |
| tests/query_test.go | Added getRandomTableName, refactored prepareTable, removed endpoint args |
| tests/putitem_test.go | Updated to call prepareTable(t) |
| tests/go.mod | Upgraded SDK/dynago versions, added testing/localdb dependency and replace |
| tests/client_test.go | Removed Docker logic, wired in localdb.Start(), updated client tests |
| testing/localdb/localdb.go | New package for Docker-based DynamoDB Local setup and table creation |
| testing/localdb/go.mod | Module and dependencies for the new testing/localdb package |
Comments suppressed due to low confidence (5)
testing/localdb/localdb.go:63
- [nitpick] Enhance readability of the error wrap by adding a separator, e.g.
fmt.Errorf("failed to create table: %w", err)so the message is clearer.
return fmt.Errorf("failed to create table %w", err)
tests/query_test.go:14
- This file uses
prepareTable,dynagoandtestdb, but missing imports. Addimport "testing",import "github.com/oolio-group/dynago"andimport "github.com/oolio-group/dynago/testing/localdb"so the helper and client types resolve.
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
tests/client_test.go:25
getRandomTableNameis undefined in this file. You need to either define this helper at the top ofclient_test.goor import it from a shared test helper module.
tableName := getRandomTableName(t)
tests/client_test.go:47
tableNameis not declared inTestNewClientLocalEndpoint. You must declaretableName(e.g. viagetRandomTableName(t)) before creating the client and creating the table.
err = testdb.CreateTable(context.TODO(), tableName, "pk", "sk")
testing/localdb/localdb.go:31
- The HTTP response body from
client.Getshould be closed to avoid resource leaks. After checkingerr, adddefer res.Body.Close().
res, err := client.Get(db.address)
NalinSajwan
approved these changes
Jul 3, 2025
tillpos-tony
approved these changes
Jul 4, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introducing
testing/localdbpackage to help with DynamoDB integration tests.Moved test container and create table logic to localdb package for better code structuring.
Additionally, Fixes flaky tests failing occasionally.
Tests can now run in parallel.