blob: 2fef636251401b1986aeffeec3be3b994f95e00a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import ./make-test-python.nix ({ pkgs, ...} :
let
port = 10004;
tcpPort = 10005;
httpPort = 10080;
tcpStreamPort = 10006;
bufferSize = 742;
in {
name = "snapcast";
meta = with pkgs.lib.maintainers; {
maintainers = [ hexa ];
};
nodes = {
server = {
services.snapserver = {
enable = true;
port = port;
tcp.port = tcpPort;
http.port = httpPort;
buffer = bufferSize;
streams = {
mpd = {
type = "pipe";
location = "/run/snapserver/mpd";
query.mode = "create";
};
bluetooth = {
type = "pipe";
location = "/run/snapserver/bluetooth";
};
tcp = {
type = "tcp";
location = "127.0.0.1:${toString tcpStreamPort}";
};
};
};
};
client = {
environment.systemPackages = [ pkgs.snapcast ];
};
};
testScript = ''
import json
get_rpc_version = {"id": "1", "jsonrpc": "2.0", "method": "Server.GetRPCVersion"}
start_all()
server.wait_for_unit("snapserver.service")
server.wait_until_succeeds("ss -ntl | grep -q ${toString port}")
server.wait_until_succeeds("ss -ntl | grep -q ${toString tcpPort}")
server.wait_until_succeeds("ss -ntl | grep -q ${toString httpPort}")
server.wait_until_succeeds("ss -ntl | grep -q ${toString tcpStreamPort}")
with subtest("check that pipes are created"):
server.succeed("test -p /run/snapserver/mpd")
server.succeed("test -p /run/snapserver/bluetooth")
with subtest("test tcp json-rpc"):
server.succeed(f"echo '{json.dumps(get_rpc_version)}' | nc -w 1 localhost ${toString tcpPort}")
with subtest("test http json-rpc"):
server.succeed(
"curl --fail http://localhost:${toString httpPort}/jsonrpc -d '{json.dumps(get_rpc_version)}'"
)
with subtest("test a connection"):
client.execute("systemd-run snapclient -h server -p ${toString port}")
server.wait_until_succeeds(
"journalctl -o cat -u snapserver.service | grep -q 'Hello from'"
)
client.wait_until_succeeds("journalctl -o cat -u run-\* | grep -q ${toString bufferSize}")
'';
})
|