nixos/tests/mpd: update and format
mpc-cli is now mpc
This commit is contained in:
parent
178ea7bbd5
commit
77ec23d6af
@ -1,12 +1,13 @@
|
|||||||
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
import ./make-test-python.nix (
|
||||||
|
{ pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
track = pkgs.fetchurl {
|
track = pkgs.fetchurl {
|
||||||
# Sourced from http://freemusicarchive.org/music/Blue_Wave_Theory/Surf_Music_Month_Challenge/Skyhawk_Beach_fade_in
|
# Sourced from http://freemusicarchive.org/music/Blue_Wave_Theory/Surf_Music_Month_Challenge/Skyhawk_Beach_fade_in
|
||||||
# License: http://creativecommons.org/licenses/by-sa/4.0/
|
|
||||||
|
|
||||||
name = "Blue_Wave_Theory-Skyhawk_Beach.mp3";
|
name = "Blue_Wave_Theory-Skyhawk_Beach.mp3";
|
||||||
url = "https://freemusicarchive.org/file/music/ccCommunity/Blue_Wave_Theory/Surf_Music_Month_Challenge/Blue_Wave_Theory_-_04_-_Skyhawk_Beach.mp3";
|
url = "https://freemusicarchive.org/file/music/ccCommunity/Blue_Wave_Theory/Surf_Music_Month_Challenge/Blue_Wave_Theory_-_04_-_Skyhawk_Beach.mp3";
|
||||||
sha256 = "0xw417bxkx4gqqy139bb21yldi37xx8xjfxrwaqa0gyw19dl6mgp";
|
hash = "sha256-91VDWwrcP6Cw4rk72VHvZ8RGfRBrpRE8xo/02dcJhHc=";
|
||||||
|
meta.license = lib.licenses.cc-by-sa-40;
|
||||||
};
|
};
|
||||||
|
|
||||||
defaultCfg = rec {
|
defaultCfg = rec {
|
||||||
@ -16,42 +17,56 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
|
|||||||
musicDirectory = "${dataDir}/music";
|
musicDirectory = "${dataDir}/music";
|
||||||
};
|
};
|
||||||
|
|
||||||
defaultMpdCfg = with defaultCfg; {
|
defaultMpdCfg = {
|
||||||
inherit dataDir musicDirectory user group;
|
inherit (defaultCfg)
|
||||||
|
dataDir
|
||||||
|
musicDirectory
|
||||||
|
user
|
||||||
|
group
|
||||||
|
;
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
musicService = { user, group, musicDirectory }: {
|
musicService =
|
||||||
description = "Sets up the music file(s) for MPD to use.";
|
{
|
||||||
requires = [ "mpd.service" ];
|
user,
|
||||||
after = [ "mpd.service" ];
|
group,
|
||||||
wantedBy = [ "default.target" ];
|
musicDirectory,
|
||||||
script = ''
|
}:
|
||||||
cp ${track} ${musicDirectory}
|
{
|
||||||
'';
|
description = "Sets up the music file(s) for MPD to use.";
|
||||||
serviceConfig = {
|
requires = [ "mpd.service" ];
|
||||||
User = user;
|
after = [ "mpd.service" ];
|
||||||
Group = group;
|
wantedBy = [ "default.target" ];
|
||||||
|
script = ''
|
||||||
|
cp ${track} ${musicDirectory}
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
User = user;
|
||||||
|
Group = group;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
mkServer = { mpd, musicService, }:
|
mkServer =
|
||||||
{ boot.kernelModules = [ "snd-dummy" ];
|
{ mpd, musicService }:
|
||||||
|
{
|
||||||
|
boot.kernelModules = [ "snd-dummy" ];
|
||||||
services.mpd = mpd;
|
services.mpd = mpd;
|
||||||
systemd.services.musicService = musicService;
|
systemd.services.musicService = musicService;
|
||||||
};
|
};
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
name = "mpd";
|
name = "mpd";
|
||||||
meta = with pkgs.lib.maintainers; {
|
meta = {
|
||||||
maintainers = [ emmanuelrosa ];
|
maintainers = with lib.maintainers; [ emmanuelrosa ];
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes =
|
nodes = {
|
||||||
{ client =
|
client = { ... }: { };
|
||||||
{ ... }: { };
|
|
||||||
|
|
||||||
serverALSA =
|
serverALSA =
|
||||||
{ ... }: lib.mkMerge [
|
{ ... }:
|
||||||
|
lib.mkMerge [
|
||||||
(mkServer {
|
(mkServer {
|
||||||
mpd = defaultMpdCfg // {
|
mpd = defaultMpdCfg // {
|
||||||
network.listenAddress = "any";
|
network.listenAddress = "any";
|
||||||
@ -63,13 +78,14 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
|
|||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
musicService = with defaultMpdCfg; musicService { inherit user group musicDirectory; };
|
musicService = musicService { inherit (defaultMpdCfg) user group musicDirectory; };
|
||||||
})
|
})
|
||||||
{ networking.firewall.allowedTCPPorts = [ 6600 ]; }
|
{ networking.firewall.allowedTCPPorts = [ 6600 ]; }
|
||||||
];
|
];
|
||||||
|
|
||||||
serverPulseAudio =
|
serverPulseAudio =
|
||||||
{ ... }: lib.mkMerge [
|
{ ... }:
|
||||||
|
lib.mkMerge [
|
||||||
(mkServer {
|
(mkServer {
|
||||||
mpd = defaultMpdCfg // {
|
mpd = defaultMpdCfg // {
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
@ -80,7 +96,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
musicService = with defaultCfg; musicService { inherit user group musicDirectory; };
|
musicService = musicService { inherit (defaultMpdCfg) user group musicDirectory; };
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
hardware.pulseaudio = {
|
hardware.pulseaudio = {
|
||||||
@ -94,40 +110,41 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
mpc = "${pkgs.mpc-cli}/bin/mpc --wait"
|
mpc = "${lib.getExe pkgs.mpc} --wait"
|
||||||
|
|
||||||
# Connects to the given server and attempts to play a tune.
|
# Connects to the given server and attempts to play a tune.
|
||||||
def play_some_music(server):
|
def play_some_music(server):
|
||||||
server.wait_for_unit("mpd.service")
|
server.wait_for_unit("mpd.service")
|
||||||
server.succeed(f"{mpc} update")
|
server.succeed(f"{mpc} update")
|
||||||
_, tracks = server.execute(f"{mpc} ls")
|
_, tracks = server.execute(f"{mpc} ls")
|
||||||
|
|
||||||
for track in tracks.splitlines():
|
for track in tracks.splitlines():
|
||||||
server.succeed(f"{mpc} add {track}")
|
server.succeed(f"{mpc} add {track}")
|
||||||
|
|
||||||
_, added_tracks = server.execute(f"{mpc} playlist")
|
_, added_tracks = server.execute(f"{mpc} playlist")
|
||||||
|
|
||||||
# Check we succeeded adding audio tracks to the playlist
|
# Check we succeeded adding audio tracks to the playlist
|
||||||
assert len(added_tracks.splitlines()) > 0
|
assert len(added_tracks.splitlines()) > 0
|
||||||
|
|
||||||
server.succeed(f"{mpc} play")
|
server.succeed(f"{mpc} play")
|
||||||
|
|
||||||
_, output = server.execute(f"{mpc} status")
|
_, output = server.execute(f"{mpc} status")
|
||||||
# Assure audio track is playing
|
# Assure audio track is playing
|
||||||
assert "playing" in output
|
assert "playing" in output
|
||||||
|
|
||||||
server.succeed(f"{mpc} stop")
|
server.succeed(f"{mpc} stop")
|
||||||
|
|
||||||
|
|
||||||
play_some_music(serverALSA)
|
play_some_music(serverALSA)
|
||||||
play_some_music(serverPulseAudio)
|
play_some_music(serverPulseAudio)
|
||||||
|
|
||||||
client.wait_for_unit("multi-user.target")
|
client.wait_for_unit("multi-user.target")
|
||||||
client.succeed(f"{mpc} -h serverALSA status")
|
client.succeed(f"{mpc} -h serverALSA status")
|
||||||
|
|
||||||
# The PulseAudio-based server is configured not to accept external client connections
|
# The PulseAudio-based server is configured not to accept external client connections
|
||||||
# to perform the following test:
|
# to perform the following test:
|
||||||
client.fail(f"{mpc} -h serverPulseAudio status")
|
client.fail(f"{mpc} -h serverPulseAudio status")
|
||||||
'';
|
'';
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user