Skip to content

Commit ac93625

Browse files
authored
Merge pull request #18 from linux-credentials/ci/tests
Ci/tests
2 parents 63ec9a0 + 7e89084 commit ac93625

4 files changed

Lines changed: 36 additions & 26 deletions

File tree

.github/workflows/main.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ jobs:
1818
- name: Install system dependencies
1919
run: |
2020
sudo apt install -y --no-install-recommends \
21-
curl git build-essential meson \
21+
curl git build-essential \
2222
libgtk-4-dev gettext libdbus-1-dev libssl-dev libudev-dev \
23-
libxml2-utils desktop-file-utils
23+
libxml2-utils desktop-file-utils \
24+
python3-pip ninja-build
25+
- name: Install Meson
26+
run: |
27+
# Newer version needed for --interactive flag needed below
28+
python3 -m pip install --user -v 'meson==1.5.0'
2429
- name: Setup meson project
2530
run: meson setup build
2631
- name: Build
2732
run: ninja -C build
33+
- name: Test
34+
# We have to use the --interactive flag because of some
35+
# weird issue with meson hanging after cargo exits due to the TestDBus.
36+
# Probably has to do with forking the test processes.
37+
run: meson test --interactive
38+
working-directory: build/

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ project(
22
'xyz-iinuwa-credential-manager-portal-gtk',
33
'rust',
44
version: '0.1.0',
5-
meson_version: '>= 0.60',
5+
meson_version: '>= 1.5.0',
66
# license: 'MIT',
77
)
88

xyz-iinuwa-credential-manager-portal-gtk/tests/dbus.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ fn test_client_capabilities() {
1010
let client = DbusClient::new();
1111
let msg = client.call_method("GetClientCapabilities", &()).unwrap();
1212
let body = msg.body();
13-
let rsp: HashMap<String, Value> = body.deserialize().unwrap();
13+
let rsp: HashMap<String, bool> = body.deserialize::<HashMap<String, Value>>().unwrap()
14+
.into_iter()
15+
.map(|(k, v)| (k, v.try_into().unwrap()))
16+
.collect();
1417

1518
let capabilities = HashMap::from([
1619
("conditionalCreate", false),
@@ -24,8 +27,8 @@ fn test_client_capabilities() {
2427
("signalUnknownCredential", false),
2528
]);
2629
for (key, expected) in capabilities.iter() {
27-
let value: &Value = rsp.get(*key).unwrap();
28-
assert_eq!(*expected, value.try_into().unwrap());
30+
let actual = rsp.get(*key).unwrap();
31+
assert_eq!(*expected, *actual);
2932
}
3033
}
3134

@@ -35,36 +38,32 @@ mod client {
3538
use serde::Serialize;
3639
use zbus::{blocking::Connection, zvariant::DynamicType, Message};
3740

38-
fn init_test_dbus() -> TestDBus {
39-
let dbus = TestDBus::new(TestDBusFlags::NONE);
40-
41-
// assumes this runs in root of Cargo project.
42-
let current_dir = std::env::current_dir().unwrap();
43-
let service_dir = current_dir.join(SERVICE_DIR);
44-
println!("{:?}", service_dir);
45-
dbus.add_service_dir(service_dir.to_str().unwrap());
46-
47-
dbus.up();
48-
dbus
49-
}
50-
5141
pub(super) struct DbusClient {
52-
_bus: TestDBus,
42+
bus: TestDBus,
5343
}
5444

5545
impl DbusClient {
5646
pub fn new() -> Self {
57-
Self {
58-
_bus: init_test_dbus(),
59-
}
47+
let bus = TestDBus::new(TestDBusFlags::NONE);
48+
bus.add_service_dir(SERVICE_DIR);
49+
bus.up();
50+
Self { bus }
6051
}
6152

6253
pub fn call_method<B>(&self, method_name: &str, body: &B) -> zbus::Result<Message>
6354
where
6455
B: Serialize + DynamicType,
6556
{
6657
let connection = Connection::session().unwrap();
67-
connection.call_method(Some(SERVICE_NAME), PATH, Some(INTERFACE), method_name, body)
58+
let message = connection.call_method(Some(SERVICE_NAME), PATH, Some(INTERFACE), method_name, body);
59+
connection.close().unwrap();
60+
message
61+
}
62+
63+
}
64+
impl Drop for DbusClient {
65+
fn drop(&mut self) {
66+
self.bus.stop();
6867
}
6968
}
7069
}

xyz-iinuwa-credential-manager-portal-gtk/tests/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ configure_file(
2828
)
2929

3030
test(
31-
'cargo dbus tests',
31+
'dbus',
3232
cargo,
3333
env: [cargo_env],
3434
args: [
@@ -40,4 +40,4 @@ test(
4040
],
4141
protocol: 'exitcode',
4242
verbose: true,
43-
)
43+
)

0 commit comments

Comments
 (0)