From 07d541a76e7a162c967229f53176082be012d45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Mon, 25 Sep 2023 13:41:53 +0200 Subject: [PATCH] chore: support for changing the network name --- docs/modules/dapr.md | 9 +++++++++ modules/dapr/examples_test.go | 1 + modules/dapr/options.go | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/docs/modules/dapr.md b/docs/modules/dapr.md index 63f4e6a1e3..664ead1e3a 100644 --- a/docs/modules/dapr.md +++ b/docs/modules/dapr.md @@ -31,6 +31,11 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize - `context.Context`, the Go context. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. +This entrypoint function will create: + +- a Dapr network in which the Dapr container and all its components will be attached. Default name is `dapr-network`. +- a Dapr container. + ### Container Options When starting the Dapr container, you can pass options in a variadic way to configure it. @@ -46,6 +51,10 @@ for Dapr. E.g. `testcontainers.WithImage("daprio/daprd:1.11.3")`. It's possible to define the application name used by Dapr with the `WithAppName(name string)` functional option. If not passed, the default value is `dapr-app`. +#### Network Name + +It's possible to define the network name used by Dapr with the `WithNetworkName(name string)` functional option. If not passed, the default value is `dapr-network`. + #### Components You can add components to the Dapr container with the `WithComponents(components ...Component)` functional option. If not passed, the default value is an empty map. diff --git a/modules/dapr/examples_test.go b/modules/dapr/examples_test.go index 60f80959a7..b35d8ace70 100644 --- a/modules/dapr/examples_test.go +++ b/modules/dapr/examples_test.go @@ -15,6 +15,7 @@ func ExampleRunContainer() { daprContainer, err := dapr.RunContainer(ctx, testcontainers.WithImage("daprio/daprd:1.11.3"), dapr.WithAppName("dapr-app"), + dapr.WithNetworkName("dapr-network"), dapr.WithComponents( dapr.NewComponent("pubsub", "pubsub.in-memory", map[string]string{"foo": "bar", "bar": "baz"}), dapr.NewComponent("statestore", "statestore.in-memory", map[string]string{"baz": "qux", "quux": "quuz"}), diff --git a/modules/dapr/options.go b/modules/dapr/options.go index eac95c3b12..33b834bc14 100644 --- a/modules/dapr/options.go +++ b/modules/dapr/options.go @@ -42,6 +42,13 @@ func WithAppName(name string) Option { } } +// WithNetworkName defines the network name in which the dapr container is attached. +func WithNetworkName(name string) Option { + return func(o *options) { + o.NetworkName = name + } +} + // componentStruct { type Component struct { Name string