diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 347e83e..4752ca1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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/ diff --git a/meson.build b/meson.build index 1dbd588..b6f9f0a 100644 --- a/meson.build +++ b/meson.build @@ -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', ) diff --git a/xyz-iinuwa-credential-manager-portal-gtk/tests/dbus.rs b/xyz-iinuwa-credential-manager-portal-gtk/tests/dbus.rs index b65918c..2089b9d 100644 --- a/xyz-iinuwa-credential-manager-portal-gtk/tests/dbus.rs +++ b/xyz-iinuwa-credential-manager-portal-gtk/tests/dbus.rs @@ -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 = body.deserialize().unwrap(); + let rsp: HashMap = body.deserialize::>().unwrap() + .into_iter() + .map(|(k, v)| (k, v.try_into().unwrap())) + .collect(); let capabilities = HashMap::from([ ("conditionalCreate", false), @@ -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); } } @@ -35,28 +38,16 @@ 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(&self, method_name: &str, body: &B) -> zbus::Result @@ -64,7 +55,15 @@ mod client { 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(); } } } diff --git a/xyz-iinuwa-credential-manager-portal-gtk/tests/meson.build b/xyz-iinuwa-credential-manager-portal-gtk/tests/meson.build index 549b598..cf289d9 100644 --- a/xyz-iinuwa-credential-manager-portal-gtk/tests/meson.build +++ b/xyz-iinuwa-credential-manager-portal-gtk/tests/meson.build @@ -28,7 +28,7 @@ configure_file( ) test( - 'cargo dbus tests', + 'dbus', cargo, env: [cargo_env], args: [ @@ -40,4 +40,4 @@ test( ], protocol: 'exitcode', verbose: true, -) \ No newline at end of file +)