Skip to content

Commit

Permalink
nixos/tests/peertube: add test for plugins
Browse files Browse the repository at this point in the history
Co-authored-by: a-kenji <[email protected]>
  • Loading branch information
sbruder and a-kenji committed Sep 16, 2022
1 parent 0d64092 commit 47fc3aa
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ in {
parsedmarc = handleTest ./parsedmarc {};
pdns-recursor = handleTest ./pdns-recursor.nix {};
peerflix = handleTest ./peerflix.nix {};
peertube = handleTestOn ["x86_64-linux"] ./web-apps/peertube.nix {};
peertube = handleTestOn ["x86_64-linux"] ./web-apps/peertube {};
pgadmin4 = handleTest ./pgadmin4.nix {};
pgadmin4-standalone = handleTest ./pgadmin4-standalone.nix {};
pgjwt = handleTest ./pgjwt.nix {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ../make-test-python.nix ({pkgs, ...}:
import ../../make-test-python.nix ({pkgs, ...}:
{
name = "peertube";
meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];
Expand Down
7 changes: 7 additions & 0 deletions nixos/tests/web-apps/peertube/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ system ? builtins.currentSystem
, pkgs ? import ../../../.. { inherit system; }
}:
{
base = import ./base.nix { inherit system pkgs; };
plugins = import ./plugins.nix { inherit system pkgs; };
}
85 changes: 85 additions & 0 deletions nixos/tests/web-apps/peertube/plugins.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import ../../make-test-python.nix ({ pkgs, ... }: {
name = "peertube-plugins";
meta.maintainers = with pkgs.lib.maintainers; [ a-kenji sbruder ];

nodes = {
server = { lib, pkgs, ... }: {
services.peertube = {
enable = true;
localDomain = "peertube.local";
enableWebHttps = false;

database.createLocally = true;
redis.createLocally = true;

plugins = with pkgs.peertube.plugins; [
peertube-plugin-hello-world
];
};
specialisation = {
no-plugins.configuration = {
services.peertube.plugins = lib.mkForce [ ];
};
};
};
};

testScript = { nodes, ... }: ''
import json
import re
def get_config():
content = server.succeed("curl --fail http://localhost:9000/")
return json.loads(
json.loads(
'"'
+ re.search(
r'<script type="application\/javascript">window.PeerTubeServerConfig = "(.*?)"<\/script>',
content,
).group(1)
+ '"'
)
)
server.start()
# This waits for the peertube service starting,
# getting stopped by the plugin provisioning script
# and starting again.
server.wait_for_open_port(9000)
server.wait_for_closed_port(9000)
server.wait_for_open_port(9000)
config = get_config()
plugins = config["plugin"]["registered"]
assert len(plugins) == 1
hello_world_plugin = plugins[0]
assert hello_world_plugin["npmName"] == "peertube-plugin-hello-world"
assert (
hello_world_plugin["version"]
== "${pkgs.peertube.plugins.peertube-plugin-hello-world.version}"
)
client_scripts = [
f'http://localhost:9000/plugins/hello-world/{hello_world_plugin["version"]}/client-scripts/{script["script"]}'
for script in hello_world_plugin["clientScripts"].values()
]
server.succeed(f"curl --fail {client_scripts[0]}")
server.succeed(
"${nodes.server.config.system.build.toplevel}/specialisation/no-plugins/bin/switch-to-configuration test >&2"
)
# This again waits for peertube to be restarted
server.wait_for_closed_port(9000)
server.wait_for_open_port(9000)
config = get_config()
assert len(config["plugin"]["registered"]) == 0
'';
})
2 changes: 1 addition & 1 deletion pkgs/servers/peertube/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ in stdenv.mkDerivation rec {

passthru = {
plugins = callPackage ./plugins { };
tests.peertube = nixosTests.peertube;
tests = nixosTests.peertube;
};

meta = with lib; {
Expand Down

0 comments on commit 47fc3aa

Please sign in to comment.