Skip to content

Commit

Permalink
address CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vyskocilm committed Dec 3, 2024
1 parent a599cae commit ff17ba1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/modules/nats.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ These arguments are passed to the NATS server when it starts, as part of the com
- 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>
It's possible to pass a custom config file to NATS container using `nats.WithConfigFile(strings.NewReader(config))`. The `io.Reader` is passed as a `-config /etc/nats.conf` arguments to an entrypoint.
It's possible to pass a custom config file to NATS container using `nats.WithConfigFile(strings.NewReader(config))`. The content of `io.Reader` is passed as a `-config /etc/nats.conf` arguments to an entrypoint.

!!! note
Changing the connectivity (listen address or ports) can break the container setup. So configuration must be done with care.
Expand Down
9 changes: 6 additions & 3 deletions modules/nats/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"strings"
"testing"
"time"

"github.com/nats-io/nats.go"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -78,21 +79,23 @@ authorization {

// connect without a correct token must fail
mallory, err := nats.Connect(uri, nats.Name("Mallory"), nats.Token("secret"))
require.Error(t, err)
require.ErrorIs(t, err, nats.ErrAuthorization)
t.Cleanup(mallory.Close)
require.EqualError(t, err, "nats: Authorization Violation")

// connect with a correct token must succeed
nc, err := nats.Connect(uri, nats.Name("API Token Test"), nats.Token("s3cr3t"))
require.NoError(t, err)
t.Cleanup(nc.Close)
require.NoError(t, err)

// validate /etc/nats.conf mentioned in logs
const expected = "Using configuration file: /etc/nats.conf"
logs, err := ctr.Logs(ctx)
require.NoError(t, err)
sc := bufio.NewScanner(logs)
found := false
time.AfterFunc(5*time.Second, func() {
require.Truef(t, found, "expected log line not found after 5 seconds: %s", expected)
})
for sc.Scan() {
if strings.Contains(sc.Text(), expected) {
found = true
Expand Down

0 comments on commit ff17ba1

Please sign in to comment.