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
15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ jobs:
- name: Install system dependencies
run: |
sudo apt install -y --no-install-recommends \
curl git build-essential meson \
curl git build-essential \
libgtk-4-dev gettext libdbus-1-dev libssl-dev libudev-dev \
libxml2-utils desktop-file-utils
libxml2-utils desktop-file-utils \
python3-pip ninja-build
- name: Install Meson
run: |
# Newer version needed for --interactive flag needed below
python3 -m pip install --user -v 'meson==1.5.0'
- name: Setup meson project
run: meson setup build
- name: Build
run: ninja -C build
- name: Test
# We have to use the --interactive flag because of some
# weird issue with meson hanging after cargo exits due to the TestDBus.
# Probably has to do with forking the test processes.
run: meson test --interactive
working-directory: build/
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project(
'xyz-iinuwa-credential-manager-portal-gtk',
'rust',
version: '0.1.0',
meson_version: '>= 0.60',
meson_version: '>= 1.5.0',
# license: 'MIT',
)

Expand Down
41 changes: 20 additions & 21 deletions xyz-iinuwa-credential-manager-portal-gtk/tests/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ fn test_client_capabilities() {
let client = DbusClient::new();
let msg = client.call_method("GetClientCapabilities", &()).unwrap();
let body = msg.body();
let rsp: HashMap<String, Value> = body.deserialize().unwrap();
let rsp: HashMap<String, bool> = body.deserialize::<HashMap<String, Value>>().unwrap()
.into_iter()
.map(|(k, v)| (k, v.try_into().unwrap()))
.collect();

let capabilities = HashMap::from([
("conditionalCreate", false),
Expand All @@ -24,8 +27,8 @@ fn test_client_capabilities() {
("signalUnknownCredential", false),
]);
for (key, expected) in capabilities.iter() {
let value: &Value = rsp.get(*key).unwrap();
assert_eq!(*expected, value.try_into().unwrap());
let actual = rsp.get(*key).unwrap();
assert_eq!(*expected, *actual);
}
}

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

fn init_test_dbus() -> TestDBus {
let dbus = TestDBus::new(TestDBusFlags::NONE);

// assumes this runs in root of Cargo project.
let current_dir = std::env::current_dir().unwrap();
let service_dir = current_dir.join(SERVICE_DIR);
println!("{:?}", service_dir);
dbus.add_service_dir(service_dir.to_str().unwrap());

dbus.up();
dbus
}

pub(super) struct DbusClient {
_bus: TestDBus,
bus: TestDBus,
}

impl DbusClient {
pub fn new() -> Self {
Self {
_bus: init_test_dbus(),
}
let bus = TestDBus::new(TestDBusFlags::NONE);
bus.add_service_dir(SERVICE_DIR);
bus.up();
Self { bus }
}

pub fn call_method<B>(&self, method_name: &str, body: &B) -> zbus::Result<Message>
where
B: Serialize + DynamicType,
{
let connection = Connection::session().unwrap();
connection.call_method(Some(SERVICE_NAME), PATH, Some(INTERFACE), method_name, body)
let message = connection.call_method(Some(SERVICE_NAME), PATH, Some(INTERFACE), method_name, body);
connection.close().unwrap();
message
}

}
impl Drop for DbusClient {
fn drop(&mut self) {
self.bus.stop();
}
}
}
4 changes: 2 additions & 2 deletions xyz-iinuwa-credential-manager-portal-gtk/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ configure_file(
)

test(
'cargo dbus tests',
'dbus',
cargo,
env: [cargo_env],
args: [
Expand All @@ -40,4 +40,4 @@ test(
],
protocol: 'exitcode',
verbose: true,
)
)