Skip to content

Commit 219cc4f

Browse files
CSHARP-3948: Follow-up changes. (#681)
1 parent 9a62d16 commit 219cc4f

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/EncryptionTestHelper.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,34 @@ public static void ConfigureDefaultExtraOptions(Dictionary<string, object> extra
4141
extraOptions.Add("mongocryptdURI", $"mongodb://localhost:{mongocryptdPort}");
4242
}
4343

44-
var portValue = $" --port={mongocryptdPort}";
44+
var portKey = "--port=";
45+
var portValue = $" {portKey}{mongocryptdPort}";
4546
if (extraOptions.TryGetValue("mongocryptdSpawnArgs", out var args))
4647
{
47-
object effectiveValue = args switch
48+
object effectiveValue;
49+
switch (args)
4850
{
49-
string str => str + portValue,
50-
IEnumerable enumerable => new List<object>(enumerable.Cast<object>()) { portValue },
51-
_ => throw new Exception("Unsupported mongocryptdSpawnArgs type."),
52-
};
51+
case string str:
52+
{
53+
effectiveValue = str.Contains(portKey) ? str : str + portValue;
54+
}
55+
break;
56+
case IEnumerable enumerable:
57+
{
58+
var list = new List<string>(enumerable.Cast<string>());
59+
if (list.Any(v => v.Contains(portKey)))
60+
{
61+
effectiveValue = list;
62+
}
63+
else
64+
{
65+
list.Add(portValue);
66+
effectiveValue = list;
67+
}
68+
}
69+
break;
70+
default: throw new Exception("Unsupported mongocryptdSpawnArgs type.");
71+
}
5372
extraOptions["mongocryptdSpawnArgs"] = effectiveValue;
5473
}
5574
else

0 commit comments

Comments
 (0)