Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ updates:
- /modules/redpanda
- /modules/registry
- /modules/scylladb
- /modules/socat
- /modules/surrealdb
- /modules/valkey
- /modules/vault
Expand Down
4 changes: 4 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@
"name": "module / scylladb",
"path": "../modules/scylladb"
},
{
"name": "module / socat",
"path": "../modules/socat"
},
{
"name": "module / surrealdb",
"path": "../modules/surrealdb"
Expand Down
52 changes: 52 additions & 0 deletions docs/modules/socat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Socat

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for Socat.

## Adding this module to your project dependencies

Please run the following command to add the Socat module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/socat
```

## Usage example

<!--codeinclude-->
[Creating a Socat container](../../modules/socat/examples_test.go) inside_block:ExampleRun
<!--/codeinclude-->

## Module Reference

### Run function

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

The Socat module exposes one entrypoint function to create the Socat container, and this function receives three parameters:

```golang
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*SocatContainer, error)
```

- `context.Context`, the Go context.
- `string`, the Docker image to use.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the Socat container, you can pass options in a variadic way to configure it.

#### Image

Use the second argument in the `Run` function to set a valid Docker image.
In example: `Run(context.Background(), "alpine/socat:1.8.0.1")`.

{% include "../features/common_functional_options.md" %}

### Container Methods

The Socat container exposes the following methods:
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ nav:
- modules/redpanda.md
- modules/registry.md
- modules/scylladb.md
- modules/socat.md
- modules/surrealdb.md
- modules/valkey.md
- modules/vault.md
Expand Down
5 changes: 5 additions & 0 deletions modules/socat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-socat
90 changes: 90 additions & 0 deletions modules/socat/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package socat_test

import (
"context"
"fmt"
"io"
"log"
"net/http"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/socat"
"github.com/testcontainers/testcontainers-go/network"
)

func ExampleRun() {
ctx := context.Background()

nw, err := network.New(ctx)
if err != nil {
log.Printf("failed to create network: %v", err)
return
}
defer func() {
if err := nw.Remove(ctx); err != nil {
log.Printf("failed to remove network: %s", err)
}
}()

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "testcontainers/helloworld:1.2.0",
ExposedPorts: []string{"8080/tcp"},
Networks: []string{nw.Name},
NetworkAliases: map[string][]string{
nw.Name: {"helloworld"},
},
},
Started: true,
})
if err != nil {
log.Printf("failed to create container: %v", err)
return
}
defer func() {
if err := testcontainers.TerminateContainer(ctr); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()

target := socat.NewTarget(8080, "helloworld")

socatContainer, err := socat.Run(
ctx, "alpine/socat:1.8.0.1",
socat.WithTargets(target),
network.WithNetwork([]string{"socat"}, nw),
)
if err != nil {
log.Printf("failed to create container: %v", err)
return
}
defer func() {
if err := testcontainers.TerminateContainer(socatContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()

httpClient := http.DefaultClient

baseURI := socatContainer.TargetURL(target)

resp, err := httpClient.Get(baseURI.String() + "/ping")
if err != nil {
log.Printf("failed to get response: %v", err)
return
}

fmt.Printf("%d\n", resp.StatusCode)

body, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("failed to read body: %v", err)
return
}

fmt.Printf("%s", string(body))

// Output:
// 200
// PONG
}
67 changes: 67 additions & 0 deletions modules/socat/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module github.com/testcontainers/testcontainers-go/modules/socat

go 1.23.0

toolchain go1.23.6

require (
github.com/docker/go-connections v0.5.0
github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.36.0
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.0.1+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/ebitengine/purego v0.8.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.9 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/sys v0.31.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/testcontainers/testcontainers-go => ../..
Loading
Loading