[grilo/mocking: 23/27] net: Don't fallback to "grl-net-mock-data.ini"



commit 93928e515f585cf6235412f7ffbbeeb75b385abf
Author: Mathias Hasselmann <mathias openismus com>
Date:   Mon Oct 22 15:28:38 2012 +0200

    net: Don't fallback to "grl-net-mock-data.ini"
    
    Just print a warning and disable mocking if the specified mock response file
    cannot be found.

 libs/net/grl-net-mock.c |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/libs/net/grl-net-mock.c b/libs/net/grl-net-mock.c
index db4cc70..37450c2 100644
--- a/libs/net/grl-net-mock.c
+++ b/libs/net/grl-net-mock.c
@@ -152,23 +152,19 @@ get_content_mocked (GrlNetWc *self,
 void init_mock_requester (GrlNetWc *self)
 {
   char *config_filename = g_strdup (g_getenv (GRL_NET_MOCKED_VAR));
+  enable_mocking = FALSE;
 
   if (config_filename == NULL) {
-      enable_mocking = FALSE;
-      return;
+    return;
   }
 
   enable_mocking = TRUE;
 
   /* Read configuration file. */
-  if (config_filename)
-    GRL_DEBUG ("Trying to load mock file \"%s\"", config_filename);
-  else
-    config_filename = g_strdup ("grl-net-mock-data.ini");
-
   GError *error = NULL;
   config = g_key_file_new ();
 
+  GRL_DEBUG ("Loading mock responses from \"%s\"", config_filename);
   g_key_file_load_from_file (config, config_filename, G_KEY_FILE_NONE, &error);
 
   int version = 0;
@@ -182,12 +178,15 @@ void init_mock_requester (GrlNetWc *self)
     version = g_key_file_get_integer (config, "default", "version", &error);
 
     if (error || version < GRL_MOCK_VERSION) {
-      GRL_WARNING ("Unsupported mock version %d.", version);
+      GRL_WARNING ("Unsupported mock version.");
       g_clear_error (&error);
+    } else {
+      enable_mocking = TRUE;
     }
   }
 
-  if (version < GRL_MOCK_VERSION) {
+  if (!enable_mocking) {
+    g_free (config_filename);
     g_key_file_unref (config);
     config = NULL;
     return;
@@ -195,11 +194,7 @@ void init_mock_requester (GrlNetWc *self)
 
   char **parameter_names = g_key_file_get_string_list (config, "default",
                                                        "ignored-parameters",
-                                                       NULL, &error);
-  if (error) {
-    parameter_names = NULL;
-    g_clear_error (&error);
-  }
+                                                       NULL, NULL);
 
   /* Build regular expressions for ignored query parameters. */
   if (parameter_names) {



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