mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
nixosTests.mongodb: actually use mongodb service module and add support for mongodb-ce
This commit is contained in:
parent
fd348f4354
commit
ac16c51570
1 changed files with 26 additions and 45 deletions
|
@ -1,56 +1,37 @@
|
|||
# This test start mongodb, runs a query using mongo shell
|
||||
{ pkgs, ... }:
|
||||
# This test starts mongodb and runs a query using mongo shell
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
# required for test execution on darwin
|
||||
pkgs = config.node.pkgs;
|
||||
testQuery = pkgs.writeScript "nixtest.js" ''
|
||||
db.greetings.insert({ "greeting": "hello" });
|
||||
db.greetings.insertOne({ "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(
|
||||
"${pkg}/bin/mongo ${testQuery}"
|
||||
)
|
||||
|
||||
node.execute(
|
||||
"${pkg}/bin/mongod --shutdown --dbpath data"
|
||||
)
|
||||
node.wait_for_closed_port(27017)
|
||||
'';
|
||||
|
||||
mongoshExe = lib.getExe pkgs.mongosh;
|
||||
in
|
||||
{
|
||||
name = "mongodb";
|
||||
meta = with pkgs.lib.maintainers; {
|
||||
maintainers = [
|
||||
bluescreen303
|
||||
offline
|
||||
phile314
|
||||
];
|
||||
meta.maintainers = with pkgs.lib.maintainers; [
|
||||
bluescreen303
|
||||
offline
|
||||
phile314
|
||||
niklaskorz
|
||||
];
|
||||
|
||||
nodes.mongodb = {
|
||||
services.mongodb.enable = true;
|
||||
};
|
||||
|
||||
nodes = {
|
||||
node =
|
||||
{ ... }:
|
||||
{
|
||||
environment.systemPackages = with pkgs; [
|
||||
# remember to update mongodb.passthru.tests if you change this
|
||||
mongodb-7_0
|
||||
];
|
||||
};
|
||||
};
|
||||
testScript = ''
|
||||
start_all()
|
||||
|
||||
testScript =
|
||||
''
|
||||
node.start()
|
||||
''
|
||||
+ runMongoDBTest pkgs.mongodb-7_0
|
||||
+ ''
|
||||
node.shutdown()
|
||||
'';
|
||||
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"
|
||||
'';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue