2016-09-13 18:38:45 +03:00
|
|
|
# This test start mongodb, runs a query using mongo shell
|
|
|
|
|
2020-03-26 15:46:22 +03:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
2019-08-04 09:25:56 +03:00
|
|
|
let
|
|
|
|
testQuery = pkgs.writeScript "nixtest.js" ''
|
|
|
|
db.greetings.insert({ "greeting": "hello" });
|
|
|
|
print(db.greetings.findOne().greeting);
|
|
|
|
'';
|
2016-09-13 18:38:45 +03:00
|
|
|
|
2019-08-04 09:25:56 +03:00
|
|
|
runMongoDBTest = pkg: ''
|
2020-03-26 15:46:22 +03:00
|
|
|
node.execute("(rm -rf data || true) && mkdir data")
|
|
|
|
node.execute(
|
|
|
|
"${pkg}/bin/mongod --fork --logpath logs --dbpath data"
|
|
|
|
)
|
|
|
|
node.wait_for_open_port(27017)
|
2019-08-04 09:25:56 +03:00
|
|
|
|
2020-03-26 15:46:22 +03:00
|
|
|
assert "hello" in node.succeed(
|
2020-07-07 21:53:31 +03:00
|
|
|
"${pkg}/bin/mongo ${testQuery}"
|
2020-03-26 15:46:22 +03:00
|
|
|
)
|
2019-08-04 09:25:56 +03:00
|
|
|
|
2020-03-26 15:46:22 +03:00
|
|
|
node.execute(
|
|
|
|
"${pkg}/bin/mongod --shutdown --dbpath data"
|
|
|
|
)
|
|
|
|
node.wait_for_closed_port(27017)
|
2019-08-04 09:25:56 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
name = "mongodb";
|
2021-01-10 22:08:30 +03:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2023-12-09 12:45:33 +03:00
|
|
|
maintainers = [ bluescreen303 offline phile314 ];
|
2019-08-04 09:25:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
node = {...}: {
|
|
|
|
environment.systemPackages = with pkgs; [
|
2022-03-02 13:55:53 +03:00
|
|
|
mongodb-4_4
|
|
|
|
mongodb-5_0
|
2019-08-04 09:25:56 +03:00
|
|
|
];
|
|
|
|
};
|
2016-09-13 18:38:45 +03:00
|
|
|
};
|
|
|
|
|
2020-03-26 15:46:22 +03:00
|
|
|
testScript = ''
|
|
|
|
node.start()
|
|
|
|
''
|
2022-03-02 13:55:53 +03:00
|
|
|
+ runMongoDBTest pkgs.mongodb-4_4
|
|
|
|
+ runMongoDBTest pkgs.mongodb-5_0
|
2020-03-26 15:46:22 +03:00
|
|
|
+ ''
|
|
|
|
node.shutdown()
|
|
|
|
'';
|
2019-08-04 09:25:56 +03:00
|
|
|
})
|