0
0
mirror of https://github.com/cucumber-sp/yandex-music-linux.git synced 2025-04-06 01:03:44 +03:00

nix: introduce tests

Introduce set of tests based on NixOS test framework.
This commit is contained in:
Yury Shvedov 2025-03-09 16:13:18 +03:00
parent d45af61f82
commit 30847e331a
6 changed files with 218 additions and 9 deletions

View File

@ -101,3 +101,20 @@ jobs:
- name: Build yandex-music without flakes binaries
run: nix build --impure .#yandex-music-noflakes
nix-test:
runs-on: ubuntu-latest
env:
NIXPKGS_ALLOW_UNFREE: 1
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ (inputs.ref || '') }}
- name: Install nix
uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Run NixOS tests
run: nix build --impure .#tests

View File

@ -40,6 +40,7 @@ Native YandexMusic client for Linux. Built using repacking of Windows client (El
- [Run with flakes](#run-with-flakes)
- [Run old style](#run-old-style)
- [Install to NixOS](#install-to-nixos)
- [NixOS tests](#nixos-tests)
- [Star History](#star-history)
@ -337,6 +338,40 @@ nix-build --expr '(import <nixpkgs> {}).callPackage ./nix {}'
programs.yandex-music.enable = true;
programs.yandex-music.tray.enable = true; # to enable tray support
```
#### NixOS tests
This project uses [NixOS Testing
framework](https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests) to
perform generic run-tests of NixOS module and built app.
It runs automatically by github actions, but you may want to perform tests on
your own PC.
The root flake exports package `tests` with symlinks to artefact of all tests.
So you can run them by
```bash
nix build .#tests
```
Each test is complete qemu VM with NixOS onboard and configured yandex-music
application. The test performs withing the result package building inside nix
sandbox. The simple python script perform all the basic checks. The tests are
differs between each other by configuration options to yandex-music module. You
can see all of them [here](./nix/test.nix#L46).
You can run each test separately as sub-attr of `tests` package, e.g:
```bash
nix build .#tests.trayMonoWhite
```
You may want to see logs of each test (even failed) with `nix log` command, e.g:
```bash
nix log .#tests.customTitleBar
```
## Star History

View File

@ -21,9 +21,14 @@
pkgs.callPackage ./nix {
inherit ymExe;
};
modules = isHm: rec {
modules =
{
isHm ? false,
isTest ? false,
}:
rec {
yandex-music = {
imports = [ (import ./nix/module.nix { inherit isHm yandex-music-with; }) ];
imports = [ (import ./nix/module.nix { inherit isHm isTest yandex-music-with; }) ];
};
default = yandex-music;
};
@ -38,13 +43,17 @@
yandex-music = yandex-music-with pkgs;
yandex-music-noflakes = pkgs.callPackage ./nix { };
default = yandex-music;
tests = pkgs.callPackage ./nix/test.nix {
nixosModule = (modules { isTest = true; }).yandex-music;
inherit yandex-music-with;
};
};
formatter = pkgs.nixfmt-rfc-style;
}
)
// {
nixosModules = modules false;
homeManagerModules = modules true;
nixosModules = modules { };
homeManagerModules = modules { isHm = true; };
nixosModule = self.nixosModules.default;
};

View File

@ -1,6 +1,7 @@
{
yandex-music-with,
isHm ? false,
isTest ? false,
}:
{
lib,
@ -13,14 +14,18 @@ let
in
{
/*
The NixOS test framework disallow to extend `nixpkgs.overlays` configuration
option, so we make it here conditionally.
*/
imports = [
{
(lib.mkIf (!isTest) {
nixpkgs.overlays = [
(final: prev: {
yandex-music = yandex-music-with prev;
})
];
}
})
];
options = {

62
nix/test-suite.nix Normal file
View File

@ -0,0 +1,62 @@
/*
This test suite uses nixos common x11 and user-account test configurations.
Those configurations use auto-login to ice-wm desktop manager.
This test configuration enables yandex-music application, launches it and
check for window existence. Additionally it takes screenshot after successful
launch to allow to validate state manually. The result may miss the content
inside window because of lack of GPU support.
TODO(Shvedov): We should to perform automatic checks of screen state.
*/
{
testers,
path,
# The yandex-music module
nixosModule,
# The extra configuration
configuration ? { },
# The extra code of test script
extraTestScript ? "",
# The name of test
name ? "yandex-music-test",
}:
testers.runNixOSTest {
inherit name;
nodes.machine =
let
tests = "${path}/nixos/tests/common/";
user = "alice";
in
{
imports = [
nixosModule
"${tests}/x11.nix"
"${tests}/user-account.nix"
configuration
];
test-support.displayManager.auto.user = user;
programs.yandex-music.enable = true;
};
testScript =
''
# We have to execute command with su beckause all commands performs under
# the root user.
def mk_command(command, tail = "", fork = False):
if fork:
tail = f"{tail} >&2 &"
return f"su -c '{command}' - alice {tail}"
machine.wait_for_x()
machine.execute(mk_command("yandex-music", fork = True))
check_command = mk_command('xwininfo -root -tree', tail = "| grep 'Яндекс Музыка'")
machine.wait_until_succeeds(check_command, 120)
machine.sleep(40)
machine.succeed(check_command)
machine.screenshot("screen")
''
+ extraTestScript;
}

81
nix/test.nix Normal file
View File

@ -0,0 +1,81 @@
/*
This is set of tests of yandex-music application. The main purpose of this
test is to check the NixOS module for yandex-music and whether its runs
successfully with such configuration.
*/
{
pkgs,
yandex-music-with,
nixosModule,
linkFarm,
lib,
}:
let
# Extend packages with our package to overcome the limitation of nixOSTest
# modules regarding the overlays.
pkgs' = pkgs.extend (cur: prev: { yandex-music = yandex-music-with prev; });
removeNameAttr = attrs: lib.removeAttrs attrs [ "name" ];
test-suite =
{
name ? "yandex-music-test",
...
}@configuration:
pkgs'.callPackage ./test-suite.nix {
inherit nixosModule name;
configuration = removeNameAttr configuration;
};
yandex-music-config = cfg: {
programs.yandex-music = cfg;
};
yandex-music-test-suite =
{
name,
...
}@cfg:
test-suite (
(yandex-music-config (removeNameAttr cfg))
// {
name = "yandex-music-test-${name}";
}
);
/*
This is set of similar tests with slightly different configuration options
for yandex-music module. All they will be joined together to package with
symlinks to all results.
*/
tests = {
base = test-suite { };
trayDefault = yandex-music-test-suite {
tray.enable = true;
name = "tray-default";
};
trayAlways = yandex-music-test-suite {
tray.enable = true;
tray.always = true;
name = "tray-always";
};
trayMonoBlack = yandex-music-test-suite {
tray.enable = true;
tray.style = 2;
name = "tray-mono-black";
};
trayMonoWhite = yandex-music-test-suite {
tray.enable = true;
tray.style = 3;
name = "tray-mono-white";
};
devTools = yandex-music-test-suite {
devTools.enable = true;
name = "dev-tools";
};
customTitleBar = yandex-music-test-suite {
customTitleBar.enable = true;
name = "custom-title-bar";
};
animatiosFpsZero = yandex-music-test-suite {
vibeAnimationMaxFps = 0;
name = "animation-fps-zero";
};
};
in
(linkFarm "yandex-music-test-all" tests) // tests