|
0 |
From: Simon McVittie <smcv@debian.org>
|
|
1 |
Date: Tue, 4 Jul 2017 11:01:09 +0100
|
|
2 |
Subject: tests: Isolate tests from real home directory more thoroughly
|
|
3 |
|
|
4 |
The library test previously used the real ~/.cache, while the
|
|
5 |
library test and the shell-script tests would use the real ~/.config
|
|
6 |
to look up the XDG user-dirs.dirs. Other home-directory-related code
|
|
7 |
might have used the real $HOME.
|
|
8 |
|
|
9 |
As a general rule, build-time tests should not affect the real home
|
|
10 |
directory. Debian autobuilders run as a user whose home directory
|
|
11 |
does not exist, in order to catch packages whose build process could
|
|
12 |
affect or be affected by the contents of the home directory. This
|
|
13 |
caused testlibrary to fail when it tried to create that nonexistent
|
|
14 |
directory, which I think happened while trying to create ~/.cache.
|
|
15 |
|
|
16 |
Signed-off-by: Simon McVittie <smcv@debian.org>
|
|
17 |
Forwarded: https://github.com/flatpak/flatpak/pull/894
|
|
18 |
---
|
|
19 |
tests/libtest.sh | 2 ++
|
|
20 |
tests/testlibrary.c | 27 ++++++++++++++++++++++++---
|
|
21 |
2 files changed, 26 insertions(+), 3 deletions(-)
|
|
22 |
|
|
23 |
diff --git a/tests/libtest.sh b/tests/libtest.sh
|
|
24 |
index 72573f0..801606f 100644
|
|
25 |
--- a/tests/libtest.sh
|
|
26 |
+++ b/tests/libtest.sh
|
|
27 |
@@ -80,7 +80,9 @@ mkdir -p ${TEST_DATA_DIR}/system
|
|
28 |
export FLATPAK_SYSTEM_DIR=${TEST_DATA_DIR}/system
|
|
29 |
export FLATPAK_SYSTEM_HELPER_ON_SESSION=1
|
|
30 |
|
|
31 |
+export HOME=${TEST_DATA_DIR}/home
|
|
32 |
export XDG_CACHE_HOME=${TEST_DATA_DIR}/home/cache
|
|
33 |
+export XDG_CONFIG_HOME=${TEST_DATA_DIR}/home/config
|
|
34 |
export XDG_DATA_HOME=${TEST_DATA_DIR}/home/share
|
|
35 |
export XDG_RUNTIME_DIR=${TEST_DATA_DIR}/runtime
|
|
36 |
|
|
37 |
diff --git a/tests/testlibrary.c b/tests/testlibrary.c
|
|
38 |
index e14bdf6..a9a6deb 100644
|
|
39 |
--- a/tests/testlibrary.c
|
|
40 |
+++ b/tests/testlibrary.c
|
|
41 |
@@ -766,6 +766,9 @@ copy_gpg (void)
|
|
42 |
static void
|
|
43 |
global_setup (void)
|
|
44 |
{
|
|
45 |
+ g_autofree char *cachedir = NULL;
|
|
46 |
+ g_autofree char *configdir = NULL;
|
|
47 |
+ g_autofree char *datadir = NULL;
|
|
48 |
g_autofree char *homedir = NULL;
|
|
49 |
|
|
50 |
testdir = g_strdup ("/var/tmp/flatpak-test-XXXXXX");
|
|
51 |
@@ -773,11 +776,29 @@ global_setup (void)
|
|
52 |
if (g_test_verbose ())
|
|
53 |
g_print ("testdir: %s\n", testdir);
|
|
54 |
|
|
55 |
- homedir = g_strconcat (testdir, "/home/share", NULL);
|
|
56 |
+ homedir = g_strconcat (testdir, "/home", NULL);
|
|
57 |
g_mkdir_with_parents (homedir, S_IRWXU|S_IRWXG|S_IRWXO);
|
|
58 |
- g_setenv ("XDG_DATA_HOME", homedir, TRUE);
|
|
59 |
+ g_setenv ("HOME", homedir, TRUE);
|
|
60 |
if (g_test_verbose ())
|
|
61 |
- g_print ("setting XDG_DATA_HOME=%s\n", homedir);
|
|
62 |
+ g_print ("setting HOME=%s\n", datadir);
|
|
63 |
+
|
|
64 |
+ cachedir = g_strconcat (testdir, "/home/cache", NULL);
|
|
65 |
+ g_mkdir_with_parents (cachedir, S_IRWXU|S_IRWXG|S_IRWXO);
|
|
66 |
+ g_setenv ("XDG_CACHE_HOME", cachedir, TRUE);
|
|
67 |
+ if (g_test_verbose ())
|
|
68 |
+ g_print ("setting XDG_CACHE_HOME=%s\n", cachedir);
|
|
69 |
+
|
|
70 |
+ configdir = g_strconcat (testdir, "/home/config", NULL);
|
|
71 |
+ g_mkdir_with_parents (configdir, S_IRWXU|S_IRWXG|S_IRWXO);
|
|
72 |
+ g_setenv ("XDG_CONFIG_HOME", configdir, TRUE);
|
|
73 |
+ if (g_test_verbose ())
|
|
74 |
+ g_print ("setting XDG_CONFIG_HOME=%s\n", configdir);
|
|
75 |
+
|
|
76 |
+ datadir = g_strconcat (testdir, "/home/share", NULL);
|
|
77 |
+ g_mkdir_with_parents (datadir, S_IRWXU|S_IRWXG|S_IRWXO);
|
|
78 |
+ g_setenv ("XDG_DATA_HOME", datadir, TRUE);
|
|
79 |
+ if (g_test_verbose ())
|
|
80 |
+ g_print ("setting XDG_DATA_HOME=%s\n", datadir);
|
|
81 |
|
|
82 |
flatpak_runtimedir = g_strconcat (testdir, "/runtime", NULL);
|
|
83 |
g_mkdir_with_parents (flatpak_runtimedir, S_IRWXU|S_IRWXG|S_IRWXO);
|