Make both Engine and AccountInfo a bit more unit testable.
* src/engine/api/geary-account-information.vala (AccountInformation): Make main constrcutor public, pass in the id rather than divining it from the config dir's name for both ctors. Update call sites. * src/engine/api/geary-engine.vala (Engine): Also make the ctor public.
This commit is contained in:
parent
dbf0251646
commit
6eac43b2e7
2 changed files with 14 additions and 11 deletions
|
|
@ -209,8 +209,8 @@ public class Geary.AccountInformation : BaseObject {
|
||||||
/**
|
/**
|
||||||
* Creates a new, empty account info file.
|
* Creates a new, empty account info file.
|
||||||
*/
|
*/
|
||||||
internal AccountInformation(File config_directory, File data_directory) {
|
public AccountInformation(string id, File config_directory, File data_directory) {
|
||||||
this.id = config_directory.get_basename();
|
this.id = id;
|
||||||
this.config_dir = config_directory;
|
this.config_dir = config_directory;
|
||||||
this.data_dir = data_directory;
|
this.data_dir = data_directory;
|
||||||
this.file = config_dir.get_child(SETTINGS_FILENAME);
|
this.file = config_dir.get_child(SETTINGS_FILENAME);
|
||||||
|
|
@ -222,10 +222,11 @@ public class Geary.AccountInformation : BaseObject {
|
||||||
* Throws an error if the config file was not found, could not be
|
* Throws an error if the config file was not found, could not be
|
||||||
* parsed, or doesn't have all required fields.
|
* parsed, or doesn't have all required fields.
|
||||||
*/
|
*/
|
||||||
internal AccountInformation.from_file(File config_directory,
|
internal AccountInformation.from_file(string id,
|
||||||
|
File config_directory,
|
||||||
File data_directory)
|
File data_directory)
|
||||||
throws Error {
|
throws Error {
|
||||||
this(config_directory, data_directory);
|
this(id, config_directory, data_directory);
|
||||||
|
|
||||||
KeyFile key_file = new KeyFile();
|
KeyFile key_file = new KeyFile();
|
||||||
key_file.load_from_file(file.get_path() ?? "", KeyFileFlags.NONE);
|
key_file.load_from_file(file.get_path() ?? "", KeyFileFlags.NONE);
|
||||||
|
|
|
||||||
|
|
@ -105,10 +105,11 @@ public class Geary.Engine : BaseObject {
|
||||||
*/
|
*/
|
||||||
public signal void untrusted_host(Geary.AccountInformation account_information,
|
public signal void untrusted_host(Geary.AccountInformation account_information,
|
||||||
Endpoint endpoint, Endpoint.SecurityType security, TlsConnection cx, Service service);
|
Endpoint endpoint, Endpoint.SecurityType security, TlsConnection cx, Service service);
|
||||||
|
|
||||||
private Engine() {
|
// Public so it can be tested
|
||||||
|
public Engine() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void check_opened() throws EngineError {
|
private void check_opened() throws EngineError {
|
||||||
if (!is_open)
|
if (!is_open)
|
||||||
throw new EngineError.OPEN_REQUIRED("Geary.Engine instance not open");
|
throw new EngineError.OPEN_REQUIRED("Geary.Engine instance not open");
|
||||||
|
|
@ -192,10 +193,12 @@ public class Geary.Engine : BaseObject {
|
||||||
FileInfo info = info_list.nth_data(0);
|
FileInfo info = info_list.nth_data(0);
|
||||||
if (info.get_file_type() == FileType.DIRECTORY) {
|
if (info.get_file_type() == FileType.DIRECTORY) {
|
||||||
try {
|
try {
|
||||||
|
string id = info.get_name();
|
||||||
account_list.add(
|
account_list.add(
|
||||||
new AccountInformation.from_file(
|
new AccountInformation.from_file(
|
||||||
user_config_dir.get_child(info.get_name()),
|
id,
|
||||||
user_data_dir.get_child(info.get_name())
|
user_config_dir.get_child(id),
|
||||||
|
user_data_dir.get_child(id)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (Error err) {
|
} catch (Error err) {
|
||||||
|
|
@ -291,8 +294,7 @@ public class Geary.Engine : BaseObject {
|
||||||
throw new EngineError.ALREADY_EXISTS("Account %s already exists", id);
|
throw new EngineError.ALREADY_EXISTS("Account %s already exists", id);
|
||||||
|
|
||||||
return new AccountInformation(
|
return new AccountInformation(
|
||||||
user_config_dir.get_child(id),
|
id, user_config_dir.get_child(id), user_data_dir.get_child(id)
|
||||||
user_data_dir.get_child(id)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue