From b8467444e40c09e725bd81372d236a5a948694f2 Mon Sep 17 00:00:00 2001 From: Mark Nevill Date: Mon, 16 Oct 2023 21:28:50 +0100 Subject: [PATCH] fix: handle removal of ephemeralForTest in MongoDB 7 --- memongo.go | 7 ++++++- memongo_test.go | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/memongo.go b/memongo.go index ec254d9..20528aa 100644 --- a/memongo.go +++ b/memongo.go @@ -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 { diff --git a/memongo_test.go b/memongo_test.go index c96a1a8..592001a 100644 --- a/memongo_test.go +++ b/memongo_test.go @@ -3,6 +3,7 @@ package memongo_test import ( "context" "fmt" + "strings" "testing" "github.com/tryvium-travels/memongo" @@ -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) { @@ -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) { @@ -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) { @@ -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()) @@ -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) { @@ -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())