|
| 1 | +package dockermcpgateway_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "io" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + "github.com/testcontainers/testcontainers-go" |
| 11 | + dmcpg "github.com/testcontainers/testcontainers-go/modules/dockermcpgateway" |
| 12 | +) |
| 13 | + |
| 14 | +func TestDockerMCPGateway(t *testing.T) { |
| 15 | + ctx := context.Background() |
| 16 | + |
| 17 | + ctr, err := dmcpg.Run(ctx, "docker/mcp-gateway:latest") |
| 18 | + testcontainers.CleanupContainer(t, ctr) |
| 19 | + require.NoError(t, err) |
| 20 | + |
| 21 | + require.Empty(t, ctr.Tools()) |
| 22 | +} |
| 23 | + |
| 24 | +func TestDockerMCPGateway_withServerAndTools(t *testing.T) { |
| 25 | + ctx := context.Background() |
| 26 | + |
| 27 | + ctr, err := dmcpg.Run( |
| 28 | + ctx, "docker/mcp-gateway:latest", |
| 29 | + dmcpg.WithTools("curl", []string{"curl"}), |
| 30 | + dmcpg.WithTools("brave", []string{"brave_local_search", "brave_web_search"}), |
| 31 | + dmcpg.WithTools("github-official", []string{"add_issue_comment"}), |
| 32 | + ) |
| 33 | + testcontainers.CleanupContainer(t, ctr) |
| 34 | + require.NoError(t, err) |
| 35 | + |
| 36 | + require.Len(t, ctr.Tools(), 3) |
| 37 | + |
| 38 | + for server, tools := range ctr.Tools() { |
| 39 | + switch server { |
| 40 | + case "curl": |
| 41 | + require.Equal(t, []string{"curl"}, tools) |
| 42 | + case "brave": |
| 43 | + require.ElementsMatch(t, []string{"brave_local_search", "brave_web_search"}, tools) |
| 44 | + case "github-official": |
| 45 | + require.Equal(t, []string{"add_issue_comment"}, tools) |
| 46 | + default: |
| 47 | + t.Errorf("unexpected server: %s", server) |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestDockerMCPGateway_withSecret(t *testing.T) { |
| 53 | + ctx := context.Background() |
| 54 | + |
| 55 | + ctr, err := dmcpg.Run( |
| 56 | + ctx, "docker/mcp-gateway:latest", |
| 57 | + dmcpg.WithSecret("github.personal_access_token", "test_token"), |
| 58 | + ) |
| 59 | + testcontainers.CleanupContainer(t, ctr) |
| 60 | + require.NoError(t, err) |
| 61 | + |
| 62 | + r, err := ctr.CopyFileFromContainer(ctx, "/testcontainers/app/secrets") |
| 63 | + require.NoError(t, err) |
| 64 | + |
| 65 | + bytes, err := io.ReadAll(r) |
| 66 | + require.NoError(t, err) |
| 67 | + require.Equal(t, "github.personal_access_token=test_token\n", string(bytes)) |
| 68 | +} |
| 69 | + |
| 70 | +func TestDockerMCPGateway_withSecrets(t *testing.T) { |
| 71 | + ctx := context.Background() |
| 72 | + |
| 73 | + ctr, err := dmcpg.Run( |
| 74 | + ctx, "docker/mcp-gateway:latest", |
| 75 | + dmcpg.WithSecrets(map[string]string{ |
| 76 | + "github.personal_access_token": "test_token", |
| 77 | + "another.secret": "another_value", |
| 78 | + }), |
| 79 | + ) |
| 80 | + testcontainers.CleanupContainer(t, ctr) |
| 81 | + require.NoError(t, err) |
| 82 | + |
| 83 | + r, err := ctr.CopyFileFromContainer(ctx, "/testcontainers/app/secrets") |
| 84 | + require.NoError(t, err) |
| 85 | + |
| 86 | + bytes, err := io.ReadAll(r) |
| 87 | + require.NoError(t, err) |
| 88 | + require.Equal(t, "github.personal_access_token=test_token\nanother.secret=another_value\n", string(bytes)) |
| 89 | +} |
0 commit comments