godbus / dbus

Native Go bindings for D-Bus
BSD 2-Clause "Simplified" License
959 stars 222 forks source link

peer to peer connection #354

Closed tanshihaj closed 1 year ago

tanshihaj commented 1 year ago

I want to mock ModemManager's dbus interface in my program to test its functionality. I think that most honest way is to create peer-to-peer connection and mock ModemManager's behavior. Is it possible to do it with this library?

guelfey commented 1 year ago

I see basically 3 options:

  1. Using NewConn you can indeed create a peer to peer connection, and then create a whole mock implementation of a server using this. But that would require lots of test harnessing code and include the overhead of all the D-Bus encoding and decoding, thus more testing this library and not your actual application code.
  2. You can mock away BusObject, which is a kind of large interface, but you can focus on implementing only what your application uses.
  3. Handle this from your own code: e.g. create a ModemManager interface whose real implementation just calls the D-Bus method, then mock it away in tests.