Skip to content

chore(tests): improve integration tests; testing/localdb package#27

Merged
shidil merged 4 commits intomainfrom
testing/localdb
Jul 4, 2025
Merged

chore(tests): improve integration tests; testing/localdb package#27
shidil merged 4 commits intomainfrom
testing/localdb

Conversation

@shidil
Copy link
Member

@shidil shidil commented Jul 3, 2025

Introducing testing/localdb package 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.

image

Copilot AI review requested due to automatic review settings July 3, 2025 07:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/localdb with Start() and TestDatabase for spinning up/tearing down a local DynamoDB container.
  • Refactor all existing tests to use getRandomTableName and prepareTable(t) instead of passing endpoint/name and duplicating container logic.
  • Bump AWS SDK and dynago versions in tests/go.mod and 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, dynago and testdb, but missing imports. Add import "testing", import "github.com/oolio-group/dynago" and import "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

  • getRandomTableName is undefined in this file. You need to either define this helper at the top of client_test.go or import it from a shared test helper module.
	tableName := getRandomTableName(t)

tests/client_test.go:47

  • tableName is not declared in TestNewClientLocalEndpoint. You must declare tableName (e.g. via getRandomTableName(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.Get should be closed to avoid resource leaks. After checking err, add defer res.Body.Close().
	res, err := client.Get(db.address)

@shidil shidil requested review from NalinSajwan and snehithv July 3, 2025 07:30
@shidil shidil merged commit 505e3d6 into main Jul 4, 2025
2 checks passed
@shidil shidil deleted the testing/localdb branch July 4, 2025 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants