Make sure unit cache tests are not messing the user's cache
authorXavier Claessens <xavier.claessens@collabora.co.uk>
Mon, 26 Mar 2012 12:09:55 +0000 (14:09 +0200)
committerXavier Claessens <xavier.claessens@collabora.co.uk>
Wed, 28 Mar 2012 12:10:16 +0000 (14:10 +0200)
XDG_CACHE_HOME must be set before the first call of g_get_user_cache_dir().
The problem is g_file_new_for_path() actually ends to a call to
g_get_user_cache_dir() somewhere in gvfs, so ensure we set the env before
that.

tests/folks/avatar-cache.vala
tests/folks/object-cache.vala

index 9d0684c..8090ec0 100644 (file)
@@ -34,9 +34,11 @@ public class AvatarCacheTests : Folks.TestCase
       base ("AvatarCache");
 
       /* Use a temporary cache directory */
-      this._cache_dir =
-          File.new_for_path (Environment.get_tmp_dir ()).
-              get_child ("folks-avatar-cache-tests");
+      /* FIXME: Use g_dir_make_tmp() but it is not bound: #672846 */
+      var tmp_path = Environment.get_tmp_dir () + "/folks-avatar-cache-tests";
+      Environment.set_variable ("XDG_CACHE_HOME", tmp_path, true);
+      assert (Environment.get_user_cache_dir () == tmp_path);
+      this._cache_dir = File.new_for_path (tmp_path);
 
       this.add_test ("store-and-load-avatar", this.test_store_and_load_avatar);
       this.add_test ("store-avatar-overwrite",
@@ -52,8 +54,6 @@ public class AvatarCacheTests : Folks.TestCase
   public override void set_up ()
     {
       this._delete_cache_directory ();
-      Environment.set_variable ("XDG_CACHE_HOME", this._cache_dir.get_path (),
-          true);
 
       this._cache = AvatarCache.dup ();
       this._avatar =
index c669067..efdb0ff 100644 (file)
@@ -64,9 +64,11 @@ public class ObjectCacheTests : Folks.TestCase
       base ("ObjectCache");
 
       /* Use a temporary cache directory */
-      this._cache_dir =
-          File.new_for_path (Environment.get_tmp_dir ()).
-              get_child ("folks-object-cache-tests");
+      /* FIXME: Use g_dir_make_tmp() but it is not bound: #672846 */
+      var tmp_path = Environment.get_tmp_dir () + "/folks-object-cache-tests";
+      Environment.set_variable ("XDG_CACHE_HOME", tmp_path, true);
+      assert (Environment.get_user_cache_dir () == tmp_path);
+      this._cache_dir = File.new_for_path (tmp_path);
 
       // Basic functionality tests
       this.add_test ("create", this.test_create);
@@ -93,8 +95,6 @@ public class ObjectCacheTests : Folks.TestCase
   public override void set_up ()
     {
       this._delete_cache_directory ();
-      Environment.set_variable ("XDG_CACHE_HOME", this._cache_dir.get_path (),
-          true);
     }
 
   public override void tear_down ()