testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

chore: enable usetesting linter

Open mmorel-35 opened this issue 2 months ago • 3 comments

What does this PR do?

Enables and fixes issues from usetesting linter

Why is it important?

Related issues

mmorel-35 avatar Sep 27 '25 11:09 mmorel-35

[!WARNING]

Rate limit exceeded

@mmorel-35 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 23 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4773e6b3154fcb77e385f861946d5114e482ebab and ae9e0a8b935bfbb135bf56a14166486de2125623.

📒 Files selected for processing (107)
  • .golangci.yml (2 hunks)
  • container_test.go (6 hunks)
  • docker_auth_test.go (9 hunks)
  • docker_client_test.go (2 hunks)
  • docker_exec_test.go (3 hunks)
  • docker_files_test.go (5 hunks)
  • docker_test.go (55 hunks)
  • examples/nginx/nginx_test.go (1 hunks)
  • examples_test.go (1 hunks)
  • from_dockerfile_test.go (6 hunks)
  • generic_test.go (5 hunks)
  • image_substitutors_test.go (2 hunks)
  • image_test.go (6 hunks)
  • internal/core/docker_host_test.go (15 hunks)
  • internal/core/docker_rootless_test.go (6 hunks)
  • lifecycle_test.go (7 hunks)
  • logconsumer_test.go (11 hunks)
  • modulegen/_template/module_test.go.tmpl (1 hunks)
  • modules/aerospike/aerospike_test.go (2 hunks)
  • modules/arangodb/arangodb_test.go (2 hunks)
  • modules/arangodb/examples_test.go (1 hunks)
  • modules/artemis/artemis_test.go (2 hunks)
  • modules/azure/azurite/azurite_test.go (3 hunks)
  • modules/azure/azurite/examples_test.go (12 hunks)
  • modules/azure/eventhubs/eventhubs_test.go (3 hunks)
  • modules/azure/eventhubs/examples_test.go (3 hunks)
  • modules/azure/servicebus/examples_test.go (4 hunks)
  • modules/azure/servicebus/servicebus_test.go (3 hunks)
  • modules/azurite/azurite_test.go (1 hunks)
  • modules/cassandra/cassandra_test.go (4 hunks)
  • modules/chroma/chroma_test.go (2 hunks)
  • modules/chroma/examples_test.go (9 hunks)
  • modules/clickhouse/clickhouse_test.go (9 hunks)
  • modules/cockroachdb/cockroachdb_test.go (2 hunks)
  • modules/compose/compose_api_test.go (30 hunks)
  • modules/compose/compose_examples_test.go (3 hunks)
  • modules/compose/compose_test.go (3 hunks)
  • modules/consul/consul_test.go (1 hunks)
  • modules/couchbase/couchbase_test.go (7 hunks)
  • modules/databend/databend_test.go (2 hunks)
  • modules/dind/dind_test.go (1 hunks)
  • modules/dockermcpgateway/dockermcpgateway_test.go (4 hunks)
  • modules/dockermodelrunner/docker_desktop_test.go (2 hunks)
  • modules/dockermodelrunner/dockermodelrunner_test.go (2 hunks)
  • modules/dockermodelrunner/examples_test.go (6 hunks)
  • modules/dolt/dolt_test.go (6 hunks)
  • modules/dynamodb/dynamodb_test.go (9 hunks)
  • modules/elasticsearch/elasticsearch_test.go (4 hunks)
  • modules/etcd/etcd_test.go (3 hunks)
  • modules/etcd/etcd_unit_test.go (4 hunks)
  • modules/gcloud/bigquery/bigquery_test.go (1 hunks)
  • modules/gcloud/bigtable/bigtable_test.go (1 hunks)
  • modules/gcloud/datastore/datastore_test.go (1 hunks)
  • modules/gcloud/firestore/firestore_test.go (2 hunks)
  • modules/gcloud/pubsub/pubsub_test.go (1 hunks)
  • modules/gcloud/spanner/spanner_test.go (1 hunks)
  • modules/grafana-lgtm/grafana_test.go (1 hunks)
  • modules/inbucket/inbucket_test.go (1 hunks)
  • modules/influxdb/influxdb_test.go (5 hunks)
  • modules/k3s/k3s_test.go (3 hunks)
  • modules/k6/k6_test.go (1 hunks)
  • modules/kafka/kafka_test.go (4 hunks)
  • modules/localstack/localstack_test.go (4 hunks)
  • modules/localstack/v1/s3_test.go (1 hunks)
  • modules/localstack/v2/s3_test.go (2 hunks)
  • modules/mariadb/mariadb_test.go (6 hunks)
  • modules/meilisearch/meilisearch_test.go (2 hunks)
  • modules/memcached/memcached_test.go (1 hunks)
  • modules/milvus/milvus_test.go (2 hunks)
  • modules/minio/minio_test.go (1 hunks)
  • modules/mockserver/examples_test.go (2 hunks)
  • modules/mongodb/atlaslocal/atlaslocal_test.go (27 hunks)
  • modules/mongodb/mongodb_test.go (1 hunks)
  • modules/mssql/mssql_test.go (6 hunks)
  • modules/mysql/mysql_test.go (4 hunks)
  • modules/nats/examples_test.go (1 hunks)
  • modules/nats/nats_test.go (2 hunks)
  • modules/nebulagraph/nebulagraph_test.go (1 hunks)
  • modules/neo4j/neo4j_test.go (3 hunks)
  • modules/ollama/examples_test.go (4 hunks)
  • modules/ollama/local_test.go (5 hunks)
  • modules/ollama/ollama_test.go (7 hunks)
  • modules/openfga/examples_test.go (8 hunks)
  • modules/openfga/openfga_test.go (1 hunks)
  • modules/openldap/openldap_test.go (4 hunks)
  • modules/opensearch/opensearch_test.go (1 hunks)
  • modules/pinecone/pinecone_test.go (2 hunks)
  • modules/postgres/postgres_test.go (15 hunks)
  • modules/pulsar/pulsar_test.go (1 hunks)
  • modules/qdrant/examples_test.go (9 hunks)
  • modules/qdrant/qdrant_test.go (1 hunks)
  • modules/rabbitmq/examples_test.go (2 hunks)
  • modules/rabbitmq/rabbitmq_test.go (6 hunks)
  • modules/redis/redis_test.go (5 hunks)
  • modules/redpanda/redpanda_test.go (13 hunks)
  • modules/registry/examples_test.go (5 hunks)
  • modules/registry/registry_test.go (9 hunks)
  • modules/scylladb/scylladb_test.go (5 hunks)
  • modules/socat/socat_test.go (5 hunks)
  • modules/solace/examples_test.go (2 hunks)
  • modules/solace/solace_test.go (2 hunks)
  • modules/surrealdb/surrealdb_test.go (2 hunks)
  • modules/toxiproxy/options_test.go (1 hunks)
  • modules/toxiproxy/toxiproxy_test.go (2 hunks)
  • modules/valkey/valkey_test.go (6 hunks)
  • modules/vault/vault_test.go (3 hunks)
  • modules/vearch/vearch_test.go (1 hunks)

Summary by CodeRabbit

  • Tests

    • Standardized context handling across the test suite to use test-managed contexts and timeouts, improving reliability and alignment with test deadlines.
    • Updated examples and a few internal helpers to accept and propagate contexts consistently.
    • Minor cleanup removing unused imports with no behavioral impact.
  • Chores

    • Tightened linting rules to enforce best practices in tests, promoting consistent context usage and safer environment handling.

No user-facing functionality changes; behavior remains the same outside of improved test stability and tooling.

Walkthrough

Refactors tests to derive contexts from testing.T via t.Context() instead of context.Background()/TODO across the codebase, updates examples to use a shared ctx, and adds the “usetesting” linter with configuration. A few test helper functions’ signatures now accept a context parameter to propagate the test context.

Changes

Cohort / File(s) Summary
Lint configuration
.golangci.yml
Enables linter usetesting; adds settings.usetesting.os-setenv: false.
Tests: adopt t.Context()
container_test.go, docker_*_test.go, examples_test.go, from_dockerfile_test.go, generic_test.go, image_*_test.go, internal/core/*_test.go, lifecycle_test.go, logconsumer_test.go, modulegen/main_test.go, modules/*/*_test.go (many), modules/.../v*/**/*_test.go
Replace context.Background()/TODO with t.Context(); remove unused context imports; update timeouts to derive from t.Context(); propagate ctx through calls (Run, Exec, Inspect, Endpoint, etc.).
Examples: unify local ctx
examples/nginx/nginx_test.go, modules/*/examples_test.go, modules/compose/compose_examples_test.go, modules/azure/*/examples_test.go, modules/ollama/examples_test.go, modules/qdrant/examples_test.go, modules/mockserver/examples_test.go, modules/nats/examples_test.go, modules/arangodb/examples_test.go
Introduce/reuse a local ctx; replace inline Background/TODO; in some cases wrap with WithTimeout; thread ctx through client/container calls.
Helper signature updates (tests/examples)
modules/dynamodb/dynamodb_test.go (createTable now takes ctx), modules/rabbitmq/examples_test.go (assertPlugins now takes ctx), modules/solace/examples_test.go (testMessagePublishAndConsume now takes ctx), modules/dockermodelrunner/docker_desktop_test.go + modules/dockermodelrunner/examples_test.go (isDockerDesktopRunning now takes ctx), modules/clickhouse/clickhouse_test.go (getAllRows now takes ctx)
Add context.Context parameters to helpers; update all call sites to pass t.Context()/ctx; no exported API changes.
Cloud provider modules (GCP/Azure/AWS)
modules/gcloud/*/*_test.go, modules/azure/**/_test.go, modules/localstack/**/_test.go, modules/scylladb/*_test.go, modules/dynamodb/dynamodb_test.go
Replace Background/TODO with t.Context()/ctx; propagate ctx into SDK calls (e.g., AWS config LoadDefaultConfig, client ops).

Sequence Diagram(s)

sequenceDiagram
  participant T as testing.T
  participant Test as Test Code
  participant Prov as Testcontainers Provider
  participant Svc as Service/Client

  T->>Test: t.Context()
  Test->>Prov: Run(ctx)
  Prov-->>Test: Container
  Test->>Prov: Endpoint/Inspect/Exec(ctx)
  Test->>Svc: Client Ops (ctx)
  note over Test,Svc: ctx carries test deadlines/cancellation
  T-->>Test: Test ends → ctx canceled

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • testcontainers/testcontainers-go#3305 — Migrates tests from GenericContainer to Run/options; touches many of the same test files and container lifecycles, complementary to this PR’s context propagation.

Suggested labels

chore

Suggested reviewers

  • mdelapenya
  • stevenh

Poem

I nibbled the tests with context in paw,
Swapped Background breezes for T’s timely law.
With whispers of cancel and deadlines that sing,
Our burrow now listens to what test clocks bring.
Thump-thump—usetesting keeps watch in the spring! 🐇⏱️

Pre-merge checks and finishing touches and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.11% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title succinctly describes the primary change of enabling the usetesting linter, which aligns with the modifications in the .golangci.yml and corresponding test updates. It uses clear, concise language and directly reflects the intent of the changeset. The conventional "chore:" prefix properly categorizes the nature of the change without extraneous detail. Therefore, the title effectively summarizes the main purpose of the PR.
Description Check ✅ Passed The pull request description clearly states that the PR enables the usetesting linter and applies fixes, which directly corresponds to the changes observed in the configuration and test files. Although some sections are placeholders, the core description stays on-topic and conveys the PR’s purpose without drifting into unrelated details.

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Sep 27 '25 11:09 coderabbitai[bot]

Deploy Preview for testcontainers-go ready!

Name Link
Latest commit ae9e0a8b935bfbb135bf56a14166486de2125623
Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68d7ed462b1498000855c874
Deploy Preview https://deploy-preview-3316--testcontainers-go.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Sep 27 '25 11:09 netlify[bot]

Curious, why disable os-setenv?

NathanBaulch avatar Oct 14 '25 01:10 NathanBaulch