mirror of
https://github.com/spacebarchat/server.git
synced 2026-06-25 06:02:24 +00:00
97 lines
2.9 KiB
Nix
97 lines
2.9 KiB
Nix
{
|
|
self,
|
|
withIpc ? "unix",
|
|
}:
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
let
|
|
sb = import ../lib/mkEndpoint.nix;
|
|
isRabbitMqTest = lib.strings.hasPrefix "rabbitmq" withIpc;
|
|
in
|
|
{
|
|
name = "test-bundle-starts" + lib.optionalString (withIpc != "unix") ("_ipc=" + withIpc);
|
|
skipTypeCheck = true;
|
|
skipLint = true;
|
|
globalTimeout = 120;
|
|
|
|
nodes.machine = {
|
|
imports = [ self.nixosModules.default ];
|
|
|
|
services.spacebarchat-server =
|
|
let
|
|
cfg = {
|
|
enable = true;
|
|
apiEndpoint = sb.mkEndpoint "api.sb.localhost" 3001 false;
|
|
gatewayEndpoint = sb.mkEndpoint "gw.sb.localhost" 3002 false;
|
|
cdnEndpoint = sb.mkEndpoint "cdn.sb.localhost" 3003 false;
|
|
serverName = "sb.localhost";
|
|
extraEnvironment = {
|
|
DATABASE = "postgres://postgres:postgres@127.0.0.1/spacebar";
|
|
LOG_REQUESTS = "-"; # Log all requests
|
|
LOG_VALIDATION_ERRORS = true;
|
|
};
|
|
ipcMethod = withIpc;
|
|
|
|
settings = {
|
|
rabbitmq = {
|
|
host = lib.mkIf isRabbitMqTest "amqp://guest:guest@127.0.0.1:5672";
|
|
};
|
|
};
|
|
|
|
nginx.enable = true;
|
|
};
|
|
in
|
|
lib.trace ("Testing with config: " + builtins.toJSON cfg) cfg;
|
|
services.nginx.enable = true;
|
|
services.rabbitmq.enable = isRabbitMqTest;
|
|
services.postgresql = {
|
|
enable = true;
|
|
initdbArgs = [
|
|
"--encoding=UTF8"
|
|
"--locale=C.UTF-8"
|
|
"--data-checksums"
|
|
"--allow-group-access"
|
|
];
|
|
enableTCPIP = true;
|
|
authentication = pkgs.lib.mkOverride 10 ''
|
|
# TYPE, DATABASE, USER, ADDRESS, METHOD
|
|
local all all trust
|
|
host all all 127.0.0.1/32 trust
|
|
host all all ::1/128 trust
|
|
host all all 0.0.0.0/0 md5
|
|
'';
|
|
initialScript = pkgs.writeText "backend-initScript" ''
|
|
CREATE ROLE spacebar WITH LOGIN PASSWORD 'spacebar' CREATEDB;
|
|
CREATE DATABASE spacebar;
|
|
GRANT ALL PRIVILEGES ON DATABASE spacebar TO spacebar;
|
|
'';
|
|
};
|
|
};
|
|
|
|
# https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests
|
|
# https://nixos.org/manual/nixpkgs/unstable/#tester-runNixOSTest
|
|
testScript = ''
|
|
machine.wait_for_unit("spacebar-api")
|
|
machine.wait_for_unit("spacebar-cdn")
|
|
machine.wait_for_unit("spacebar-gateway")
|
|
# Wait for unit doesn't mean the service is actually ready to accept connections
|
|
machine.wait_for_open_port(80)
|
|
machine.wait_for_open_port(3001)
|
|
machine.wait_for_open_port(3002)
|
|
machine.wait_for_open_port(3003)
|
|
|
|
# this should be working
|
|
machine.succeed("curl -f http://api.sb.localhost/.well-known/spacebar/client")
|
|
|
|
# check if metrics endpoint works on all services
|
|
machine.succeed("curl -f http://api.sb.localhost/metrics")
|
|
machine.succeed("curl -f http://gateway.sb.localhost/metrics")
|
|
machine.succeed("curl -f http://cdn.sb.localhost/metrics")
|
|
'';
|
|
}
|