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 10:40:34 +00: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 18:17:33 +00:00
};
2024-04-05 10:40:34 +00: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 18:17:33 +00:00
2024-04-05 10:40:34 +00: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 03:44:07 +00:00
2024-04-05 10:40:34 +00:00
# The unnamed Redis server still opens a port for backward-compatibility
machine.wait_for_open_port(6379)
2024-04-05 10:40:34 +00:00
machine.wait_for_file("${redis.servers."".unixSocket}")
machine.wait_for_file("${redis.servers."test".unixSocket}")
2021-10-23 03:44:07 +00:00
2024-04-05 10:40:34 +00: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 10:40:34 +00: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