Commit 6e8d348b authored by Philip Withnall's avatar Philip Withnall
Browse files

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
parent 2a8d8e40
......@@ -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) {
......
......@@ -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",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment