Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions .github/workflows/flatpak.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
on:
push:
branches: [main]
branches: [main, develop]
pull_request:
name: Build flatpak
jobs:
flatpak:
name: "Flatpak"
runs-on: ubuntu-latest
container:
image: bilelmoussaoui/flatpak-github-actions:gnome-46
options: --privileged
image: bilelmoussaoui/flatpak-github-actions:gnome-47
options: >-
--privileged
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
bundle: io.github.ppvan.tarug.flatpak
manifest-path: pkgs/flatpak/io.github.ppvan.tarug.yml
cache-key: flatpak-builder-${{ github.sha }}
- uses: actions/checkout@v4
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
bundle: io.github.ppvan.tarug.flatpak
manifest-path: pkgs/flatpak/io.github.ppvan.tarug.yml
cache-key: flatpak-builder-${{ github.sha }}
run-tests: true
21 changes: 0 additions & 21 deletions .vscode/settings.json

This file was deleted.

20 changes: 8 additions & 12 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"label": "Meson (Flatpak): Run Unit test",
"type": "shell",
"command": "meson compile -C build",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Setup",
"type": "shell",
"command": "meson setup build --reconfigure",
"options": {
// Match meson buildPath
"cwd": "${workspaceFolder}/_build"
},
"group": "test",
// mesonbuild.mesonPath
"command": "${workspaceFolder}/.flatpak/meson.sh test",
}
]
}
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ valac = meson.get_compiler('vala')
subdir('data')
subdir('resources')
subdir('src')
subdir('tests')
subdir('po')

# Using gnome module to do some task after the app is installed, like compile schema (settings data)
Expand Down
13 changes: 9 additions & 4 deletions pkgs/flatpak/io.github.ppvan.tarug.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app-id: io.github.ppvan.tarug
runtime: org.gnome.Platform
runtime-version: '47'
runtime-version: "47"
sdk: org.gnome.Sdk

sdk-extensions:
Expand All @@ -26,11 +26,16 @@ cleanup:
- /share/man
- /share/pkgconfig
- /share/vala
- '*.la'
- '*.a'
- "*.la"
- "*.a"
modules:
- name: tarug
buildsystem: meson
build-options:
test-args:
- "--socket=x11"
- "--share=network"
- "--env=POSTGRES_HOST=postgres"
sources:
- type: dir
path: ../../
Expand All @@ -42,7 +47,7 @@ modules:
url: https://gitlab.gnome.org/jwestman/blueprint-compiler
tag: v0.14.0
cleanup:
- '*'
- "*"
- name: postgresql-libs
buildsystem: simple
build-commands:
Expand Down
49 changes: 0 additions & 49 deletions src/cmd.vala

This file was deleted.

15 changes: 0 additions & 15 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,3 @@ executable(
],
install: true,
)


tarug_sources_test = tarug_sources + files('cmd.vala')
test(
'foo',
executable(
'tarug_test',
[tarug_resources, tarug_sources_test],
dependencies: tarug_deps,
vala_args: [
'--gresourcesdir=' + tarug_resources_dir,
]
),
protocol: 'tap',
)
6 changes: 5 additions & 1 deletion src/models/Connection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ namespace Tarug {
public string connection_string (int connection_timeout, int query_timeout){
var ssl_mode = use_ssl ? "verify-full" : "disable";
var options = @"\'-c statement_timeout=$(query_timeout * 1000)\'";
var res = Resolver.get_default ();
var adds = res.lookup_by_name (host, null);

var base_str = @"user=$user password=$password port=$port host=$host dbname=$database application_name=$(Config.APP_NAME) sslmode=$ssl_mode connect_timeout=$connection_timeout options=$options";
var host_addr = adds.nth_data (0).to_string ();

var base_str = @"user=$user password=$password port=$port hostaddr=$host_addr dbname=$database application_name=$(Config.APP_NAME) sslmode=$ssl_mode connect_timeout=$connection_timeout options=$options";
var builder = new StringBuilder(base_str);

if (use_ssl) {
Expand Down
6 changes: 6 additions & 0 deletions src/services/SQLService.vala
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ namespace Tarug {
}
}

public void close_db() {
this.active_db = null;
this.active_chanel = null;
this.active_result = null;
}

private void start_connect(string db_url) throws TarugError {
active_db = Postgres.connect_start (db_url);
var status = active_db.get_status ();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/logging.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Tarug {
var prog = GLib.Environment.get_prgname();
GLib.on_error_stack_trace(prog);

Log.set_handler(Config.G_LOG_DOMAIN, LogLevelFlags.LEVEL_DEBUG | LogLevelFlags.LEVEL_WARNING, log_function);
switch (debug_domain) {
case Config.G_LOG_DOMAIN, "all":
Log.set_handler(Config.G_LOG_DOMAIN, LogLevelFlags.LEVEL_DEBUG | LogLevelFlags.LEVEL_WARNING, log_function);
break;

default:
Expand Down
39 changes: 39 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
gnome = import('gnome')

conf = configuration_data()

conf.set_quoted('APP_ID', app_id)
conf.set_quoted('APP_NAME', 'Tarug')
conf.set_quoted('G_LOG_DOMAIN', 'Tarug')
conf.set_quoted('VERSION', meson.project_version())
conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
conf.set_quoted(
'DATADIR',
join_paths(get_option('prefix'), get_option('datadir')),
)
conf.set_quoted(
'GNOMELOCALEDIR',
join_paths(get_option('prefix'), get_option('localedir')),
)
configure_file(output: 'config.h', configuration: conf)


tests = [
'sql_connect',
]

foreach name : tests
test(
name,
executable(
name + '_test',
[tarug_resources, tarug_sources, 'test_runtime.vala', name + '_test.vala'],
dependencies: tarug_deps,
vala_args: [
'--gresourcesdir=' + tarug_resources_dir,
]
),
protocol: 'tap',
env: ['G_TEST_SRCDIR=' + meson.current_source_dir()]
)
endforeach
64 changes: 64 additions & 0 deletions tests/sql_connect_test.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Tarug;


void test_connect_db_ok (){

var main_loop = GLib.MainContext.default();
var waiter = new AsyncResultWaiter(main_loop);
var sql_service = new SQLService();
var conn = new Connection("test conn") {
host = Environment.get_variable ("POSTGRES_HOST") ?? "127.0.0.1",
port = "5432",
user = "postgres",
password = "postgres",
database = "postgres"
};


sql_service.connect_db.begin(conn, waiter.async_completion);

try {
sql_service.connect_db.end(waiter.async_result());
sql_service.close_db ();
} catch (TarugError err) {
Test.fail_printf(err.message);
}
}

void test_connect_db_fail (){
var main_loop = GLib.MainContext.default();
var waiter = new AsyncResultWaiter(main_loop);
var sql_service = new SQLService();

var conn = new Connection("wrong database config") {
host = Environment.get_variable ("POSTGRES_HOST") ?? "127.0.0.1",
port = "5432",
user = "postgres",
password = "postgres",
database = "dogsarethebest"
};


sql_service.connect_db.begin(conn, waiter.async_completion);

try {
sql_service.connect_db.end(waiter.async_result());
sql_service.close_db ();
} catch (TarugError err) {
printerr (err.message);
}
}

public int main (string[] args){
Test.init(ref args);

var container = Container.instance();
var settings = new Settings(Config.APP_ID);
container.register(settings);

// Test.add_func("/database/connect_fail", test_connect_db_fail);
Test.add_func("/database/connect_success", test_connect_db_ok);


return Test.run();
}
Loading