Enable config file versioning
This (way too large patch) enables versioning in config files, and provides a mechanism by which to load older versions from a newer version of Geary. It also properly introduces a new v1 config format that adds several groups to geary.ini to make it easier to read and to distinguish between incoming/outgoig services rather than IMAP/SMTP. To do this, a few things that should have happened in seperate patches were also done: * Make AccountInformation's imap and smtp properties mutable (they aren't stateful any more anyway), make ServiceInformation non-abstract again and remove the subclasses (to get config versioning happening without an explosion of a classes, it all has to be handled from the AccountManager anyway), and some other misc things.
This commit is contained in:
parent
79c74c4310
commit
123f51dbb2
23 changed files with 1213 additions and 757 deletions
|
|
@ -8,7 +8,11 @@
|
|||
class Accounts.ManagerTest : TestCase {
|
||||
|
||||
|
||||
private const string TEST_ID = "test";
|
||||
|
||||
private Manager? test = null;
|
||||
private Geary.AccountInformation? account = null;
|
||||
private Geary.ServiceInformation? service = null;
|
||||
private File? tmp = null;
|
||||
|
||||
|
||||
|
|
@ -17,6 +21,10 @@ class Accounts.ManagerTest : TestCase {
|
|||
add_test("create_account", create_account);
|
||||
add_test("create_orphan_account", create_orphan_account);
|
||||
add_test("create_orphan_account_with_legacy", create_orphan_account_with_legacy);
|
||||
add_test("account_config_v1", account_config_v1);
|
||||
add_test("account_config_legacy", account_config_legacy);
|
||||
add_test("service_config_v1", service_config_v1);
|
||||
add_test("service_config_legacy", service_config_legacy);
|
||||
}
|
||||
|
||||
public override void set_up() throws GLib.Error {
|
||||
|
|
@ -34,21 +42,24 @@ class Accounts.ManagerTest : TestCase {
|
|||
data.make_directory();
|
||||
|
||||
this.test = new Manager(new GearyApplication(), config, data);
|
||||
|
||||
this.account = new Geary.AccountInformation(
|
||||
TEST_ID,
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
|
||||
this.service = new Geary.ServiceInformation(Geary.Protocol.SMTP, null);
|
||||
}
|
||||
|
||||
public override void tear_down() throws GLib.Error {
|
||||
this.test = null;
|
||||
this.account = null;
|
||||
this.service = null;
|
||||
@delete(this.tmp);
|
||||
}
|
||||
|
||||
public void create_account() throws GLib.Error {
|
||||
const string ID = "test";
|
||||
Geary.AccountInformation account = new Geary.AccountInformation(
|
||||
ID,
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
bool was_added = false;
|
||||
bool was_enabled = false;
|
||||
|
||||
|
|
@ -64,7 +75,7 @@ class Accounts.ManagerTest : TestCase {
|
|||
this.test.create_account.end(async_result());
|
||||
|
||||
assert_int(1, this.test.size, "Account manager size");
|
||||
assert_equal(account, this.test.get_account(ID), "Is not contained");
|
||||
assert_equal(account, this.test.get_account(TEST_ID), "Is not contained");
|
||||
assert_true(was_added, "Was not added");
|
||||
assert_true(was_enabled, "Was not enabled");
|
||||
}
|
||||
|
|
@ -72,8 +83,7 @@ class Accounts.ManagerTest : TestCase {
|
|||
public void create_orphan_account() throws GLib.Error {
|
||||
Geary.AccountInformation account1 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
new Geary.RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
assert(account1.id == "account_01");
|
||||
|
||||
|
|
@ -85,21 +95,12 @@ class Accounts.ManagerTest : TestCase {
|
|||
|
||||
Geary.AccountInformation account2 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
new Geary.RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
assert(account2.id == "account_02");
|
||||
}
|
||||
|
||||
public void create_orphan_account_with_legacy() throws GLib.Error {
|
||||
const string ID = "test";
|
||||
Geary.AccountInformation account = new Geary.AccountInformation(
|
||||
ID,
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
|
||||
this.test.create_account.begin(
|
||||
account, new GLib.Cancellable(),
|
||||
(obj, res) => { async_complete(res); }
|
||||
|
|
@ -108,8 +109,7 @@ class Accounts.ManagerTest : TestCase {
|
|||
|
||||
Geary.AccountInformation account1 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
new Geary.RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
assert(account1.id == "account_01");
|
||||
|
||||
|
|
@ -121,12 +121,90 @@ class Accounts.ManagerTest : TestCase {
|
|||
|
||||
Geary.AccountInformation account2 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
new Geary.RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
assert(account2.id == "account_02");
|
||||
}
|
||||
|
||||
public void account_config_v1() throws GLib.Error {
|
||||
this.account.email_signature = "blarg";
|
||||
this.account.nickname = "test-name";
|
||||
this.account.ordinal = 100;
|
||||
this.account.prefetch_period_days = 42;
|
||||
this.account.save_drafts = false;
|
||||
this.account.save_sent_mail = false;
|
||||
this.account.use_email_signature = false;
|
||||
Accounts.AccountConfigV1 config = new Accounts.AccountConfigV1(false);
|
||||
|
||||
Geary.ConfigFile file =
|
||||
new Geary.ConfigFile(this.tmp.get_child("config"));
|
||||
|
||||
config.save(this.account, file);
|
||||
Geary.AccountInformation copy = config.load(file, TEST_ID, null, null);
|
||||
|
||||
assert_true(this.account.equal_to(copy));
|
||||
}
|
||||
|
||||
public void account_config_legacy() throws GLib.Error {
|
||||
this.account.email_signature = "blarg";
|
||||
this.account.nickname = "test-name";
|
||||
this.account.ordinal = 100;
|
||||
this.account.prefetch_period_days = 42;
|
||||
this.account.save_drafts = false;
|
||||
this.account.save_sent_mail = false;
|
||||
this.account.use_email_signature = false;
|
||||
Accounts.AccountConfigLegacy config =
|
||||
new Accounts.AccountConfigLegacy();
|
||||
|
||||
Geary.ConfigFile file =
|
||||
new Geary.ConfigFile(this.tmp.get_child("config"));
|
||||
|
||||
config.save(this.account, file);
|
||||
Geary.AccountInformation copy = config.load(file, TEST_ID, null, null);
|
||||
|
||||
assert_true(this.account.equal_to(copy));
|
||||
}
|
||||
|
||||
public void service_config_v1() throws GLib.Error {
|
||||
this.service.host = "blarg";
|
||||
this.service.port = 1234;
|
||||
this.service.transport_security = Geary.TlsNegotiationMethod.NONE;
|
||||
this.service.smtp_credentials_source = Geary.SmtpCredentials.CUSTOM;
|
||||
this.service.credentials = new Geary.Credentials(
|
||||
Geary.Credentials.Method.PASSWORD, "testerson"
|
||||
);
|
||||
Accounts.ServiceConfigV1 config = new Accounts.ServiceConfigV1();
|
||||
Geary.ConfigFile file =
|
||||
new Geary.ConfigFile(this.tmp.get_child("config"));
|
||||
|
||||
config.save(this.account, this.service, file);
|
||||
Geary.ServiceInformation copy = config.load(
|
||||
file, this.account, this.service.protocol, null
|
||||
);
|
||||
|
||||
assert_true(this.service.equal_to(copy));
|
||||
}
|
||||
|
||||
public void service_config_legacy() throws GLib.Error {
|
||||
this.service.host = "blarg";
|
||||
this.service.port = 1234;
|
||||
this.service.transport_security = Geary.TlsNegotiationMethod.NONE;
|
||||
this.service.smtp_credentials_source = Geary.SmtpCredentials.CUSTOM;
|
||||
this.service.credentials = new Geary.Credentials(
|
||||
Geary.Credentials.Method.PASSWORD, "testerson"
|
||||
);
|
||||
Accounts.ServiceConfigLegacy config = new Accounts.ServiceConfigLegacy();
|
||||
Geary.ConfigFile file =
|
||||
new Geary.ConfigFile(this.tmp.get_child("config"));
|
||||
|
||||
config.save(this.account, this.service, file);
|
||||
Geary.ServiceInformation copy = config.load(
|
||||
file, this.account, this.service.protocol, null
|
||||
);
|
||||
|
||||
assert_true(this.service.equal_to(copy));
|
||||
}
|
||||
|
||||
private void delete(File parent) throws GLib.Error {
|
||||
FileInfo info = parent.query_info(
|
||||
"standard::*",
|
||||
|
|
|
|||
|
|
@ -17,19 +17,19 @@ class Geary.AccountInformationTest : TestCase {
|
|||
AccountInformation test = new AccountInformation(
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
new RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
|
||||
test.append_sender(new RFC822.MailboxAddress(null, "test1@example.com"));
|
||||
assert_false(test.has_sender_aliases);
|
||||
|
||||
test.append_sender(new RFC822.MailboxAddress(null, "test2@example.com"));
|
||||
test.append_sender(new RFC822.MailboxAddress(null, "test3@example.com"));
|
||||
assert_true(test.has_sender_aliases);
|
||||
|
||||
assert_true(test.primary_mailbox.equal_to(
|
||||
new RFC822.MailboxAddress(null, "test1@example.com")));
|
||||
assert_false(test.has_sender_aliases);
|
||||
|
||||
test.append_sender(new RFC822.MailboxAddress(null, "test2@example.com"));
|
||||
assert_true(test.has_sender_aliases);
|
||||
|
||||
test.append_sender(new RFC822.MailboxAddress(null, "test3@example.com"));
|
||||
assert_true(test.has_sender_aliases);
|
||||
|
||||
assert_true(
|
||||
test.has_sender_mailbox(new RFC822.MailboxAddress(null, "test1@example.com")),
|
||||
"Primary address not found"
|
||||
|
|
|
|||
|
|
@ -66,8 +66,7 @@ class Geary.EngineTest : TestCase {
|
|||
AccountInformation info = new AccountInformation(
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
new RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
assert_false(this.engine.has_account(info.id));
|
||||
|
||||
|
|
@ -86,8 +85,7 @@ class Geary.EngineTest : TestCase {
|
|||
AccountInformation info = new AccountInformation(
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
new RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
this.engine.add_account(info);
|
||||
assert_true(this.engine.has_account(info.id));
|
||||
|
|
@ -103,8 +101,7 @@ class Geary.EngineTest : TestCase {
|
|||
AccountInformation info = new AccountInformation(
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
new RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
assert_false(this.engine.has_account(info.id));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 Michael Gratton <mike@vee.net>
|
||||
*
|
||||
* This software is licensed under the GNU Lesser General Public License
|
||||
* (version 2.1 or later). See the COPYING file in this distribution.
|
||||
*/
|
||||
|
||||
public class Geary.MockServiceInformation : ServiceInformation, MockObject {
|
||||
|
||||
|
||||
protected Gee.Queue<ExpectedCall> expected {
|
||||
get; set; default = new Gee.LinkedList<ExpectedCall>();
|
||||
}
|
||||
|
||||
public MockServiceInformation() {
|
||||
base(Protocol.IMAP, new MockCredentialsMediator());
|
||||
}
|
||||
|
||||
public override Geary.ServiceInformation temp_copy() {
|
||||
try {
|
||||
return object_call<Geary.ServiceInformation>(
|
||||
"temp_copy", { }, new MockServiceInformation()
|
||||
);
|
||||
} catch (GLib.Error err) {
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,8 +31,7 @@ class Geary.App.ConversationMonitorTest : TestCase {
|
|||
this.account_info = new AccountInformation(
|
||||
"account_01",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
new RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
this.account = new MockAccount(this.account_info);
|
||||
this.base_folder = new MockFolder(
|
||||
|
|
|
|||
|
|
@ -72,8 +72,7 @@ public class Geary.ImapEngine.AccountProcessorTest : TestCase {
|
|||
this.info = new Geary.AccountInformation(
|
||||
"test-info",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
new RFC822.MailboxAddress(null, "test1@example.com")
|
||||
);
|
||||
this.account = new Geary.MockAccount(this.info);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ class Geary.ConfigFileTest : TestCase {
|
|||
base("Geary.ConfigFileTest");
|
||||
add_test("test_string", test_string);
|
||||
add_test("test_string_fallback", test_string_fallback);
|
||||
add_test("test_escaped_string", test_escaped_string);
|
||||
add_test("test_string_list", test_string_list);
|
||||
add_test("test_string_list", test_string_list);
|
||||
add_test("test_bool", test_bool);
|
||||
|
|
@ -55,12 +54,6 @@ class Geary.ConfigFileTest : TestCase {
|
|||
assert_string("a string", this.test_group.get_string(TEST_KEY));
|
||||
}
|
||||
|
||||
public void test_escaped_string() throws Error {
|
||||
this.test_group.set_escaped_string(TEST_KEY, "a\nstring");
|
||||
assert_string("a\nstring", this.test_group.get_escaped_string(TEST_KEY));
|
||||
assert_string("=default", this.test_group.get_escaped_string(TEST_KEY_MISSING, "=default"));
|
||||
}
|
||||
|
||||
public void test_string_list() throws Error {
|
||||
this.test_group.set_string_list(
|
||||
TEST_KEY, new Gee.ArrayList<string>.wrap({ "a", "b"})
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ geary_test_engine_sources = [
|
|||
'engine/api/geary-email-properties-mock.vala',
|
||||
'engine/api/geary-folder-mock.vala',
|
||||
'engine/api/geary-folder-path-mock.vala',
|
||||
'engine/api/geary-service-information-mock.vala',
|
||||
|
||||
'engine/api/geary-account-information-test.vala',
|
||||
'engine/api/geary-attachment-test.vala',
|
||||
|
|
@ -68,7 +67,6 @@ geary_test_client_sources = [
|
|||
# geary-engine_internal.vapi, which leads to duplicate symbols when
|
||||
# linking
|
||||
'engine/api/geary-credentials-mediator-mock.vala',
|
||||
'engine/api/geary-service-information-mock.vala',
|
||||
|
||||
'client/accounts/accounts-manager-test.vala',
|
||||
'client/application/geary-configuration-test.vala',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue