1# This test starts mongodb and runs a query using mongo shell
2{ config, lib, ... }:
3let
4 # required for test execution on darwin
5 pkgs = config.node.pkgs;
6 testQuery = pkgs.writeScript "nixtest.js" ''
7 db.greetings.insertOne({ "greeting": "hello" });
8 print(db.greetings.findOne().greeting);
9 '';
10 mongoshExe = lib.getExe pkgs.mongosh;
11in
12{
13 name = "mongodb";
14 meta.maintainers = with pkgs.lib.maintainers; [
15 bluescreen303
16 offline
17 phile314
18 niklaskorz
19 ];
20
21 nodes.mongodb = {
22 services.mongodb.enable = true;
23 };
24
25 testScript = ''
26 start_all()
27
28 with subtest("start mongodb"):
29 mongodb.wait_for_unit("mongodb.service")
30 mongodb.wait_for_open_port(27017)
31
32 with subtest("insert and find a document"):
33 result = mongodb.succeed("${mongoshExe} ${testQuery}")
34 print("Test output:", result)
35 assert result.strip() == "hello"
36 '';
37}