Skip to content

Commit

Permalink
fix: Handle nil value in CleanupNetwork (#2928)
Browse files Browse the repository at this point in the history
The godoc of `CleanupNetwork` states that a `nil` network will result in
a no-op.
  • Loading branch information
l0nax authored Dec 20, 2024
1 parent abe0f82 commit 4f67ae0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,8 @@ func TestWithNewNetworkContextTimeout(t *testing.T) {
require.Empty(t, req.Networks)
require.Empty(t, req.NetworkAliases)
}

func TestCleanupWithNil(t *testing.T) {
var network *testcontainers.DockerNetwork
testcontainers.CleanupNetwork(t, network)
}
4 changes: 3 additions & 1 deletion testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func CleanupNetwork(tb testing.TB, network Network) {
tb.Helper()

tb.Cleanup(func() {
noErrorOrIgnored(tb, network.Remove(context.Background()))
if !isNil(network) {
noErrorOrIgnored(tb, network.Remove(context.Background()))
}
})
}

Expand Down

0 comments on commit 4f67ae0

Please sign in to comment.