[geary/wip/714104-refine-account-dialog] Fix failing account manager tests



commit 56906e1f35f2f2884dc20e96c653051a29c02226
Author: Michael Gratton <mike vee net>
Date:   Wed Dec 26 15:27:47 2018 +1030

    Fix failing account manager tests
    
    This makes Accounts.Manager more easily unit testable by supplying a
    credentials mediator for libsecret, rather than constructing one
    internally.

 src/client/accounts/accounts-manager.vala       | 22 ++++++++--------------
 src/client/application/geary-controller.vala    | 15 ++++++++-------
 test/client/accounts/accounts-manager-test.vala | 10 ++++++++--
 3 files changed, 24 insertions(+), 23 deletions(-)
---
diff --git a/src/client/accounts/accounts-manager.vala b/src/client/accounts/accounts-manager.vala
index e3c20ac6..1a0f6f47 100644
--- a/src/client/accounts/accounts-manager.vala
+++ b/src/client/accounts/accounts-manager.vala
@@ -203,13 +203,12 @@ public class Accounts.Manager : GLib.Object {
         new Gee.LinkedList<Geary.AccountInformation>();
 
 
-    private GearyApplication application;
+    private Geary.CredentialsMediator local_mediator;
+    private Goa.Client? goa_service = null;
+
     private GLib.File user_config_dir;
     private GLib.File user_data_dir;
 
-    private Geary.CredentialsMediator? libsecret = null;
-    private Goa.Client? goa_service = null;
-
 
     /** Fired when a new account is created. */
     public signal void account_added(Geary.AccountInformation added, Status status);
@@ -225,10 +224,10 @@ public class Accounts.Manager : GLib.Object {
     public signal void report_problem(Geary.ProblemReport problem);
 
 
-    public Manager(GearyApplication application,
+    public Manager(Geary.CredentialsMediator local_mediator,
                    GLib.File user_config_dir,
                    GLib.File user_data_dir) {
-        this.application = application;
+        this.local_mediator = local_mediator;
         this.user_config_dir = user_config_dir;
         this.user_data_dir = user_data_dir;
     }
@@ -254,11 +253,6 @@ public class Accounts.Manager : GLib.Object {
         );
     }
 
-    public async void connect_libsecret(GLib.Cancellable? cancellable)
-        throws GLib.Error {
-        this.libsecret = yield new SecretMediator(this.application, cancellable);
-    }
-
     public async void connect_goa(GLib.Cancellable? cancellable)
         throws GLib.Error {
         this.goa_service = yield new Goa.Client(cancellable);
@@ -299,7 +293,7 @@ public class Accounts.Manager : GLib.Object {
         string id = LOCAL_ID_FORMAT.printf(next_id);
 
         return new Geary.AccountInformation(
-            id, provider, this.libsecret, primary_mailbox
+            id, provider, this.local_mediator, primary_mailbox
         );
     }
 
@@ -559,7 +553,7 @@ public class Accounts.Manager : GLib.Object {
         Goa.Object? goa_handle = null;
         GoaMediator? goa_mediator = null;
         Geary.ServiceProvider? default_provider = null;
-        Geary.CredentialsMediator mediator = this.libsecret;
+        Geary.CredentialsMediator mediator = this.local_mediator;
 
         if (is_goa) {
             if (this.goa_service == null) {
@@ -1508,7 +1502,7 @@ public class Accounts.ServiceConfigLegacy : ServiceConfig, GLib.Object {
         Geary.ConfigFile.Group service_config =
             config.get_group(AccountConfigLegacy.GROUP);
 
-        string prefix = service.protocol.to_value() + "_";
+        string prefix = service.protocol.to_value().ascii_down() + "_";
 
         if (service.credentials != null) {
             service_config.set_string(
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 46c9b850..b3bae268 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -305,8 +305,15 @@ public class GearyController : Geary.BaseObject {
         }
 
         // Hook up accounts and credentials machinery
+        SecretMediator? libsecret = null;
+        try {
+            libsecret = yield new SecretMediator(this.application, cancellable);
+        } catch (GLib.Error err) {
+            error("Error opening libsecret: %s", err.message);
+        }
+
         this.account_manager = new Accounts.Manager(
-            this.application,
+            libsecret,
             this.application.get_user_config_directory(),
             this.application.get_user_data_directory()
         );
@@ -323,12 +330,6 @@ public class GearyController : Geary.BaseObject {
             on_report_problem
         );
 
-        try {
-            yield this.account_manager.connect_libsecret(cancellable);
-        } catch (GLib.Error err) {
-            warning("Error opening libsecret: %s", err.message);
-        }
-
         try {
             yield this.account_manager.connect_goa(cancellable);
         } catch (GLib.Error err) {
diff --git a/test/client/accounts/accounts-manager-test.vala b/test/client/accounts/accounts-manager-test.vala
index 6d792767..f15752ee 100644
--- a/test/client/accounts/accounts-manager-test.vala
+++ b/test/client/accounts/accounts-manager-test.vala
@@ -13,6 +13,7 @@ class Accounts.ManagerTest : TestCase {
     private Manager? test = null;
     private Geary.CredentialsMediator? mediator = null;
     private Geary.AccountInformation? account = null;
+    private Geary.RFC822.MailboxAddress primary_mailbox;
     private File? tmp = null;
 
 
@@ -41,20 +42,25 @@ class Accounts.ManagerTest : TestCase {
         GLib.File data = this.tmp.get_child("data");
         data.make_directory();
 
-        this.test = new Manager(new GearyApplication(), config, data);
+        this.primary_mailbox = new Geary.RFC822.MailboxAddress(
+            null, "test1 example com"
+        );
+
         this.mediator = new Geary.MockCredentialsMediator();
         this.account = new Geary.AccountInformation(
             TEST_ID,
             Geary.ServiceProvider.OTHER,
             this.mediator,
-            new Geary.RFC822.MailboxAddress(null, "test1 example com")
+            this.primary_mailbox
         );
+        this.test = new Manager(this.mediator, config, data);
     }
 
        public override void tear_down() throws GLib.Error {
         this.account = null;
         this.mediator = null;
         this.test = null;
+        this.primary_mailbox = null;
         @delete(this.tmp);
        }
 


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