Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ TEST-*.xml

# Environment variables
.env

# Coverage files
coverage.out
18 changes: 10 additions & 8 deletions modules/mongodb/atlaslocal/atlaslocal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"io"
"math/rand/v2"
"net"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -541,8 +542,11 @@ func TestConnectionString(t *testing.T) {
require.NoError(t, err, "Failed to parse connection string")

require.Equal(t, "mongodb", connString.Scheme)
require.Equal(t, "localhost", connString.Hosts[0][:9])
require.NotEmpty(t, connString.Hosts[0][10:], "Port should be non-empty")
host, port, err := net.SplitHostPort(connString.Hosts[0])
require.NoError(t, err, "Invalid host:port")
require.NotEmpty(t, host)
require.NotEmpty(t, port)

require.Equal(t, tc.wantUsername, connString.Username)
require.Equal(t, tc.wantPassword, connString.Password)
require.Equal(t, tc.wantDatabase, connString.Database)
Expand Down Expand Up @@ -759,11 +763,9 @@ func requireInitScriptsDoesNotExist(t *testing.T, ctr testcontainers.Container,

// Sanity check to verify that all scripts are present.
for filename := range expectedScripts {
cmd := []string{"sh", "-c", "cd docker-entrypoint-initdb.d && ls -l"}

exitCode, reader, err := ctr.Exec(context.Background(), cmd)
cmd := []string{"sh", "-lc", "ls -1 /docker-entrypoint-initdb.d 2>/dev/null || true"}
_, reader, err := ctr.Exec(context.Background(), cmd)
require.NoError(t, err)
require.Zero(t, exitCode, "Expected exit code 0 for command: %v", cmd)

content, _ := io.ReadAll(reader)
require.NotContains(t, string(content), filename)
Expand Down Expand Up @@ -792,7 +794,7 @@ func newAuthFiles(t *testing.T) (string, string, string) {
// Create username and password files.
usernameFilepath := filepath.Join(tmpDir, "username.txt")

err := os.WriteFile(usernameFilepath, []byte("file_testuser"), 0o755)
err := os.WriteFile(usernameFilepath, []byte("file_testuser"), 0o600)
require.NoError(t, err)

_, err = os.Stat(usernameFilepath)
Expand All @@ -801,7 +803,7 @@ func newAuthFiles(t *testing.T) (string, string, string) {
// Create the password file.
passwordFilepath := filepath.Join(tmpDir, "password.txt")

err = os.WriteFile(passwordFilepath, []byte("file_testpass"), 0o755)
err = os.WriteFile(passwordFilepath, []byte("file_testpass"), 0o600)
require.NoError(t, err)

_, err = os.Stat(passwordFilepath)
Expand Down
Loading