nixpkgs/nixos/tests/redis.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.5 KiB
Nix
Raw Normal View History

{
2024-04-05 12:40:34 +02:00
system ? builtins.currentSystem,
config ? { },
pkgs ? import ../../.. { inherit system config; },
lib ? pkgs.lib,
}:
let
makeTest = import ./make-test-python.nix;
mkTestName =
pkg: "${pkg.pname}_${builtins.replaceStrings [ "." ] [ "" ] (lib.versions.majorMinor pkg.version)}";
redisPackages = {
inherit (pkgs) redis keydb;
2019-08-31 20:17:33 +02:00
};
2024-04-05 12:40:34 +02:00
makeRedisTest =
{
package,
name ? mkTestName package,
}:
makeTest {
inherit name;
meta.maintainers = [
lib.maintainers.flokli
lib.teams.helsinki-systems.members
];
nodes = {
machine =
{ lib, ... }:
{
services = {
redis = {
inherit package;
servers."".enable = true;
servers."test".enable = true;
};
};
users.users = lib.listToAttrs (
map
(
suffix:
lib.nameValuePair "member${suffix}" {
createHome = false;
description = "A member of the redis${suffix} group";
isNormalUser = true;
extraGroups = [ "redis${suffix}" ];
}
)
[
""
"-test"
]
);
};
};
2019-08-31 20:17:33 +02:00
2024-04-05 12:40:34 +02:00
testScript =
{ nodes, ... }:
let
inherit (nodes.machine.services) redis;
in
''
start_all()
machine.wait_for_unit("redis")
machine.wait_for_unit("redis-test")
2021-10-23 05:44:07 +02:00
2024-04-05 12:40:34 +02:00
# The unnamed Redis server still opens a port for backward-compatibility
machine.wait_for_open_port(6379)
2024-04-05 12:40:34 +02:00
machine.wait_for_file("${redis.servers."".unixSocket}")
machine.wait_for_file("${redis.servers."test".unixSocket}")
2021-10-23 05:44:07 +02:00
2024-04-05 12:40:34 +02:00
# The unix socket is accessible to the redis group
machine.succeed('su member -c "${pkgs.redis}/bin/redis-cli ping | grep PONG"')
machine.succeed('su member-test -c "${pkgs.redis}/bin/redis-cli ping | grep PONG"')
2024-04-05 12:40:34 +02:00
machine.succeed("${pkgs.redis}/bin/redis-cli ping | grep PONG")
machine.succeed("${pkgs.redis}/bin/redis-cli -s ${redis.servers."".unixSocket} ping | grep PONG")
machine.succeed("${pkgs.redis}/bin/redis-cli -s ${
redis.servers."test".unixSocket
} ping | grep PONG")
'';
};
in
lib.mapAttrs (_: package: makeRedisTest { inherit package; }) redisPackages