at master 890 B view raw
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 offline 16 phile314 17 niklaskorz 18 ]; 19 20 nodes.mongodb = { 21 services.mongodb.enable = true; 22 }; 23 24 testScript = '' 25 start_all() 26 27 with subtest("start mongodb"): 28 mongodb.wait_for_unit("mongodb.service") 29 mongodb.wait_for_open_port(27017) 30 31 with subtest("insert and find a document"): 32 result = mongodb.succeed("${mongoshExe} ${testQuery}") 33 print("Test output:", result) 34 assert result.strip() == "hello" 35 ''; 36}