Skip to content

Commit

Permalink
chore: support for changing the network name
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Sep 25, 2023
1 parent 16cf77a commit 07d541a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/modules/dapr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions modules/dapr/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
Expand Down
7 changes: 7 additions & 0 deletions modules/dapr/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07d541a

Please sign in to comment.