[folks] Tests: fix EDS linking tests



commit 4b965d4bc8c419493db41322fd2269b4ec30eacb
Author: Julian Sparber <julian sparber net>
Date:   Mon Dec 16 22:48:50 2019 +0100

    Tests: fix EDS linking tests
    
    Linking depents now on the key-file to store linking information,
    therefore this adds the key-file backend to the eds tests.
    
    It also cleans up the set-up for the key-file backend as well.

 tests/lib/eds/meson.build       |  4 ++++
 tests/lib/eds/test-case.vala    | 25 ++++++++++++++++++++++-
 tests/lib/key-file/backend.vala | 45 ++++++++++-------------------------------
 3 files changed, 39 insertions(+), 35 deletions(-)
---
diff --git a/tests/lib/eds/meson.build b/tests/lib/eds/meson.build
index a0913bff..e2b1fc8c 100644
--- a/tests/lib/eds/meson.build
+++ b/tests/lib/eds/meson.build
@@ -8,6 +8,7 @@ libeds_test_deps = [
   libebook_dep,
   eds_backendlib_dep,
   build_conf_dep,
+  libkeyfile_test_dep,
 ]
 
 libeds_test = library('eds-test',
@@ -19,4 +20,7 @@ libeds_test = library('eds-test',
 libeds_test_dep = declare_dependency(
   link_with: libeds_test,
   include_directories: include_directories('.'),
+  dependencies: [
+    libkeyfile_test_dep,
+  ],
 )
diff --git a/tests/lib/eds/test-case.vala b/tests/lib/eds/test-case.vala
index 2f41592d..e25075dd 100644
--- a/tests/lib/eds/test-case.vala
+++ b/tests/lib/eds/test-case.vala
@@ -37,6 +37,9 @@
  */
 public class EdsTest.TestCase : Folks.TestCase
 {
+  /* The key-file store is needed for linking */
+  public KfTest.Backend? kf_backend = null;
+
   /**
    * An EDS backend, normally non-null between set_up() and tear_down().
    *
@@ -50,7 +53,7 @@ public class EdsTest.TestCase : Folks.TestCase
     {
       base (name);
 
-      Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "eds", true);
+      Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "eds, key-file", true);
       Environment.set_variable ("FOLKS_PRIMARY_STORE", "eds:local://test",
           true);
     }
@@ -157,6 +160,7 @@ public class EdsTest.TestCase : Folks.TestCase
     {
       base.set_up ();
       this.create_backend ();
+      this.create_kf_backend ();
       this.configure_primary_store ();
     }
 
@@ -191,6 +195,20 @@ public class EdsTest.TestCase : Folks.TestCase
       Environment.set_variable ("FOLKS_PRIMARY_STORE", config_val, true);
     }
 
+  /**
+   * Virtual method to create the keyfile backend. Currently called by
+   * the constructor (once per process), but might move into set_up() later.
+   *
+   * Subclasses may chain up, but are not required to so.
+   */
+  public virtual void create_kf_backend ()
+    {
+      if (this.kf_backend != null)
+        ((!) this.kf_backend).set_up ("");
+
+      this.kf_backend = new KfTest.Backend ();
+    }
+
   public override void tear_down ()
     {
       if (this.eds_backend != null)
@@ -199,6 +217,11 @@ public class EdsTest.TestCase : Folks.TestCase
           this.eds_backend = null;
         }
 
+      if (this.kf_backend != null)
+        {
+          ((!) this.kf_backend).tear_down ();
+        }
+
       Environment.unset_variable ("FOLKS_PRIMARY_STORE");
 
       /* Ensure that all pending operations are complete.
diff --git a/tests/lib/key-file/backend.vala b/tests/lib/key-file/backend.vala
index ec5b31a0..0d17f5ae 100644
--- a/tests/lib/key-file/backend.vala
+++ b/tests/lib/key-file/backend.vala
@@ -20,60 +20,37 @@
  *      Philip Withnall <philip withnall collabora co uk>
  */
 
+
+const string KEY_FILE_NAME = "relationships.ini";
+
 public class KfTest.Backend
 {
-  private string key_file_name;
+  private string key_file_dir;
 
   public void set_up (string key_file_contents)
     {
-      int fd;
-
       /* Create a temporary file */
       try
         {
-          fd = FileUtils.open_tmp ("folks-kf-test-XXXXXX",
-              out this.key_file_name);
+          this.key_file_dir = DirUtils.make_tmp ("folks-kf-test-XXXXXX");
+          FileUtils.set_contents (this.key_file_dir + "/" + KEY_FILE_NAME, key_file_contents);
         }
       catch (FileError e)
         {
-          error ("Error opening temporary file: %s", e.message);
-        }
-
-      /* Populate it with the given content */
-      IOChannel channel = new IOChannel.unix_new (fd);
-      try
-        {
-          channel.write_chars ((char[]) key_file_contents, null);
-        }
-      catch (ConvertError e)
-        {
-          error ("Error converting for writing to temporary file '%s': %s\n%s",
-              this.key_file_name, e.message, key_file_contents);
-        }
-      catch (IOChannelError e)
-        {
-          error ("Error writing to temporary file '%s': %s", this.key_file_name,
-              e.message);
-        }
-
-      try
-        {
-          channel.shutdown (true);
+          error ("Error writing to temporary file: %s", e.message);
         }
-      catch (IOChannelError e) {}
-      FileUtils.close (fd);
 
       /* Set the environment variable for the key file path to the temporary
        * file, causing the key-file backend to use it next time it's loaded */
       Environment.set_variable ("FOLKS_BACKEND_KEY_FILE_PATH",
-          this.key_file_name, true);
+          this.key_file_dir + "/" + KEY_FILE_NAME, true);
     }
 
   public void tear_down ()
     {
       /* Remove the temporary file */
-      if (this.key_file_name != null)
-        FileUtils.remove (this.key_file_name);
-      this.key_file_name = null;
+      if (this.key_file_dir != null)
+        DirUtils.remove (this.key_file_dir);
+      this.key_file_dir = null;
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]