tests: some minor cleanups

This commit is contained in:
Robert Helgesson 2023-07-08 10:12:35 +02:00
parent f288310b7a
commit af715ed857
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
12 changed files with 298 additions and 330 deletions

View file

@ -1,29 +1,27 @@
{ config, lib, pkgs, ... }: { config, ... }:
{ {
config = { home.stateVersion = "23.05";
home.stateVersion = "23.05";
programs.beets = { programs.beets = {
enable = true; enable = true;
package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; package = config.lib.test.mkStubPackage { outPath = "@beets@"; };
mpdIntegration = { mpdIntegration = {
enableStats = true; enableStats = true;
host = "10.0.0.42"; host = "10.0.0.42";
port = 6601; port = 6601;
};
}; };
nmt.script = ''
assertFileExists home-files/.config/beets/config.yaml
assertFileContent \
home-files/.config/beets/config.yaml \
${./mpdstats-external-expected.yaml}
assertFileExists home-files/.config/systemd/user/beets-mpdstats.service
assertFileContent \
home-files/.config/systemd/user/beets-mpdstats.service \
${./mpdstats-external-expected.service}
'';
}; };
nmt.script = ''
assertFileExists home-files/.config/beets/config.yaml
assertFileContent \
home-files/.config/beets/config.yaml \
${./mpdstats-external-expected.yaml}
assertFileExists home-files/.config/systemd/user/beets-mpdstats.service
assertFileContent \
home-files/.config/systemd/user/beets-mpdstats.service \
${./mpdstats-external-expected.service}
'';
} }

View file

@ -1,31 +1,29 @@
{ config, lib, pkgs, ... }: { config, ... }:
{ {
config = { home.stateVersion = "23.05";
home.stateVersion = "23.05";
services.mpd = { services.mpd = {
enable = true; enable = true;
musicDirectory = "/my/music/dir"; musicDirectory = "/my/music/dir";
network.port = 4242; network.port = 4242;
};
programs.beets = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@beets@"; };
mpdIntegration.enableStats = true;
};
nmt.script = ''
assertFileExists home-files/.config/beets/config.yaml
assertFileContent \
home-files/.config/beets/config.yaml \
${./mpdstats-expected.yaml}
assertFileExists home-files/.config/systemd/user/beets-mpdstats.service
assertFileContent \
home-files/.config/systemd/user/beets-mpdstats.service \
${./mpdstats-expected.service}
'';
}; };
programs.beets = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@beets@"; };
mpdIntegration.enableStats = true;
};
nmt.script = ''
assertFileExists home-files/.config/beets/config.yaml
assertFileContent \
home-files/.config/beets/config.yaml \
${./mpdstats-expected.yaml}
assertFileExists home-files/.config/systemd/user/beets-mpdstats.service
assertFileContent \
home-files/.config/systemd/user/beets-mpdstats.service \
${./mpdstats-expected.service}
'';
} }

View file

@ -1,20 +1,18 @@
{ config, lib, pkgs, ... }: { config, ... }:
{ {
config = { home.stateVersion = "23.05";
home.stateVersion = "23.05";
programs.beets = { programs.beets = {
enable = true; enable = true;
package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; package = config.lib.test.mkStubPackage { outPath = "@beets@"; };
mpdIntegration.enableUpdate = true; mpdIntegration.enableUpdate = true;
};
nmt.script = ''
assertFileExists home-files/.config/beets/config.yaml
assertFileContent \
home-files/.config/beets/config.yaml \
${./mpdupdate-expected.yaml}
'';
}; };
nmt.script = ''
assertFileExists home-files/.config/beets/config.yaml
assertFileContent \
home-files/.config/beets/config.yaml \
${./mpdupdate-expected.yaml}
'';
} }

View file

@ -1,55 +1,53 @@
{ config, lib, pkgs, ... }: { pkgs, ... }:
{ {
config = { programs.nnn = {
programs.nnn = { enable = true;
enable = true; bookmarks = {
bookmarks = { d = "~/Documents";
d = "~/Documents"; D = "~/Downloads";
D = "~/Downloads"; p = "~/Pictures";
p = "~/Pictures"; v = "~/Videos";
v = "~/Videos";
};
package = pkgs.nnnDummy;
extraPackages = with pkgs; [ foo bar ];
plugins = {
src = ./plugins;
mappings = {
c = "fzcd";
f = "finder";
v = "imgview";
};
};
}; };
package = pkgs.nnnDummy;
test.stubs = { extraPackages = with pkgs; [ foo bar ];
nnnDummy.buildScript = '' plugins = {
runHook preInstall src = ./plugins;
mappings = {
mkdir -p "$out/bin" c = "fzcd";
touch "$out/bin/nnn" f = "finder";
chmod +x "$out/bin/nnn" v = "imgview";
};
runHook postInstall
'';
foo = { name = "foo"; };
bar = { name = "bar"; };
};
nmt = {
description =
"Check if the binary is correctly wrapped and if the symlinks are made";
script = ''
assertDirectoryExists home-files/.config/nnn/plugins
for bookmark in 'export NNN_BMS' '~/Downloads' '~/Documents' '~/Pictures' '~/Videos'; do
assertFileRegex home-path/bin/nnn "$bookmark"
done
for plugin in 'export NNN_PLUG' 'fzcd' 'finder' 'imgview'; do
assertFileRegex home-path/bin/nnn "$plugin"
done
'';
}; };
}; };
test.stubs = {
nnnDummy.buildScript = ''
runHook preInstall
mkdir -p "$out/bin"
touch "$out/bin/nnn"
chmod +x "$out/bin/nnn"
runHook postInstall
'';
foo = { name = "foo"; };
bar = { name = "bar"; };
};
nmt = {
description =
"Check if the binary is correctly wrapped and if the symlinks are made";
script = ''
assertDirectoryExists home-files/.config/nnn/plugins
for bookmark in 'export NNN_BMS' '~/Downloads' '~/Documents' '~/Pictures' '~/Videos'; do
assertFileRegex home-path/bin/nnn "$bookmark"
done
for plugin in 'export NNN_PLUG' 'fzcd' 'finder' 'imgview'; do
assertFileRegex home-path/bin/nnn "$plugin"
done
'';
};
} }

View file

@ -1,47 +1,43 @@
{ config, lib, pkgs, ... }: { lib, pkgs, ... }:
with lib;
{ {
config = { programs.qutebrowser = {
programs.qutebrowser = { enable = true;
enable = true;
enableDefaultBindings = false; enableDefaultBindings = false;
keyBindings = { keyBindings = {
normal = { normal = {
"<Ctrl-v>" = "spawn mpv {url}"; "<Ctrl-v>" = "spawn mpv {url}";
",l" = ''config-cycle spellcheck.languages ["en-GB"] ["en-US"]''; ",l" = ''config-cycle spellcheck.languages ["en-GB"] ["en-US"]'';
"<F1>" = mkMerge [ "<F1>" = lib.mkMerge [
"config-cycle tabs.show never always" "config-cycle tabs.show never always"
"config-cycle statusbar.show in-mode always" "config-cycle statusbar.show in-mode always"
"config-cycle scrolling.bar never always" "config-cycle scrolling.bar never always"
]; ];
};
prompt = { "<Ctrl-y>" = "prompt-yes"; };
}; };
prompt = { "<Ctrl-y>" = "prompt-yes"; };
}; };
test.stubs.qutebrowser = { };
nmt.script = let
qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then
".qutebrowser/config.py"
else
".config/qutebrowser/config.py";
in ''
assertFileContent \
home-files/${qutebrowserConfig} \
${
pkgs.writeText "qutebrowser-expected-config.py" ''
config.load_autoconfig(False)
c.bindings.default = {}
config.bind(",l", "config-cycle spellcheck.languages [\"en-GB\"] [\"en-US\"]", mode="normal")
config.bind("<Ctrl-v>", "spawn mpv {url}", mode="normal")
config.bind("<F1>", "config-cycle tabs.show never always ;; config-cycle statusbar.show in-mode always ;; config-cycle scrolling.bar never always", mode="normal")
config.bind("<Ctrl-y>", "prompt-yes", mode="prompt")''
}
'';
}; };
test.stubs.qutebrowser = { };
nmt.script = let
qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then
".qutebrowser/config.py"
else
".config/qutebrowser/config.py";
in ''
assertFileContent \
home-files/${qutebrowserConfig} \
${
pkgs.writeText "qutebrowser-expected-config.py" ''
config.load_autoconfig(False)
c.bindings.default = {}
config.bind(",l", "config-cycle spellcheck.languages [\"en-GB\"] [\"en-US\"]", mode="normal")
config.bind("<Ctrl-v>", "spawn mpv {url}", mode="normal")
config.bind("<F1>", "config-cycle tabs.show never always ;; config-cycle statusbar.show in-mode always ;; config-cycle scrolling.bar never always", mode="normal")
config.bind("<Ctrl-y>", "prompt-yes", mode="prompt")''
}
'';
} }

View file

@ -1,33 +1,29 @@
{ config, lib, pkgs, ... }: { pkgs, ... }:
with lib;
{ {
config = { programs.qutebrowser = {
programs.qutebrowser = { enable = true;
enable = true;
quickmarks = { quickmarks = {
nixpkgs = "https://github.com/NixOS/nixpkgs"; nixpkgs = "https://github.com/NixOS/nixpkgs";
home-manager = "https://github.com/nix-community/home-manager"; home-manager = "https://github.com/nix-community/home-manager";
};
}; };
test.stubs.qutebrowser = { };
nmt.script = let
quickmarksFile = if pkgs.stdenv.hostPlatform.isDarwin then
".qutebrowser/quickmarks"
else
".config/qutebrowser/quickmarks";
in ''
assertFileContent \
home-files/${quickmarksFile} \
${
pkgs.writeText "qutebrowser-expected-quickmarks" ''
home-manager https://github.com/nix-community/home-manager
nixpkgs https://github.com/NixOS/nixpkgs''
}
'';
}; };
test.stubs.qutebrowser = { };
nmt.script = let
quickmarksFile = if pkgs.stdenv.hostPlatform.isDarwin then
".qutebrowser/quickmarks"
else
".config/qutebrowser/quickmarks";
in ''
assertFileContent \
home-files/${quickmarksFile} \
${
pkgs.writeText "qutebrowser-expected-quickmarks" ''
home-manager https://github.com/nix-community/home-manager
nixpkgs https://github.com/NixOS/nixpkgs''
}
'';
} }

View file

@ -1,50 +1,46 @@
{ config, lib, pkgs, ... }: { pkgs, ... }:
with lib;
{ {
config = { programs.qutebrowser = {
programs.qutebrowser = { enable = true;
enable = true;
settings = { settings = {
colors = { colors = {
hints = { hints = {
bg = "#000000"; bg = "#000000";
fg = "#ffffff"; fg = "#ffffff";
};
tabs.bar.bg = "#000000";
}; };
spellcheck.languages = [ "en-US" "sv-SE" ]; tabs.bar.bg = "#000000";
tabs.tabs_are_windows = true;
}; };
spellcheck.languages = [ "en-US" "sv-SE" ];
extraConfig = '' tabs.tabs_are_windows = true;
# Extra qutebrowser configuration.
'';
}; };
test.stubs.qutebrowser = { }; extraConfig = ''
# Extra qutebrowser configuration.
nmt.script = let
qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then
".qutebrowser/config.py"
else
".config/qutebrowser/config.py";
in ''
assertFileContent \
home-files/${qutebrowserConfig} \
${
pkgs.writeText "qutebrowser-expected-config.py" ''
config.load_autoconfig(False)
c.colors.hints.bg = "#000000"
c.colors.hints.fg = "#ffffff"
c.colors.tabs.bar.bg = "#000000"
c.spellcheck.languages = ["en-US", "sv-SE"]
c.tabs.tabs_are_windows = True
# Extra qutebrowser configuration.
''
}
''; '';
}; };
test.stubs.qutebrowser = { };
nmt.script = let
qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then
".qutebrowser/config.py"
else
".config/qutebrowser/config.py";
in ''
assertFileContent \
home-files/${qutebrowserConfig} \
${
pkgs.writeText "qutebrowser-expected-config.py" ''
config.load_autoconfig(False)
c.colors.hints.bg = "#000000"
c.colors.hints.fg = "#ffffff"
c.colors.tabs.bar.bg = "#000000"
c.spellcheck.languages = ["en-US", "sv-SE"]
c.tabs.tabs_are_windows = True
# Extra qutebrowser configuration.
''
}
'';
} }

View file

@ -1,24 +1,24 @@
{ config, lib, pkgs, ... }: { { pkgs, ... }:
config = {
programs.terminator = { {
enable = true; programs.terminator = {
config = { enable = true;
global_config.borderless = true; config = {
profiles.default.background_color = "#002b36"; global_config.borderless = true;
}; profiles.default.background_color = "#002b36";
}; };
test.stubs.terminator = { };
nmt.script = ''
assertFileContent home-files/.config/terminator/config ${
pkgs.writeText "expected" ''
[global_config]
borderless = True
[profiles]
[[default]]
background_color = "#002b36"''
}
'';
}; };
test.stubs.terminator = { };
nmt.script = ''
assertFileContent home-files/.config/terminator/config ${
pkgs.writeText "expected" ''
[global_config]
borderless = True
[profiles]
[[default]]
background_color = "#002b36"''
}
'';
} }

View file

@ -1,36 +1,32 @@
{ config, lib, pkgs, ... }: { lib, ... }:
with lib;
{ {
config = { programs.topgrade = {
programs.topgrade = { enable = true;
enable = true;
settings = mkMerge [ settings = lib.mkMerge [
{ {
disable = [ "sdkman" "flutter" "node" "nix" "home_manager" ]; disable = [ "sdkman" "flutter" "node" "nix" "home_manager" ];
remote_topgrades = [ "backup" "ci" ]; remote_topgrades = [ "backup" "ci" ];
remote_topgrade_path = "bin/topgrade"; remote_topgrade_path = "bin/topgrade";
} }
{ {
set_title = false; set_title = false;
cleanup = true; cleanup = true;
commands = { "Purge unused APT packages" = "sudo apt autoremove"; }; commands = { "Purge unused APT packages" = "sudo apt autoremove"; };
} }
]; ];
};
test.stubs.topgrade = { };
nmt.script = ''
assertFileContent \
home-files/.config/topgrade.toml \
${./settings-expected.toml}
'';
}; };
test.stubs.topgrade = { };
nmt.script = ''
assertFileContent \
home-files/.config/topgrade.toml \
${./settings-expected.toml}
'';
} }

View file

@ -1,7 +1,5 @@
# Test that keybindings.json is created correctly. # Test that keybindings.json is created correctly.
{ config, lib, pkgs, ... }: { pkgs, ... }:
with lib;
let let
bindings = [ bindings = [
@ -65,18 +63,16 @@ let
''; '';
in { in {
config = { programs.vscode = {
programs.vscode = { enable = true;
enable = true; keybindings = bindings;
keybindings = bindings; package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
};
nmt.script = ''
assertFileExists "home-files/${keybindingsPath}"
assertFileContent "home-files/${keybindingsPath}" "${expectedKeybindings}"
assertPathNotExists "home-files/${settingsPath}"
'';
}; };
nmt.script = ''
assertFileExists "home-files/${keybindingsPath}"
assertFileContent "home-files/${keybindingsPath}" "${expectedKeybindings}"
assertPathNotExists "home-files/${settingsPath}"
'';
} }

View file

@ -1,4 +1,4 @@
{ pkgs, config, ... }: { pkgs, ... }:
let let

View file

@ -1,52 +1,48 @@
{ config, lib, pkgs, ... }: { config, pkgs, ... }:
with lib;
{ {
config = { programs.zsh = {
programs.zsh = { enable = true;
zplug = {
enable = true; enable = true;
zplug = { zplugHome = pkgs.emptyDirectory;
enable = true; plugins = [
zplugHome = pkgs.emptyDirectory; {
plugins = [ name = "plugins/git";
{ tags = [ "from:oh-my-zsh" ];
name = "plugins/git"; }
tags = [ "from:oh-my-zsh" ]; {
} name = "lib/clipboard";
{ tags = [ "from:oh-my-zsh" ''if:"[[ $OSTYPE == *darwin* ]]"'' ];
name = "lib/clipboard"; }
tags = [ "from:oh-my-zsh" ''if:"[[ $OSTYPE == *darwin* ]]"'' ]; ];
}
];
};
}; };
test.stubs = {
zplug = { };
zsh = { };
};
nmt.script = ''
assertFileContains home-files/.zshrc \
'source @zplug@/share/zplug/init.zsh'
assertFileContains home-files/.zshrc \
'zplug "plugins/git", from:oh-my-zsh'
assertFileContains home-files/.zshrc \
'zplug "lib/clipboard", from:oh-my-zsh, if:"[[ $OSTYPE == *darwin* ]]"'
assertFileContains home-files/.zshrc \
'if ! zplug check; then
zplug install
fi'
assertFileRegex home-files/.zshrc \
'^zplug load$'
assertFileContains home-files/.zshrc \
'export ZPLUG_HOME=${config.programs.zsh.zplug.zplugHome}'
'';
}; };
test.stubs = {
zplug = { };
zsh = { };
};
nmt.script = ''
assertFileContains home-files/.zshrc \
'source @zplug@/share/zplug/init.zsh'
assertFileContains home-files/.zshrc \
'zplug "plugins/git", from:oh-my-zsh'
assertFileContains home-files/.zshrc \
'zplug "lib/clipboard", from:oh-my-zsh, if:"[[ $OSTYPE == *darwin* ]]"'
assertFileContains home-files/.zshrc \
'if ! zplug check; then
zplug install
fi'
assertFileRegex home-files/.zshrc \
'^zplug load$'
assertFileContains home-files/.zshrc \
'export ZPLUG_HOME=${config.programs.zsh.zplug.zplugHome}'
'';
} }