···
1
-
# This test start mongodb, runs a query using mongo shell
1
+
# This test starts mongodb and runs a query using mongo shell
2
+
{ config, lib, ... }:
4
+
# required for test execution on darwin
5
+
pkgs = config.node.pkgs;
testQuery = pkgs.writeScript "nixtest.js" ''
5
-
db.greetings.insert({ "greeting": "hello" });
7
+
db.greetings.insertOne({ "greeting": "hello" });
print(db.greetings.findOne().greeting);
9
-
runMongoDBTest = pkg: ''
10
-
node.execute("(rm -rf data || true) && mkdir data")
12
-
"${pkg}/bin/mongod --fork --logpath logs --dbpath data"
14
-
node.wait_for_open_port(27017)
16
-
assert "hello" in node.succeed(
17
-
"${pkg}/bin/mongo ${testQuery}"
21
-
"${pkg}/bin/mongod --shutdown --dbpath data"
23
-
node.wait_for_closed_port(27017)
10
+
mongoshExe = lib.getExe pkgs.mongosh;
29
-
meta = with pkgs.lib.maintainers; {
14
+
meta.maintainers = with pkgs.lib.maintainers; [
22
+
services.mongodb.enable = true;
41
-
environment.systemPackages = with pkgs; [
42
-
# remember to update mongodb.passthru.tests if you change this
28
+
with subtest("start mongodb"):
29
+
mongodb.wait_for_unit("mongodb.service")
30
+
mongodb.wait_for_open_port(27017)
52
-
+ runMongoDBTest pkgs.mongodb-7_0
32
+
with subtest("insert and find a document"):
33
+
result = mongodb.succeed("${mongoshExe} ${testQuery}")
34
+
print("Test output:", result)
35
+
assert result.strip() == "hello"