Skip to content

Commit

Permalink
fix: handle removal of ephemeralForTest in MongoDB 7
Browse files Browse the repository at this point in the history
  • Loading branch information
devnev authored and saniales committed Nov 8, 2023
1 parent ea6505b commit b846744
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
7 changes: 6 additions & 1 deletion memongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ func StartWithOptions(opts *Options) (*Server, error) {
args := []string{"--dbpath", dbDir, "--port", strconv.Itoa(opts.Port)}
if opts.ShouldUseReplica {
engine = "wiredTiger"
args = append(args, []string{"--replSet", "rs0", "--bind_ip", "localhost"}...)
args = append(args, "--replSet", "rs0")
} else if strings.HasPrefix(opts.MongoVersion, "7.") {
engine = "wiredTiger"
}
if engine == "wiredTiger" {
args = append(args, "--bind_ip", "localhost")
}

if opts.Auth {
Expand Down
21 changes: 15 additions & 6 deletions memongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package memongo_test
import (
"context"
"fmt"
"strings"
"testing"

"github.com/tryvium-travels/memongo"
Expand All @@ -16,7 +17,7 @@ import (
)

func TestDefaultOptions(t *testing.T) {
versions := []string{"4.4.7", "5.0.0"}
versions := []string{"4.4.7", "5.0.0", "7.0.0"}

for _, version := range versions {
t.Run(version, func(t *testing.T) {
Expand All @@ -36,7 +37,7 @@ func TestDefaultOptions(t *testing.T) {
}

func TestWithReplica(t *testing.T) {
versions := []string{"4.4.7", "5.0.0"}
versions := []string{"4.4.7", "5.0.0", "7.0.0"}

for _, version := range versions {
t.Run(version, func(t *testing.T) {
Expand All @@ -61,7 +62,7 @@ func TestWithReplica(t *testing.T) {
}

func TestWithAuth(t *testing.T) {
versions := []string{"4.4.7", "5.0.0"}
versions := []string{"4.4.7", "5.0.0", "7.0.0"}

for _, version := range versions {
t.Run(version, func(t *testing.T) {
Expand Down Expand Up @@ -95,7 +96,11 @@ func TestWithAuth(t *testing.T) {

require.NoError(t, client2.Ping(context.Background(), nil))
_, err = client2.ListDatabaseNames(context.Background(), bson.D{})
require.EqualError(t, err, "(Unauthorized) command listDatabases requires authentication")
if strings.HasPrefix(version, "7.") {
require.EqualError(t, err, "(Unauthorized) Command listDatabases requires authentication")
} else {
require.EqualError(t, err, "(Unauthorized) command listDatabases requires authentication")
}

// Now connect again with auth
opts := options.Client().ApplyURI(server.URI())
Expand All @@ -115,7 +120,7 @@ func TestWithAuth(t *testing.T) {
}

func TestWithReplicaAndAuth(t *testing.T) {
versions := []string{"4.4.7", "5.0.0"}
versions := []string{"4.4.7", "5.0.0", "7.0.0"}

for _, version := range versions {
t.Run(version, func(t *testing.T) {
Expand Down Expand Up @@ -154,7 +159,11 @@ func TestWithReplicaAndAuth(t *testing.T) {

require.NoError(t, client2.Ping(context.Background(), nil))
_, err = client2.ListDatabaseNames(context.Background(), bson.D{})
require.EqualError(t, err, "(Unauthorized) command listDatabases requires authentication")
if strings.HasPrefix(version, "7.") {
require.EqualError(t, err, "(Unauthorized) Command listDatabases requires authentication")
} else {
require.EqualError(t, err, "(Unauthorized) command listDatabases requires authentication")
}

// Now connect again with auth
opts := options.Client().ApplyURI(server.URI())
Expand Down

0 comments on commit b846744

Please sign in to comment.