@@ -2,11 +2,11 @@ package framework
22
33import (
44 "bytes"
5- "context"
65 "encoding/json"
76 "errors"
87 "fmt"
98 "os"
9+ "os/exec"
1010 "path/filepath"
1111 "strings"
1212 "sync"
@@ -21,8 +21,6 @@ import (
2121 "github.com/pelletier/go-toml/v2"
2222 "github.com/rs/zerolog"
2323 "github.com/stretchr/testify/require"
24- "github.com/testcontainers/testcontainers-go"
25- "github.com/testcontainers/testcontainers-go/network"
2624)
2725
2826const (
@@ -43,15 +41,8 @@ const (
4341)
4442
4543var (
46- Once = & sync.Once {}
47- // Secrets is a singleton AWS Secrets Manager
48- // Loaded once on start inside Load and is safe to call concurrently
49- Secrets * AWSSecretsManager
50-
51- DefaultNetworkName string
52-
53- Validator * validator.Validate = validator .New (validator .WithRequiredStructEnabled ())
54-
44+ DefaultNetworkName = "ctf"
45+ Validator = validator .New (validator .WithRequiredStructEnabled ())
5546 ValidatorTranslator ut.Translator
5647)
5748
@@ -202,7 +193,7 @@ func Load[X any](t *testing.T) (*X, error) {
202193 require .NoError (t , err )
203194 })
204195 }
205- if err = DefaultNetwork (Once ); err != nil {
196+ if err = DefaultNetwork (nil ); err != nil {
206197 L .Info ().Err (err ).Msg ("docker network creation failed, either docker is not running or you are running in CRIB mode" )
207198 }
208199 return input , nil
@@ -253,19 +244,17 @@ func BaseCacheName() (string, error) {
253244 return fmt .Sprintf ("%s-cache.toml" , name ), nil
254245}
255246
256- func DefaultNetwork (once * sync.Once ) error {
257- var net * testcontainers.DockerNetwork
258- var innerErr error
259- once .Do (func () {
260- net , innerErr = network .New (
261- context .Background (),
262- network .WithLabels (map [string ]string {"framework" : "ctf" }),
263- )
264- if innerErr == nil {
265- DefaultNetworkName = net .Name
247+ func DefaultNetwork (_ * sync.Once ) error {
248+ netCmd := exec .Command ("docker" , "network" , "create" , DefaultNetworkName )
249+ out , err := netCmd .CombinedOutput ()
250+ L .Debug ().Str ("Out" , string (out )).Msg ("Creating Docker network" )
251+ if err != nil {
252+ if strings .Contains (string (out ), "already exists" ) {
253+ return nil
266254 }
267- })
268- return innerErr
255+ return err
256+ }
257+ return err
269258}
270259
271260func RenderTemplate (tmpl string , data interface {}) (string , error ) {
0 commit comments