nixos/tests/dendrite: init (#121777)

master
Michael Lingelbach 2021-05-14 04:11:22 -07:00 committed by GitHub
parent 92dcaba935
commit 46284492f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 1 deletions

View File

@ -90,6 +90,7 @@ in
custom-ca = handleTest ./custom-ca.nix {};
croc = handleTest ./croc.nix {};
deluge = handleTest ./deluge.nix {};
dendrite = handleTest ./dendrite.nix {};
dhparams = handleTest ./dhparams.nix {};
discourse = handleTest ./discourse.nix {};
dnscrypt-proxy2 = handleTestOn ["x86_64-linux"] ./dnscrypt-proxy2.nix {};

99
nixos/tests/dendrite.nix Normal file
View File

@ -0,0 +1,99 @@
import ./make-test-python.nix (
{ pkgs, ... }:
let
homeserverUrl = "http://homeserver:8008";
private_key = pkgs.runCommand "matrix_key.pem" {
buildInputs = [ pkgs.dendrite ];
} "generate-keys --private-key $out";
in
{
name = "dendrite";
meta = with pkgs.lib; {
maintainers = teams.matrix.members;
};
nodes = {
homeserver = { pkgs, ... }: {
services.dendrite = {
enable = true;
settings = {
global.server_name = "test-dendrite-server.com";
global.private_key = private_key;
client_api.registration_disabled = false;
};
};
networking.firewall.allowedTCPPorts = [ 8008 ];
};
client = { pkgs, ... }: {
environment.systemPackages = [
(
pkgs.writers.writePython3Bin "do_test"
{ libraries = [ pkgs.python3Packages.matrix-nio ]; } ''
import asyncio
from nio import AsyncClient
async def main() -> None:
# Connect to dendrite
client = AsyncClient("http://homeserver:8008", "alice")
# Register as user alice
response = await client.register("alice", "my-secret-password")
# Log in as user alice
response = await client.login("my-secret-password")
# Create a new room
response = await client.room_create(federate=False)
room_id = response.room_id
# Join the room
response = await client.join(room_id)
# Send a message to the room
response = await client.room_send(
room_id=room_id,
message_type="m.room.message",
content={
"msgtype": "m.text",
"body": "Hello world!"
}
)
# Sync responses
response = await client.sync(timeout=30000)
# Check the message was received by dendrite
last_message = response.rooms.join[room_id].timeline.events[-1].body
assert last_message == "Hello world!"
# Leave the room
response = await client.room_leave(room_id)
# Close the client
await client.close()
asyncio.get_event_loop().run_until_complete(main())
''
)
];
};
};
testScript = ''
start_all()
with subtest("start the homeserver"):
homeserver.wait_for_unit("dendrite.service")
homeserver.wait_for_open_port(8008)
with subtest("ensure messages can be exchanged"):
client.succeed("do_test")
'';
}
)

View File

@ -1,4 +1,4 @@
{ lib, buildGoModule, fetchFromGitHub}:
{ lib, buildGoModule, fetchFromGitHub, nixosTests }:
buildGoModule rec {
pname = "matrix-dendrite";
@ -13,6 +13,10 @@ buildGoModule rec {
vendorSha256 = "1l1wydvi0yalas79cvhrqg563cvs57hg9rv6qnkw879r6smb2x1n";
passthru.tests = {
inherit (nixosTests) dendrite;
};
meta = with lib; {
homepage = "https://matrix.org";
description = "Dendrite is a second-generation Matrix homeserver written in Go!";