8000 test(source/redis): use testcontainers by emagda97 · Pull Request #4476 · googleapis/mcp-toolbox · GitHub
[go: up one dir, main page]

Skip to content

test(source/redis): use testcontainers - #4476

Draft
emagda97 wants to merge 5 commits into
mainfrom
fix/redis-testcontainers
Draft

emagda97 wants to merge 5 commits into
mainfrom
fix/redis-testcontainers

Conversation

@emagda97
Copy link
Copy Markdown
Collaborator

Description

Migrate Redis integration tests to testcontainers.

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure you have manually reviewed the entire diff before requesting a
    review
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>

@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request transitions the Redis integration tests to use an ephemeral Redis container via testcontainers-go when REDIS_ADDRESS is not configured, removing the dependency on Memorystore Redis in the CI configuration. Feedback on the changes highlights a potential nil pointer dereference in setupRedisContainer where testcontainers.CleanupContainer is registered before checking if the container initialization failed.

Comment thread tests/redis/redis_test.go
Comment on lines +63 to +66
testcontainers.CleanupContainer(t, container)
if err != nil {
t.Fatalf("failed to start Redis container: %s", err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Calling testcontainers.CleanupContainer(t, container) before checking if err != nil can cause a nil pointer dereference and panic during test cleanup if container startup fails. This is because CleanupContainer registers a cleanup function that attempts to terminate the container, which will be nil if GenericContainer returned an error. Moving the cleanup registration after the error check ensures that we only attempt to clean up successfully started containers.

Suggested change
testcontainers.CleanupContainer(t, container)
if err != nil {
t.Fatalf("failed to start Redis container: %s", err)
}
if err != nil {
t.Fatalf("failed to start Redis container: %s", err)
}
testcontainers.CleanupContainer(t, container)

This branch has not been deployed

No deployments
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.

1 participant

0