Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use testcontainers-go for couchbase and minio #1508

Merged
merged 7 commits into from
Aug 29, 2024

Conversation

mdelapenya
Copy link
Contributor

@mdelapenya mdelapenya commented Aug 21, 2024

  • chore: missing usage of constant
  • chore: use testcontainers-go module for couchbase in tests
  • chore: simplify
  • chore: use testcontainers-go module for minio in tests

What does this PR do?

This PR adds testcontainers-go to the Couchbase and Minio modules, updating the current code to be consistent across modules in how the store is created for testing purpose (minio created one container per test suite, instead of per test method).

Why is it important?

Increase adoption of testcontainers-go for consistency when running the integration tests on contributions.

Follow-ups

Consider a) running one container per test suite Vs b) one container per test function. While a) is optimal for resource allocation, it can lead to test data polution if tests are not written correctly to create/destroy its data. OTOH b) can lead to have more containers running, but given the type of tests here, I'd say this is meaningless for the current state of the project.

Summary by CodeRabbit

  • New Features

    • Introduced environment variables for Couchbase and MinIO to enhance testing infrastructure.
    • Added a new function for setting up a MinIO test storage environment, improving reliability and isolation of tests.
  • Improvements

    • Streamlined Couchbase and MinIO testing workflows by removing manual setup steps and utilizing pre-defined Docker images.
    • Enhanced error handling in storage setup functions to improve robustness and prevent misleading test results.
  • Refactor

    • Updated functions for better clarity and maintainability, directly using testing.TB type.
    • Simplified test initialization processes across various components.

@mdelapenya mdelapenya requested a review from a team as a code owner August 21, 2024 15:26
@mdelapenya mdelapenya requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team August 21, 2024 15:26
Copy link
Contributor

coderabbitai bot commented Aug 21, 2024

Walkthrough

The recent changes enhance the testing infrastructure by introducing environment variables for Couchbase and MinIO images, streamlining the testing workflows. The modifications reduce complexity, improve error handling, and ensure isolation between tests. Utilizing predefined Docker images simplifies setup and improves consistency across testing environments, leading to more robust and maintainable test code.

Changes

Files Change Summary
.github/workflows/... Introduced environment variables TEST_COUCHBASE_IMAGE and TEST_MINIO_IMAGE for Docker images, enhancing the testing infrastructure and removing manual setup steps.
clickhouse/clickhouse_test.go Removed TestOrBench interface and simplified getTestConnection to use testing.TB, while updating the ClickHouse image retrieval method.
couchbase/couchbase_test.go Modified newTestStore to return an error alongside Storage, enhancing error handling and connection setup for Couchbase testing.
minio/minio_test.go Introduced newTestStore for isolated MinIO setup, improving reliability and error management in tests by dynamically setting storage parameters.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Functions
    participant Store as NewTestStore Function
    participant Storage as Storage Instance

    Test->>Store: Call newTestStore()
    Store->>Storage: Initialize MinIO or Couchbase
    Store-->>Test: Return Storage, Error (if any)
    Test->>Test: Proceed with tests if no error
Loading

🐰 In the world of code where rabbits play,
New images hop in to brighten the way.
With each little test and every new store,
Errors are caught, and bugs are no more!
Aqua and brown, oh what a sight,
Our workflows are nimble, everything feels right!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (3)
minio/minio_test.go (2)

22-56: Consider adding logging for debugging purposes.

Adding logs for container initialization and connection string retrieval can aid in debugging issues during test setup.

Here's a suggestion:

log.Printf("Initializing MinIO container with image: %s", img)
...
log.Printf("MinIO connection string: %s", conn)

Line range hint 65-279: Consider adding assertions to verify state changes.

Adding assertions to verify the state of the storage after operations can enhance test coverage and reliability.

For example, after testStore.Set, you can assert that the key exists in the storage.

.github/workflows/benchmark.yml (1)

177-178: Document the new environment variables for clarity.

Consider updating the documentation to include TEST_COUCHBASE_IMAGE and TEST_MINIO_IMAGE to ensure clarity for future contributors.

You can add comments in the workflow file or update the project's README.md.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 01d0e07 and 8a873c0.

Files ignored due to path filters (4)
  • couchbase/go.mod is excluded by !**/*.mod
  • couchbase/go.sum is excluded by !**/*.sum, !**/*.sum
  • minio/go.mod is excluded by !**/*.mod
  • minio/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (6)
  • .github/workflows/benchmark.yml (1 hunks)
  • .github/workflows/test-couchbase.yml (1 hunks)
  • .github/workflows/test-minio.yml (1 hunks)
  • clickhouse/clickhouse_test.go (1 hunks)
  • couchbase/couchbase_test.go (8 hunks)
  • minio/minio_test.go (11 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/test-couchbase.yml
Additional comments not posted (5)
.github/workflows/test-minio.yml (1)

29-30: LGTM! The workflow change enhances consistency.

The introduction of the TEST_MINIO_IMAGE environment variable improves the reliability and consistency of the testing environment by using a predefined Docker image.

couchbase/couchbase_test.go (2)

22-53: LGTM! Enhanced error handling and flexibility.

The newTestStore function now returns an error, improving error handling in test cases. The use of an environment variable for the Couchbase image enhances configuration flexibility.


Line range hint 57-179: LGTM! Improved robustness in test cases.

The addition of error handling in test cases ensures that tests only proceed if the store is successfully created, preventing misleading results.

clickhouse/clickhouse_test.go (2)

26-26: LGTM! Simplified function interface.

The removal of the TestOrBench interface in favor of using testing.TB directly simplifies the code and reduces complexity.


30-30: LGTM! Enhanced maintainability with environment variables.

Using an environment variable for the ClickHouse image improves maintainability and clarity in the code.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8a873c0 and fe56bc5.

Files ignored due to path filters (1)
  • couchbase/go.mod is excluded by !**/*.mod
Files selected for processing (1)
  • .github/workflows/benchmark.yml (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/benchmark.yml

@gaby
Copy link
Member

gaby commented Aug 22, 2024

Based on our policies, this would be a breaking change. We have to discuss it since it bumps the min version of golang to 1.21/1.22

@mdelapenya
Copy link
Contributor Author

mdelapenya commented Aug 22, 2024

I found that the Go version is not consistently set across the different stores, that's why I went ahead with the bump, supported by the fact that Go 1.21 is EOL (https://endoflife.date/go):

Store 1.19 1.20 1.21 1.22 1.23
ArangoDB
Azure Blob
Badger
BBolt
ClickHouse
CloudflareKV
Coherence
Couchbase (before this PR)
DynamoDB
Etcd
Memcache
Memory
Minio (before this PR)
MockStorage
MongoDB
MSSQL
MySQL
NATS
Pebble
Postgres
Redis
Ristretto
Rueidis
S3
ScyllaDB
SQLite3

Besides that, I also found similar issues as with clickhouse regarding compilation, and remembered the comment about bumping the Go version for clickhouse mod file.

In any case, I'm open to any discussion about this, doing what's best for the project.

Thanks!

@mdelapenya
Copy link
Contributor Author

I did not mention but, once decided which version to use, I can help and submit a PR updating the version.

@ReneWerner87
Copy link
Member

thx LGTM
@gaby can you also check

@ReneWerner87
Copy link
Member

there is a problem with the benchmark
image
@mdelapenya can you check it

@ReneWerner87
Copy link
Member

or maybe its not related -> i will retrigger it

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe56bc5 and 304baba.

Files selected for processing (2)
  • .github/workflows/test-couchbase.yml (1 hunks)
  • .github/workflows/test-minio.yml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/test-couchbase.yml
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/test-minio.yml

@ReneWerner87
Copy link
Member

strange
s3 is not related to these code changes
image

i triggered the benchmark in the master , lets see, then it is there i will just merge it

@ReneWerner87 ReneWerner87 merged commit 29406b2 into gofiber:main Aug 29, 2024
21 of 22 checks passed
@mdelapenya mdelapenya deleted the tc-go-adoption branch August 29, 2024 07:02
@mdelapenya
Copy link
Contributor Author

@ReneWerner87 thanks for this! I'm preparing another batch PR. What Go versions should I use in the CI matrix? I.e. mongodb tests against Go 1.19, 1.20 and 1.21. Should we standardise to use 3 versions (current, current -1 and current -2)?

@ReneWerner87
Copy link
Member

thank you

with the goversions it is such a thing, can we make the adjustments without changing the golang versions?

each adapter is independent and has its own major version
we only use a multirepo to manage this

unless it is necessary, we want to spare the consumer a major version switch for as long as possible

@mdelapenya
Copy link
Contributor Author

Makes sense, thanks.

I'll update the store tests only, leaving to you the decision of bumping the Go versions based on the special needs for each one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants