summaryrefslogtreecommitdiffstats
path: root/nixos/tests/mongodb.nix
blob: 7a9b67342e798d69f42376aaf324198e6492e299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# This test starts mongodb and runs a query using mongo shell
{
  testName,
  config,
  lib,
  ...
}:
let
  # required for test execution on darwin
  pkgs = config.node.pkgs;
  testQuery = pkgs.writeScript "nixtest.js" ''
    db.greetings.insertOne({ "greeting": "hello" });
    print(db.greetings.findOne().greeting);
  '';
  mongoshExe = lib.getExe pkgs.mongosh;
in
{
  name = testName;
  meta.maintainers = with pkgs.lib.maintainers; [
    phile314
    niklaskorz
  ];

  nodes.mongodb = {
    services.mongodb.enable = true;
  };

  testScript = ''
    start_all()

    with subtest("start mongodb"):
        mongodb.wait_for_unit("mongodb.service")
        mongodb.wait_for_open_port(27017)

    with subtest("insert and find a document"):
        result = mongodb.succeed("${mongoshExe} ${testQuery}")
        print("Test output:", result)
        assert result.strip() == "hello"
  '';
}