1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-09-11 15:08:33 +01:00

nixos/sing-box: add basic test

This commit is contained in:
Nick Cao 2023-06-27 12:58:10 +08:00
parent d2483a8cc7
commit e3d52286b1
No known key found for this signature in database
3 changed files with 51 additions and 1 deletions

View file

@ -686,6 +686,7 @@ in {
shiori = handleTest ./shiori.nix {};
signal-desktop = handleTest ./signal-desktop.nix {};
simple = handleTest ./simple.nix {};
sing-box = handleTest ./sing-box.nix {};
slurm = handleTest ./slurm.nix {};
smokeping = handleTest ./smokeping.nix {};
snapcast = handleTest ./snapcast.nix {};

45
nixos/tests/sing-box.nix Normal file
View file

@ -0,0 +1,45 @@
import ./make-test-python.nix ({ lib, pkgs, ... }: {
name = "sing-box";
meta = {
maintainers = with lib.maintainers; [ nickcao ];
};
nodes.machine = { pkgs, ... }: {
environment.systemPackages = [ pkgs.curl ];
services.nginx.enable = true;
services.sing-box = {
enable = true;
settings = {
inbounds = [{
type = "mixed";
tag = "inbound";
listen = "127.0.0.1";
listen_port = 1080;
users = [{
username = "user";
password = { _secret = pkgs.writeText "password" "supersecret"; };
}];
}];
outbounds = [{
type = "direct";
tag = "outbound";
}];
};
};
};
testScript = ''
machine.wait_for_unit("nginx.service")
machine.wait_for_unit("sing-box.service")
machine.wait_for_open_port(80)
machine.wait_for_open_port(1080)
machine.succeed("curl --fail --max-time 10 --proxy http://user:supersecret@localhost:1080 http://localhost")
machine.fail("curl --fail --max-time 10 --proxy http://user:supervillain@localhost:1080 http://localhost")
machine.succeed("curl --fail --max-time 10 --proxy socks5://user:supersecret@localhost:1080 http://localhost")
'';
})

View file

@ -6,6 +6,7 @@
, buildPackages
, coreutils
, nix-update-script
, nixosTests
}:
buildGoModule rec {
@ -58,7 +59,10 @@ buildGoModule rec {
install -Dm444 -t "$out/lib/systemd/system/" release/config/sing-box{,@}.service
'';
passthru.updateScript = nix-update-script { };
passthru = {
updateScript = nix-update-script { };
tests = { inherit (nixosTests) sing-box; };
};
meta = with lib;{
homepage = "https://sing-box.sagernet.org";