@@ -29,14 +29,6 @@ type Container struct {
29
29
30
30
// Run creates an instance of the Socat container type
31
31
func Run (ctx context.Context , img string , opts ... testcontainers.ContainerCustomizer ) (* Container , error ) {
32
- req := testcontainers.GenericContainerRequest {
33
- ContainerRequest : testcontainers.ContainerRequest {
34
- Image : img ,
35
- Entrypoint : []string {"/bin/sh" },
36
- },
37
- Started : true ,
38
- }
39
-
40
32
// Gather all config options (defaults and then apply provided options)
41
33
settings := defaultOptions ()
42
34
for _ , opt := range opts {
@@ -45,27 +37,33 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
45
37
return nil , err
46
38
}
47
39
}
48
- if err := opt .Customize (& req ); err != nil {
49
- return nil , err
50
- }
51
40
}
52
41
42
+ moduleOpts := []testcontainers.ContainerCustomizer {
43
+ testcontainers .WithEntrypoint ("/bin/sh" ),
44
+ }
45
+
46
+ exposedPorts := []string {}
47
+
53
48
for k := range settings .targets {
54
- req . ExposedPorts = append (req . ExposedPorts , fmt .Sprintf ("%d/tcp" , k ))
49
+ exposedPorts = append (exposedPorts , fmt .Sprintf ("%d/tcp" , k ))
55
50
}
51
+ moduleOpts = append (moduleOpts , testcontainers .WithExposedPorts (exposedPorts ... ))
56
52
57
53
if settings .targetsCmd != "" {
58
- req . Cmd = append (req . Cmd , "-c" , settings .targetsCmd )
54
+ moduleOpts = append (moduleOpts , testcontainers . WithCmdArgs ( "-c" , settings .targetsCmd ) )
59
55
}
60
56
61
- container , err := testcontainers .GenericContainer (ctx , req )
57
+ moduleOpts = append (moduleOpts , opts ... )
58
+
59
+ container , err := testcontainers .Run (ctx , img , moduleOpts ... )
62
60
var c * Container
63
61
if container != nil {
64
62
c = & Container {Container : container }
65
63
}
66
64
67
65
if err != nil {
68
- return c , fmt .Errorf ("generic container : %w" , err )
66
+ return c , fmt .Errorf ("run socat : %w" , err )
69
67
}
70
68
71
69
// Only check if the socat binary is available if there are targets to expose.
0 commit comments