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 {
inherit lib pkgs;
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

View file

@ -4,3 +4,6 @@ export __HM_SESS_VARS_SOURCED=1
export V1="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
. "$HOME/.profile"

View file

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

View file

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

View file

@ -1,6 +1,6 @@
# -*- 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 V2="v2-v1"

View file

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

View file

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

View file

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

View file

@ -6,11 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
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 = {
"hm@example.com" = {
primary = true;

View file

@ -6,11 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
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 = {
"hm@example.com" = {
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 = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContent home-path/etc/profile.d/hm-session-vars.sh ${
./hm-session-vars.sh
}
assertFileContains home-path/etc/profile.d/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 ];
config = {
home.username = "hm-user";
home.homeDirectory = "/home/hm-user";
services.lieer.enable = true;
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 = {
home.homeDirectory = "/homeless-shelter";
targets.genericLinux.enable = true;
nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContent \
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
${
pkgs.substituteAll {
src = ./generic-linux-session-vars-expected.txt;
nix = pkgs.nix;
}
}
'export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"'
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'. "${pkgs.nix}/etc/profile.d/nix.sh"'
'';
};
}