tests: improve test purity

Before the XDG variables would be set from the user's environment, if
available. This would break some tests.

With this change the tests should be fully deterministic.

Fixes #1190
This commit is contained in:
Robert Helgesson 2020-04-24 21:41:22 +02:00
parent cfaf213980
commit 95b95b1407
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
17 changed files with 21 additions and 54 deletions

View file

@ -14,7 +14,15 @@ let
modules = import ../modules/modules.nix { modules = import ../modules/modules.nix {
inherit lib pkgs; inherit lib pkgs;
check = false; check = false;
}; } ++ [
# Fix impurities. Without these some of the user's environment
# will leak into the tests through `builtins.getEnv`.
{
xdg.enable = true;
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
}
];
in in

View file

@ -4,3 +4,6 @@ export __HM_SESS_VARS_SOURCED=1
export V1="v1" export V1="v1"
export V2="v2-v1" export V2="v2-v1"
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"

View file

@ -1,4 +1,4 @@
. "/test-home/.nix-profile/etc/profile.d/hm-session-vars.sh" . "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"
if [ -e "$HOME/.profile" ]; then if [ -e "$HOME/.profile" ]; then
. "$HOME/.profile" . "$HOME/.profile"

View file

@ -4,8 +4,6 @@ with lib;
{ {
config = { config = {
home.homeDirectory = "/test-home";
xsession = { xsession = {
enable = true; enable = true;
windowManager.command = "window manager command"; windowManager.command = "window manager command";

View file

@ -6,8 +6,6 @@ with lib;
config = { config = {
home.stateVersion = "19.09"; home.stateVersion = "19.09";
home.homeDirectory = "/test-home";
home.keyboard = { options = [ "ctrl:nocaps" "altwin:no_win" ]; }; home.keyboard = { options = [ "ctrl:nocaps" "altwin:no_win" ]; };
xsession = { xsession = {

View file

@ -1,6 +1,6 @@
# -*- mode: sh -*- # -*- mode: sh -*-
. "/home/testuser/.nix-profile/etc/profile.d/hm-session-vars.sh" . "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"
export V1="v1" export V1="v1"
export V2="v2-v1" export V2="v2-v1"

View file

@ -13,8 +13,6 @@ with lib;
}; };
}; };
home.homeDirectory = "/home/testuser";
nmt.script = '' nmt.script = ''
assertFileExists home-files/.profile assertFileExists home-files/.profile
assertFileContent \ assertFileContent \

View file

@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ]; imports = [ ../../accounts/email-test-accounts.nix ];
config = { config = {
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
accounts.email.accounts = { accounts.email.accounts = {
"hm@example.com" = { "hm@example.com" = {
getmail = { getmail = {

View file

@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ]; imports = [ ../../accounts/email-test-accounts.nix ];
config = { config = {
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
programs.lieer.enable = true; programs.lieer.enable = true;
accounts.email.accounts = { "hm@example.com".lieer.enable = true; }; accounts.email.accounts = { "hm@example.com".lieer.enable = true; };

View file

@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ]; imports = [ ../../accounts/email-test-accounts.nix ];
config = { config = {
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
programs.mbsync = { programs.mbsync = {
enable = true; enable = true;
groups.inboxes = { groups.inboxes = {

View file

@ -6,11 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ]; imports = [ ../../accounts/email-test-accounts.nix ];
config = { config = {
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
xdg.configHome = mkForce "/home/hm-user/.config";
xdg.cacheHome = mkForce "/home/hm-user/.cache";
accounts.email.accounts = { accounts.email.accounts = {
"hm@example.com" = { "hm@example.com" = {
primary = true; primary = true;

View file

@ -6,11 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ]; imports = [ ../../accounts/email-test-accounts.nix ];
config = { config = {
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
xdg.configHome = mkForce "/home/hm-user/.config";
xdg.cacheHome = mkForce "/home/hm-user/.cache";
accounts.email.accounts = { accounts.email.accounts = {
"hm@example.com" = { "hm@example.com" = {
primary = true; primary = true;

View file

@ -1,5 +0,0 @@
# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
export TMUX_TMPDIR="${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}"

View file

@ -11,9 +11,8 @@ with lib;
nmt.script = '' nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContent home-path/etc/profile.d/hm-session-vars.sh ${ assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
./hm-session-vars.sh 'export TMUX_TMPDIR="''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}"'
}
''; '';
}; };
} }

View file

@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ]; imports = [ ../../accounts/email-test-accounts.nix ];
config = { config = {
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
services.lieer.enable = true; services.lieer.enable = true;
accounts.email.accounts = { accounts.email.accounts = {

View file

@ -1,6 +0,0 @@
# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/homeless-shelter/.nix-profile/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"
. "@nix@/etc/profile.d/nix.sh"

View file

@ -4,20 +4,16 @@ with lib;
{ {
config = { config = {
home.homeDirectory = "/homeless-shelter";
targets.genericLinux.enable = true; targets.genericLinux.enable = true;
nmt.script = '' nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContent \ assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \ home-path/etc/profile.d/hm-session-vars.sh \
${ 'export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"'
pkgs.substituteAll { assertFileContains \
src = ./generic-linux-session-vars-expected.txt; home-path/etc/profile.d/hm-session-vars.sh \
nix = pkgs.nix; '. "${pkgs.nix}/etc/profile.d/nix.sh"'
}
}
''; '';
}; };
} }