summary refs log tree commit diff
path: root/nixos/tests/mongodb.nix
blob: ee7fc50f7ecc0a6c2b2c21e402c39f1137eae34c (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
# This test start mongodb, runs a query using mongo shell

import ./make-test-python.nix ({ pkgs, ... }:
  let
    testQuery = pkgs.writeScript "nixtest.js" ''
      db.greetings.insert({ "greeting": "hello" });
      print(db.greetings.findOne().greeting);
    '';

    runMongoDBTest = pkg: ''
      node.execute("(rm -rf data || true) && mkdir data")
      node.execute(
          "${pkg}/bin/mongod --fork --logpath logs --dbpath data"
      )
      node.wait_for_open_port(27017)

      assert "hello" in node.succeed(
          "mongo ${testQuery}"
      )

      node.execute(
          "${pkg}/bin/mongod --shutdown --dbpath data"
      )
      node.wait_for_closed_port(27017)
    '';

  in {
    name = "mongodb";
    meta = with pkgs.stdenv.lib.maintainers; {
      maintainers = [ bluescreen303 offline cstrahan rvl phile314 ];
    };

    nodes = {
      node = {...}: {
        environment.systemPackages = with pkgs; [
#          mongodb-3_4
          mongodb-3_6
          mongodb-4_0
        ];
      };
    };

    testScript = ''
      node.start()
    ''
#      + runMongoDBTest pkgs.mongodb-3_4
      + runMongoDBTest pkgs.mongodb-3_6 
      + runMongoDBTest pkgs.mongodb-4_0
      + ''
        node.shutdown()
      '';
  })