summaryrefslogtreecommitdiff
path: root/test.nix
diff options
context:
space:
mode:
authorParthiv Seetharaman <pachum99@myrdd.info>2022-02-02 12:37:54 -0800
committerParthiv Seetharaman <pachum99@myrdd.info>2022-02-02 12:40:17 -0800
commit47d65f14fc245e41a373c9500a7437dff12b4ed6 (patch)
tree74746e8e8f0029084408d760c70db79dbf12b309 /test.nix
parent6c50a62830d41428dafd8ffc73de398ab41c08a8 (diff)
re-organize repo to pass system and inputs around
follows super stupid flakes contract in the unofficial flakes roadmap
Diffstat (limited to 'test.nix')
-rw-r--r--test.nix240
1 files changed, 122 insertions, 118 deletions
diff --git a/test.nix b/test.nix
index 0257623..fd6e3f0 100644
--- a/test.nix
+++ b/test.nix
@@ -1,123 +1,127 @@
-{ pkgs ? import <nixpkgs> { } }:
-(import "${pkgs.path}/nixos/tests/make-test-python.nix" (
- { pkgs, ... }:
- let
- homeserverURL = "http://homeserver:8008";
- homeserverDomain = "example.com";
-
- 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, ... }: {
- imports = [ ./module ];
- services.dendrite = {
- enable = true;
- settings = {
- global.server_name = homeserverDomain;
- global.private_key = private_key;
- client_api.registration_disabled = false;
- };
+{ system ? builtins.currentSystem
+, inputs ? (import ./.).inputs
+}:
+let
+ pkgs = inputs.nixpkgs.legacyPackages.${system};
+
+ homeserverURL = "http://homeserver:8008";
+ homeserverDomain = "example.com";
+
+ private_key = pkgs.runCommand "matrix_key.pem" {
+ buildInputs = [ pkgs.dendrite ];
+ } "generate-keys --private-key $out";
+in
+ {
+ matrix-appservices = pkgs.nixosTest {
+ name = "matrix-appservices";
+ meta = with pkgs.lib; {
+ maintainers = teams.matrix.members;
+ };
+
+ nodes = {
+ homeserver = { pkgs, ... }: {
+ imports = [ ./module ];
+ services.dendrite = {
+ enable = true;
+ settings = {
+ global.server_name = homeserverDomain;
+ global.private_key = private_key;
+ client_api.registration_disabled = false;
};
-
- networking.firewall.allowedTCPPorts = [ 8008 ];
-
- services.matrix-appservices = {
- inherit homeserverDomain homeserverURL;
- addRegistrationFiles = true;
- homeserver = "dendrite";
- services = {
- discord = {
- port = 29180;
- package = pkgs.mx-puppet-discord;
- format = "mx-puppet";
- };
+ };
+
+ networking.firewall.allowedTCPPorts = [ 8008 ];
+
+ services.matrix-appservices = {
+ inherit homeserverDomain homeserverURL;
+ addRegistrationFiles = true;
+ homeserver = "dendrite";
+ services = {
+ discord = {
+ port = 29180;
+ package = pkgs.mx-puppet-discord;
+ format = "mx-puppet";
};
};
};
-
- 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)
-
- # Invite whatsapp user to room
- response = await client.room_invite(
- room_id,
- "@_discordpuppet_bot:${homeserverDomain}"
- )
-
- # 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": "ping"
- }
- )
-
- # Sync responses
- response = await client.sync(timeout=30000)
-
- response = await client.joined_members(room_id)
-
- # Check the message was received by dendrite
- # last_message = response.rooms.join[room_id].timeline.events[-1].body
-
- # 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)
- homeserver.wait_for_unit("matrix-as-discord.service")
-
- with subtest("ensure messages can be exchanged"):
- client.succeed("do_test")
- '';
-
- }
-)) { inherit (pkgs) pkgs system; }
+
+ 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)
+
+ # Invite whatsapp user to room
+ response = await client.room_invite(
+ room_id,
+ "@_discordpuppet_bot:${homeserverDomain}"
+ )
+
+ # 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": "ping"
+ }
+ )
+
+ # Sync responses
+ response = await client.sync(timeout=30000)
+
+ response = await client.joined_members(room_id)
+
+ # Check the message was received by dendrite
+ # last_message = response.rooms.join[room_id].timeline.events[-1].body
+ # assert last_message = "ping"
+
+ # 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)
+ homeserver.wait_for_unit("matrix-as-discord.service")
+
+ with subtest("ensure messages can be exchanged"):
+ client.succeed("do_test")
+ '';
+
+ };
+ }