Skip to content

chore(testing): use require in tests #1672

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

Merged
merged 19 commits into from
Apr 16, 2025

Conversation

mdelapenya
Copy link
Contributor

@mdelapenya mdelapenya commented Apr 15, 2025

  • chore(aerospike): use require in tests
  • chore(azureblob): use require in tests
  • chore(clickhouse): use require in tests
  • chore(couchbase): use require in tests
  • chore(dynamodb): use require in tests
  • chore(minio): use require in tests
  • chore(mongodb): use require in tests
  • chore(mysql): use require in tests
  • chore(nats): use require in tests
  • chore(neo4j): use require in tests, running a container per test function
  • chore(postgres): use require in tests
  • chore(s3): use require in tests, running a container per test function
  • chore(scylladb): use require in tests

What does this PR do?

It standarises the creation of the store in the tests using testcontainers-go. Now, the function does not return an error and instead uses testify's require to check errors in the creational function.

Also, I noticed some stores did not name the function with newTestStore, so I aligned the functions for that, so developers looking for testing patterns are less prone to commit a mistake.

Finally, I changed the creation of containers in the neo4j and s3 modules, as they created a singleton container. Now each test function uses its own container. If we see that this is not performant, we can go back to it with ease.

Why is it important?

Consistency across the test suites.

Summary by CodeRabbit

  • Refactor
    • Simplified test setup across multiple storage backends by removing error returns from helper functions, now causing tests to fail immediately on setup errors.
    • Each test now creates and cleans up its own isolated store instance, improving test reliability and resource management.
    • Centralized error handling in test helpers for more concise and readable test code.
    • Removed global shared test state in several packages, ensuring better test isolation.
  • Bug Fixes
    • Improved error reporting in the storage reset method to aggregate and return all encountered errors instead of ignoring them.
  • New Features
    • Added a new test to verify error handling when resetting a non-existent bucket in the MinIO storage backend.

@mdelapenya mdelapenya requested a review from a team as a code owner April 15, 2025 15:10
@mdelapenya mdelapenya requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team April 15, 2025 15:10
Copy link
Contributor

coderabbitai bot commented Apr 15, 2025

Walkthrough

This set of changes refactors test helper functions across multiple storage backend test files. The main alteration is the removal of error returns from test setup helpers like newTestStore, which now take a testing.TB parameter and use assertion helpers such as require.NoError to handle errors internally. This pattern centralizes error handling, ensures immediate test failure on setup errors, and simplifies test and benchmark code by removing explicit error checks after store initialization. Some files also replace global test setup with per-test helper functions, further isolating test state and resource management. Additionally, in the Aerospike tests, container cleanup is centralized within the helper function. Minor adjustments to error assertions and resource cleanup timing are made in a few other tests. The MinIO Reset method was modified to aggregate errors from object removals and return a combined error instead of always returning nil.

Changes

Files/Paths Change Summary
aerospike/aerospike_test.go Refactored startAerospikeContainer to accept testing.TB and context, use internal error assertions, and centralize container cleanup; updated newTestStore and related calls to remove error handling.
azureblob/azureblob_test.go Changed newTestStore to return only *Storage; replaced error returns with require.NoError; updated all test and benchmark calls accordingly.
clickhouse/clickhouse_test.go Renamed getTestConnection to newTestStore; changed return type to *Storage; replaced error handling with assertions; updated all usages.
couchbase/couchbase_test.go Refactored newTestStore to remove error returns and use assertions; updated all test and benchmark functions accordingly.
dynamodb/dynamodb_test.go Changed newTestStore to return only *Storage and use assertions; updated all callers; moved store creation before allocation reporting in benchmarks.
minio/minio.go Modified Reset method to collect all errors from RemoveObjects and return a combined error instead of always returning nil.
minio/minio_test.go Updated newTestStore to return only *Storage and use assertions; simplified test and benchmark setup code; removed Reset: true config; added Test_Reset_Not_Exists_Bucket.
mongodb/mongodb_test.go Refactored newTestStore to use assertions and return only *Storage; updated all test and benchmark functions; changed Test_MongoDB_Close to use require.NoError for Close() error.
mysql/mysql_test.go Changed newTestStore to remove error returns and use assertions; updated all usages; added deferred cleanup calls after store creation.
nats/nats_test.go Updated newTestStore to return only *Storage; removed error handling in all test and benchmark setups; added explicit error declarations in benchmarks where needed.
neo4j/neo4j_test.go Moved container termination earlier in TestMain with deferred anonymous function; updated Test_Neo4jStore_Close to use require.NoError; no signature changes.
postgres/postgres_test.go Refactored helper functions (newTestConfig, newTestStore, newTestStoreWithConfig) to remove error returns and use assertions; updated all test and benchmark calls accordingly.
s3/init_test.go Removed global test setup and TestMain; added newTestStore(t testing.TB) *Storage helper for per-test initialization; centralized error handling with assertions; removed explicit bucket deletion.
s3/s3_methods_test.go, s3/s3_test.go Updated all tests and benchmarks to instantiate fresh stores with newTestStore(t) and defer cleanup; replaced error checks in Test_S3_Close with assertions.
scylladb/scylladb_test.go Refactored newTestStore to remove error returns and use assertions; updated all test and benchmark functions accordingly; added error checks for calls to Set and others.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Function
    participant Helper as newTestStore(t)
    participant Container as Test Container
    participant Storage as *Storage

    Test->>Helper: Call newTestStore(t)
    Helper->>Container: Start container (if needed)
    Helper->>Helper: require.NoError on setup
    Helper->>Storage: Initialize Storage instance
    Helper->>Test: Return *Storage
    Test->>Storage: Use storage in test
    Test->>Storage: Defer Close()
Loading

Poem

In the warren of tests, we hop with delight,
No more error returns to keep us up at night.
Helpers now assert, with a thump and a cheer,
Each test runs alone, the code crystal clear.
With cleanup in tow and no global fright,
Our test garden grows—oh, what a sight!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 698ae8a and 73bf793.

📒 Files selected for processing (2)
  • minio/minio.go (1 hunks)
  • minio/minio_test.go (17 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • minio/minio_test.go

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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

🧹 Nitpick comments (1)
clickhouse/clickhouse_test.go (1)

244-254: Inconsistent benchmark timing in Set_And_Delete benchmark.

Unlike other benchmarks, this one has b.ReportAllocs() and b.ResetTimer() calls before client creation, which means the benchmark includes the time to create the client in its measurements. Consider moving these calls after client creation for consistency with other benchmarks.

-func Benchmark_Clickhouse_Set_And_Delete(b *testing.B) {
-	b.ReportAllocs()
-	b.ResetTimer()
-
-	client := newTestStore(b, Config{
+func Benchmark_Clickhouse_Set_And_Delete(b *testing.B) {
+	client := newTestStore(b, Config{
		Engine: Memory,
		Table:  "test_table",
		Clean:  true,
	})
	defer client.Close()
+
+	b.ReportAllocs()
+	b.ResetTimer()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5fb7a0 and aac5d67.

📒 Files selected for processing (15)
  • aerospike/aerospike_test.go (2 hunks)
  • azureblob/azureblob_test.go (11 hunks)
  • clickhouse/clickhouse_test.go (9 hunks)
  • couchbase/couchbase_test.go (9 hunks)
  • dynamodb/dynamodb_test.go (12 hunks)
  • minio/minio_test.go (17 hunks)
  • mongodb/mongodb_test.go (13 hunks)
  • mysql/mysql_test.go (15 hunks)
  • nats/nats_test.go (14 hunks)
  • neo4j/neo4j_test.go (13 hunks)
  • postgres/postgres_test.go (17 hunks)
  • s3/init_test.go (4 hunks)
  • s3/s3_methods_test.go (3 hunks)
  • s3/s3_test.go (9 hunks)
  • scylladb/scylladb_test.go (13 hunks)
🧰 Additional context used
🧠 Learnings (3)
s3/init_test.go (2)
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
clickhouse/clickhouse_test.go (2)
Learnt from: luk3skyw4lker
PR: gofiber/storage#1342
File: clickhouse/clickhouse_test.go:138-160
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `Test_Reset` function in `clickhouse/clickhouse_test.go` already includes a verification step to ensure the storage is empty after a reset operation by checking that a previously set key returns an empty byte slice.
Learnt from: luk3skyw4lker
PR: gofiber/storage#1342
File: clickhouse/clickhouse_test.go:138-160
Timestamp: 2024-07-01T15:48:53.094Z
Learning: The `Test_Reset` function in `clickhouse/clickhouse_test.go` already includes a verification step to ensure the storage is empty after a reset operation by checking that a previously set key returns an empty byte slice.
couchbase/couchbase_test.go (2)
Learnt from: luk3skyw4lker
PR: gofiber/storage#1342
File: clickhouse/clickhouse_test.go:138-160
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `Test_Reset` function in `clickhouse/clickhouse_test.go` already includes a verification step to ensure the storage is empty after a reset operation by checking that a previously set key returns an empty byte slice.
Learnt from: luk3skyw4lker
PR: gofiber/storage#1342
File: clickhouse/clickhouse_test.go:138-160
Timestamp: 2024-07-01T15:48:53.094Z
Learning: The `Test_Reset` function in `clickhouse/clickhouse_test.go` already includes a verification step to ensure the storage is empty after a reset operation by checking that a previously set key returns an empty byte slice.
🧬 Code Graph Analysis (1)
aerospike/aerospike_test.go (1)
aerospike/aerospike.go (1)
  • Storage (11-18)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: compare (postgres)
  • GitHub Check: lint (minio)
  • GitHub Check: lint (postgres)
  • GitHub Check: lint (dynamodb)
  • GitHub Check: lint (mongodb)
  • GitHub Check: lint (nats)
  • GitHub Check: lint (clickhouse)
  • GitHub Check: lint (neo4j)
  • GitHub Check: lint (aerospike)
  • GitHub Check: lint (mysql)
  • GitHub Check: Tests (1.24.x)
  • GitHub Check: Tests (1.23.x)
  • GitHub Check: Tests (1.24.x)
  • GitHub Check: Tests (1.24.x)
  • GitHub Check: Tests (1.23.x)
  • GitHub Check: Tests (1.24.x)
  • GitHub Check: Tests (1.24.x)
  • GitHub Check: Tests (1.23.x)
  • GitHub Check: Tests (1.23.x)
🔇 Additional comments (43)
nats/nats_test.go (4)

78-144: LGTM - Good refactoring to internal error handling

The function signature has been simplified to return only *Storage instead of a tuple with error. All error handling now happens internally using require.NoError(t, err), which will fail the test immediately if any error occurs during test store creation.


153-154: LGTM - Properly updated test initialization

Test initialization has been correctly updated to use the new helper function signature, eliminating the need for error variables and explicit error checking after store creation. The deferred close statements remain unchanged which ensures proper resource cleanup.

Also applies to: 171-172, 194-195, 216-217, 240-241, 267-268, 285-286, 308-309, 340-341, 345-346


354-355: LGTM - Benchmark initialization updated correctly

Benchmark initialization has been updated to match the new helper function signature. The benchmark logic remains unchanged.

Also applies to: 369-370, 386-387


360-361: LGTM - Added error declaration before loop to avoid redeclaration issues

Moving the error variable declaration outside the loop is a good practice to avoid variable redeclaration issues in Go, while still allowing the error result to be checked after the loop completes.

Also applies to: 392-393

azureblob/azureblob_test.go (3)

20-46: LGTM - Good refactoring with internal error handling

The helper function has been updated to return only *Storage instead of (*Storage, error), with errors now handled internally via require.NoError(t, err). This follows the standardization pattern applied across the codebase.


55-56: LGTM - Test and benchmark initialization updated correctly

All test and benchmark functions now correctly use the new helper function signature, which simplifies test code by removing error checking after store creation while ensuring that setup failures still fail the test immediately.

Also applies to: 72-73, 85-86, 110-111, 121-122, 137-138, 169-170, 176-177, 181-182, 196-197, 213-214


187-188: LGTM - Proper error variable declaration for benchmarks

Error variable declarations have been moved before the loop to avoid redeclaration issues in Go, while still allowing for error checking after the loop completes.

Also applies to: 219-220

s3/init_test.go (2)

27-72: LGTM - Good implementation of per-test store initialization

This new helper function replaces global test state with per-test initialization, which improves test isolation. The implementation correctly uses require.NoError for error assertions during bucket creation. The comment about not needing to delete test buckets is helpful for future maintainers.


9-9: LGTM - Added required import

Added require import which is needed for the assertions in the new helper function.

s3/s3_methods_test.go (1)

14-16: LGTM - Properly updated tests to use per-test stores

Tests now correctly instantiate a fresh store instance per test with proper cleanup via deferred Close calls. This change aligns with the PR objective of running separate containers per test for better isolation.

Also applies to: 27-29, 70-72

dynamodb/dynamodb_test.go (2)

19-48: Good refactoring of newTestStore to use require assertions

The function now handles errors internally using require.NoError instead of returning them, which will fail the test immediately upon error. This is a cleaner approach that centralizes error handling in the setup code.


56-57: Clean test function simplification

All test and benchmark functions have been updated to use the simplified newTestStore signature without error handling. This removes boilerplate error checking code from all tests, making them more concise and easier to read while maintaining the same functionality.

Also applies to: 69-70, 85-86, 97-98, 111-112, 128-129, 150-151, 155-156, 162-164, 177-180, 194-196

mysql/mysql_test.go (3)

25-39: Improved test store helper with built-in assertions

The newTestStore function now uses require.NoError internally instead of returning errors, centralizing error handling at the setup level. This is a cleaner pattern that will fail tests immediately if setup fails.


65-67: Test closure pattern improvement

The test now correctly creates a new store instance and immediately defers its closure, ensuring proper resource cleanup even if the test fails. This pattern is consistently applied across all tests in the file.


256-258: Better error reporting for Close test

The Test_MYSQL_Close now uses require.NoError for checking the close operation result instead of the previous implementation. This provides better error messages if the close operation fails.

scylladb/scylladb_test.go (3)

21-49: Improved error handling in test setup

The newTestStore function has been refactored to handle errors internally with require.NoError assertions. This ensures immediate test failure on setup errors instead of returning them to the caller, consistent with the standardization across the codebase.


181-183: Consistent test closure pattern

The test now correctly asserts the error from Close() using require.NoError rather than returning it, maintaining the consistency of error handling throughout the test suite.


231-232: Clean variable declaration in benchmark

The benchmark now uses a separate variable declaration for error handling, avoiding redeclaration issues and maintaining consistent error handling patterns in benchmarks.

s3/s3_test.go (3)

15-17: Improved test isolation with per-test containers

Each test now creates its own test store instance and defers its closure, matching the PR's goal of running separate containers per test function instead of a shared singleton. This enhances test isolation and prevents test interference, though it may increase test execution time.

Also applies to: 28-30, 44-46, 56-58, 70-72, 87-89, 114-116


109-111: Better error assertion for store closing

The Test_S3_Close now creates a new test store and uses require.NoError to assert the close operation succeeds, providing better error reporting than the previous implementation.


120-122: Consistent resource management in benchmarks

Benchmarks now follow the same pattern as tests - creating a dedicated store instance and deferring closure. This ensures proper resource cleanup even during benchmarking.

Also applies to: 135-137, 152-154

couchbase/couchbase_test.go (3)

24-54: Good refactor to remove error returns and use immediate assertions.

The function now correctly uses require.NoError to assert errors immediately, improving test reliability by failing fast on setup errors. This change aligns with the PR's goal of standardizing error handling in test helpers.


57-58: Tests properly updated to use simplified store creation.

All test functions have been correctly updated to remove error handling after store creation, making the tests cleaner and more focused on their intended logic.

Also applies to: 65-66, 75-76, 88-89, 103-104, 117-118, 131-132, 136-137, 143-144, 158-159, 175-176


149-150: Appropriate variable declaration adjustments for benchmarks.

The benchmark functions now correctly declare the error variable before the loop to match the new error handling pattern.

Also applies to: 181-182

minio/minio_test.go (3)

26-62: Good refactor to remove error returns and use immediate assertions.

The function now correctly uses require.NoError to assert errors immediately, improving test reliability by failing fast on setup errors. This change aligns with the PR's goal of standardizing error handling in test helpers.


70-71: Tests properly updated to use simplified store creation.

All test functions have been correctly updated to remove error handling after store creation, making the tests cleaner and more focused on their intended logic.

Also applies to: 90-91, 103-104, 116-117, 134-135, 147-148, 162-163, 179-180, 195-196, 208-209, 224-225, 242-243, 247-248, 262-263, 279-280


253-254: Appropriate variable declaration adjustments for benchmarks.

The benchmark functions now correctly declare the error variable before the loop to match the new error handling pattern.

Also applies to: 285-286

mongodb/mongodb_test.go (4)

25-54: Good refactor to remove error returns and use immediate assertions.

The function now correctly uses require.NoError to assert errors immediately, improving test reliability by failing fast on setup errors. This change aligns with the PR's goal of standardizing error handling in test helpers.


62-63: Tests properly updated to use simplified store creation.

All test functions have been correctly updated to remove error handling after store creation, making the tests cleaner and more focused on their intended logic.

Also applies to: 75-76, 91-92, 109-110, 125-126, 134-135, 148-149, 165-166, 192-193, 199-200, 214-215, 231-232


187-188: Improved error assertion in Close test.

Changed from require.Nil to require.NoError, which is more semantically correct for error checks. This improves code clarity and aligns with Go best practices for error handling.


205-206: Appropriate variable declaration adjustments for benchmarks.

The benchmark functions now correctly declare the error variable before the loop to match the new error handling pattern.

Also applies to: 237-238

clickhouse/clickhouse_test.go (3)

30-75: Function renamed and refactored to align with project conventions.

The function has been renamed from getTestConnection to newTestStore for consistency with other modules, and now correctly uses require.NoError to assert errors immediately. This change aligns with the PR's goals of standardizing naming conventions and error handling in test helpers.


78-83: Tests properly updated to use simplified store creation.

All test functions have been correctly updated to use the renamed function and remove error handling after store creation, making the tests cleaner and more focused on their intended logic.

Also applies to: 87-92, 99-104, 111-116, 129-133, 154-159, 175-180, 196-201, 205-210, 224-229, 248-253


212-215: Appropriate benchmark setup adjustments.

The benchmark functions now correctly declare the error variable before the loop and properly position the ReportAllocs and ResetTimer calls after store creation.

Also applies to: 231-235, 255-256

neo4j/neo4j_test.go (3)

20-49: Improved test isolation through per-test container management.

The new newTestStore function properly implements the container-per-test pattern, creating an isolated Neo4j container for each test function and handling cleanup appropriately. The use of require.NoError for immediate test failure on setup errors improves test reliability.


35-36: Correctly using CleanupContainer for automated test cleanup.

Using testcontainers.CleanupContainer(t, neo4jContainer) ensures the container is properly terminated when the test completes, even if it fails. This is a best practice that prevents resource leaks.


57-59: Test refactoring consistently applies the new store-per-test pattern.

All test and benchmark functions now correctly create a fresh Storage instance and defer its closure, improving test isolation and preventing state leakage between tests.

Also applies to: 70-72, 86-88, 104-106, 120-122, 129-131, 143-145, 160-162, 184-186, 196-197, 201-203, 207-209, 222-224, 239-241

aerospike/aerospike_test.go (3)

28-30: Improved test helper function signature.

Adding t.Helper() properly marks this as a helper function, which improves test failure reporting by showing the correct location in test code.


54-62: Enhanced container management with proper cleanup.

The function now correctly registers container cleanup with testcontainers.CleanupContainer(t, ctr) and uses require.NoError to fail tests immediately on setup errors instead of propagating them.


68-76: Simplified error handling in newTestStore.

The function now correctly uses require.NoError for error handling, eliminating error propagation and simplifying calling code.

postgres/postgres_test.go (3)

26-53: Streamlined test configuration with proper cleanup.

The newTestConfig function now correctly registers container cleanup with testcontainers.CleanupContainer and uses require.NoError for immediate test failure on errors. This simplifies test code by eliminating error handling in test functions.


55-65: Simplified test store creation pattern.

The newTestStore and newTestStoreWithConfig functions have been refactored to return only the store instance without error handling, making test code cleaner and more readable.


235-240: Consistently applied simplified error handling pattern across all tests.

All test and benchmark functions have been updated to use the simplified store creation pattern, removing error checking after store creation and improving test readability.

Also applies to: 248-256, 264-273, 282-293, 298-304, 307-313, 321-333, 338-357, 362-382, 387-396, 407-411, 414-416, 419-431, 434-448, 451-464

@mdelapenya
Copy link
Contributor Author

I'm not sure about the failures:

  • mysql:9 image gets stuck in the tests without processing. Need to investigate more in depth.
  • minio's benchmarks: they produce this output in my local machine, even with the main branch:
2025/04/15 17:53:43 The specified bucket does not exist
2025/04/15 17:53:43 Error detected during deletion:  {  The specified bucket does not exist}
goos: darwin
goarch: arm64
pkg: github.com/gofiber/storage/minio
cpu: Apple M1 Pro
Benchmark_Minio_Set-8                   2025/04/15 17:53:44 The specified bucket does not exist
2025/04/15 17:53:44 Error detected during deletion:  {  The specified bucket does not exist}
      39          30794987 ns/op           88367 B/op        292 allocs/op
2025/04/15 17:53:47 The specified bucket does not exist
2025/04/15 17:53:47 Error detected during deletion:  {  The specified bucket does not exist}
Benchmark_Minio_Get-8                   2025/04/15 17:53:49 The specified bucket does not exist
2025/04/15 17:53:49 Error detected during deletion:  {  The specified bucket does not exist}
      39          29842138 ns/op           16521 B/op        202 allocs/op
2025/04/15 17:53:52 The specified bucket does not exist
2025/04/15 17:53:52 Error detected during deletion:  {  The specified bucket does not exist}
Benchmark_Minio_SetAndDelete-8          2025/04/15 17:53:53 The specified bucket does not exist
2025/04/15 17:53:53 Error detected during deletion:  {  The specified bucket does not exist}
      19          60866055 ns/op          100929 B/op        458 allocs/op
PASS
ok      github.com/gofiber/storage/minio        15.615s

Is that expected?

  • neo4j: need to verify why the numbers are so high... I can revert the work for neo4j only and make progress here.

Thoughts?

@mdelapenya
Copy link
Contributor Author

mdelapenya commented Apr 15, 2025

Interesting: for minio I identified that the removal of the bucket was leaking the errors, not sure if on purpose 🤔 For that reason I checked different Reset implementations and noticed that they did capture the errors when "resetting" the state, in this case buckets (see the S3 module as reference). I fixed that in 73bf793, capturing the errors and adding a test. I checked this removed the Error detected during deletion: { The specified bucket does not exist} message in the benchmarks.

And I updated the test config for minio to avoid calling reset on startup, as in the S3 module, which was indeed the root cause: because Reset was set to true, the Reset method was called, trying to remove the config bucket, logging the error without capturing it.

BTW I'm happy to split this PR in two and fix the minio bug in a separate PR

@mdelapenya mdelapenya added ☢️ Bug Something isn't working 🧹 Updates labels Apr 15, 2025
@gaby gaby removed the ☢️ Bug Something isn't working label Apr 15, 2025
@gaby gaby requested a review from Copilot April 16, 2025 04:19
Copy link
Contributor

@Copilot 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 standardizes test setup and error handling across multiple storage backends. It replaces manual error checks with testify’s require assertions in test helper functions and aligns naming conventions for test store functions.

  • Simplified test helper functions by removing error return values.
  • Each test now creates its own isolated container instance for improved test isolation.
  • Updated naming of test store functions for consistency.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scylladb/scylladb_test.go Updated newTestStore to return *Storage; replaced error checks with require assertions.
s3/s3_test.go Simplified test setup by removing error returns from newTestStore.
s3/s3_methods_test.go Updated newTestStore usage for consistency in S3 methods tests.
s3/init_test.go Modified test store initialization; removed bucket deletion since container disposal is sufficient.
postgres/postgres_test.go Revised newTestConfig and newTestStore functions to remove unused error returns.
neo4j/neo4j_test.go Adjusted container termination handling and replaced require.Nil with require.NoError.
nats/nats_test.go Standardized test store initialization across NATS tests.
mysql/mysql_test.go Updated test store functions to use require assertions instead of manual error handling.
mongodb/mongodb_test.go Simplified newTestStore and updated tests to reflect the new signature.
minio/minio_test.go Revised newTestStore and updated test cases to remove error returns.
minio/minio.go Modified Reset() to accumulate deletion errors using errors.Join.
dynamodb/dynamodb_test.go Aligned newTestStore and test cases to use require assertions.
couchbase/couchbase_test.go Standardized test store initialization and error verification.
clickhouse/clickhouse_test.go Updated newTestStore and test cases for consistent test container usage.
azureblob/azureblob_test.go Updated newTestStore functions and tests to remove error returns.
aerospike/aerospike_test.go Revised test container startup to use require assertions; adjusted test store creation.
Comments suppressed due to low confidence (1)

aerospike/aerospike_test.go:2

  • The require package is used in the test code (e.g., require.NoError) but it is not imported. Please add 'github.com/stretchr/testify/require' to the import block to ensure the tests compile.
package aerospike

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

👍 LGTM, lets do Min.IO as a separate PR

@ReneWerner87 ReneWerner87 merged commit e21a906 into gofiber:main Apr 16, 2025
57 of 58 checks passed
@mdelapenya mdelapenya deleted the testing-patterns branch April 16, 2025 06:31
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