[geocode-glib] tests: Set XDG_CACHE_HOME to a temporary directory for tests
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] tests: Set XDG_CACHE_HOME to a temporary directory for tests
- Date: Fri, 13 Jan 2017 23:12:53 +0000 (UTC)
commit 6e8d348b6a6f713b32e703cb34665b660b2abf93
Author: Philip Withnall <philip tecnocode co uk>
Date: Thu Jan 12 23:24:57 2017 +0000
tests: Set XDG_CACHE_HOME to a temporary directory for tests
We don’t want to pollute the user’s actual cache, or to re-use cached
results between tests.
https://bugzilla.gnome.org/show_bug.cgi?id=756311
geocode-glib/test-gcglib.c | 21 +++++++++++++++++++++
geocode-glib/tests/geocode-nominatim-test.c | 4 ++++
2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/geocode-glib/test-gcglib.c b/geocode-glib/test-gcglib.c
index 6c1ae2f..ef2f51e 100644
--- a/geocode-glib/test-gcglib.c
+++ b/geocode-glib/test-gcglib.c
@@ -173,6 +173,18 @@ load_json (const gchar *expected_response_filename)
return g_steal_pointer (&expected_response);
}
+static void
+set_up_cache (void)
+{
+ g_autofree gchar *cache_path = NULL;
+ g_autoptr (GError) error = NULL;
+
+ cache_path = g_dir_make_tmp ("test-gcglib-XXXXXX", &error);
+ g_assert_no_error (error);
+
+ g_setenv ("XDG_CACHE_HOME", cache_path, TRUE);
+}
+
static GeocodeReverse *
create_reverse (GeocodeLocation *loc,
const gchar *expected_response_filename)
@@ -182,6 +194,9 @@ create_reverse (GeocodeLocation *loc,
char lat[G_ASCII_DTOSTR_BUF_SIZE];
char lon[G_ASCII_DTOSTR_BUF_SIZE];
+ /* Set up the cache to avoid polluting the user’s main cache. */
+ set_up_cache ();
+
/* Build the query parameters. */
g_ascii_dtostr (lat,
G_ASCII_DTOSTR_BUF_SIZE,
@@ -229,6 +244,9 @@ create_forward_for_params (GHashTable *tp,
{
g_autoptr (GeocodeForward) forward = NULL;
+ /* Set up the cache to avoid polluting the user’s main cache. */
+ set_up_cache ();
+
forward = geocode_forward_new_for_params (tp);
if (!enable_network) {
@@ -261,6 +279,9 @@ create_forward_for_string (const gchar *q,
{
g_autoptr (GeocodeForward) forward = NULL;
+ /* Set up the cache to avoid polluting the user’s main cache. */
+ set_up_cache ();
+
forward = geocode_forward_new_for_string (q);
if (!enable_network) {
diff --git a/geocode-glib/tests/geocode-nominatim-test.c b/geocode-glib/tests/geocode-nominatim-test.c
index 7820475..a054517 100644
--- a/geocode-glib/tests/geocode-nominatim-test.c
+++ b/geocode-glib/tests/geocode-nominatim-test.c
@@ -212,6 +212,10 @@ real_query (GeocodeNominatim *self,
GeocodeNominatim *
geocode_nominatim_test_new (void)
{
+ /* This shouldn’t be used with the user’s normal cache directory, or we
+ * will pollute it. */
+ g_assert (g_str_has_prefix (g_get_user_cache_dir (), g_get_tmp_dir ()));
+
return GEOCODE_NOMINATIM (g_object_new (GEOCODE_TYPE_NOMINATIM_TEST,
"base-url", "http://example.invalid",
"maintainer-email-address", "maintainer@invalid",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]