Simplify cleanup logic in integration tests#156
Simplify cleanup logic in integration tests#156patrickhener merged 1 commit intopatrickhener:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors integration tests to rely on t.Cleanup for container teardown, reducing repetitive per-test cleanup logic.
Changes:
- Updated
spawnTestContainerto register container cleanup viat.Cleanupand return only the mapped port. - Simplified integration tests by removing explicit cleanup calls and error handling around container startup.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
integration/integration_test.go |
Switches tests to use the simplified spawnTestContainer API (port-only) and removes explicit cleanup/error checks. |
integration/functions.go |
Refactors spawnTestContainer to handle failures internally and register container teardown via t.Cleanup. |
Comments suppressed due to low confidence (1)
integration/functions.go:29
spawnTestContainernow performs assertions viarequire.*, but it isn't marked as a test helper. Consider callingt.Helper()at the start so any failures (e.g., file opens, container startup) are reported at the test callsite instead of inside this helper, consistent with other helpers likesmbConnect.
func spawnTestContainer(t *testing.T, config string, webdav bool, smb bool) nat.Port {
// Make sure the host-side coverage drop dir exists and is writable
// by the container's non-root uid (1000). 0o777 is fine for an
// ephemeral test artifact directory.
require.NoError(t, os.MkdirAll(coverageDir, 0o777))
require.NoError(t, os.Chmod(coverageDir, 0o777))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| t.Cleanup(func() { | ||
| cleanupContainer(t, goshsServer) | ||
| }) |
There was a problem hiding this comment.
spawnTestContainer opens several host files (config/certs/keys) and passes them as Readers to testcontainers.ContainerFile, but they are never closed. Now that this function already registers a t.Cleanup, consider also closing those opened files (or defer-closing them right after opening) to avoid leaking file descriptors across the integration test suite.
Description
Refactor integration tests with
t.Cleanup.