Skip to content

Commit

Permalink
try adding network cleanup too
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-cll committed Jan 14, 2025
1 parent 9747218 commit b5dbe8b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion framework/cmd/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createComponentsFromForm(form *nodeSetForm) error {
_ *simple_node_set.Output
err error
)
if err := framework.DefaultNetwork(&sync.Once{}); err != nil {
if err := framework.DefaultNetwork(t, &sync.Once{}); err != nil {
return err
}
switch form.Network {
Expand Down
4 changes: 2 additions & 2 deletions framework/components/clnode/clnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestComponentDockerNodeWithSharedDB(t *testing.T) {
}

for _, tc := range testCases {
err := framework.DefaultNetwork(&sync.Once{})
err := framework.DefaultNetwork(t, &sync.Once{})
require.NoError(t, err)

t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestComponentDockerNodeWithDB(t *testing.T) {
}

for _, tc := range testCases {
err := framework.DefaultNetwork(&sync.Once{})
err := framework.DefaultNetwork(t, &sync.Once{})
require.NoError(t, err)

t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion framework/components/jd/jd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// since JD is private this env var should be set locally and in CI
// TODO: add ComponentDocker prefix to turn this on when we'll have access to ECRs
func TestJD(t *testing.T) {
err := framework.DefaultNetwork(&sync.Once{})
err := framework.DefaultNetwork(t, &sync.Once{})
require.NoError(t, err)
_, err = jd.NewJD(&jd.Input{
Image: os.Getenv("CTF_JD_IMAGE"),
Expand Down
2 changes: 1 addition & 1 deletion framework/components/simple_node_set/nodeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ level = 'info'
}

for _, tc := range testCases {
err := framework.DefaultNetwork(&sync.Once{})
err := framework.DefaultNetwork(t, &sync.Once{})
require.NoError(t, err)

t.Run(tc.name, func(t *testing.T) {
Expand Down
20 changes: 11 additions & 9 deletions framework/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/go-playground/validator/v10"
"github.com/pelletier/go-toml/v2"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/network"
"os"
"path/filepath"
"strings"
"sync"
"testing"
"text/template"
"time"

"github.com/davecgh/go-spew/spew"
"github.com/go-playground/validator/v10"
"github.com/pelletier/go-toml/v2"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/network"
)

const (
Expand Down Expand Up @@ -142,19 +143,20 @@ func Load[X any](t *testing.T) (*X, error) {
// return nil, fmt.Errorf("failed to connect AWSSecretsManager: %w", err)
// }
//}
err = DefaultNetwork(once)
err = DefaultNetwork(t, once)
require.NoError(t, err)
return input, nil
}

func DefaultNetwork(once *sync.Once) error {
func DefaultNetwork(t *testing.T, once *sync.Once) error {
var net *testcontainers.DockerNetwork
var err error
once.Do(func() {
net, err = network.New(
context.Background(),
network.WithLabels(map[string]string{"framework": "ctf"}),
)
testcontainers.CleanupNetwork(t, net)
DefaultNetworkName = net.Name
})
return err
Expand Down

0 comments on commit b5dbe8b

Please sign in to comment.