Skip to content

Commit

Permalink
nixos/clash-meta: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Guanran928 committed Feb 11, 2024
1 parent 4362915 commit af430c3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ in {
cinnamon = handleTest ./cinnamon.nix {};
cinnamon-wayland = handleTest ./cinnamon-wayland.nix {};
cjdns = handleTest ./cjdns.nix {};
clash-meta = handleTest ./clash-meta.nix {};
clickhouse = handleTest ./clickhouse.nix {};
cloud-init = handleTest ./cloud-init.nix {};
cloud-init-hostname = handleTest ./cloud-init-hostname.nix {};
Expand Down
44 changes: 44 additions & 0 deletions nixos/tests/clash-meta.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import ./make-test-python.nix ({ pkgs, ... }: {
name = "clash-meta";
meta.maintainers = with pkgs.lib.maintainers; [ Guanran928 ];

nodes.machine = {
environment.systemPackages = [ pkgs.curl ];

services.nginx = {
enable = true;
statusPage = true;
};

services.clash-meta = {
enable = true;
configFile = pkgs.writeTextFile {
name = "config.yaml";
text = ''
mixed-port: 7890
external-controller: 127.0.0.1:9090
authentication:
- "user:supersecret"
'';
};
};
};

testScript = ''
# Wait until it starts
machine.wait_for_unit("nginx.service")
machine.wait_for_unit("clash-meta.service")
machine.wait_for_open_port(80)
machine.wait_for_open_port(7890)
machine.wait_for_open_port(9090)
# Proxy
machine.succeed("curl --fail --max-time 10 --proxy http://user:supersecret@localhost:7890 http://localhost")
machine.succeed("curl --fail --max-time 10 --proxy socks5://user:supersecret@localhost:7890 http://localhost")
machine.fail("curl --fail --max-time 10 --proxy http://user:supervillain@localhost:7890 http://localhost")
machine.fail("curl --fail --max-time 10 --proxy socks5://user:supervillain@localhost:7890 http://localhost")
# Web UI
machine.succeed("curl --fail http://localhost:9090") == '{"hello":"clash"}'
'';
})
5 changes: 5 additions & 0 deletions pkgs/tools/networking/clash-meta/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib
, fetchFromGitHub
, buildGoModule
, nixosTests
}:
buildGoModule rec {
pname = "clash-meta";
Expand Down Expand Up @@ -35,6 +36,10 @@ buildGoModule rec {
mv $out/bin/clash $out/bin/clash-meta
'';

passthru.tests = {
nginx = nixosTests.clash-meta;
};

meta = with lib; {
description = "Another Clash Kernel";
homepage = "https://github.com/MetaCubeX/Clash.Meta";
Expand Down

0 comments on commit af430c3

Please sign in to comment.