How to unit test logging library?

38 Views Asked by At

I am writing a simple wrapper around sd_journal_send() to implement logging library for our embedded system. I am building and running my tests inside a Docker container. I want to test whether the correct message come out. I am currently using Google Test as my testing framework. The production code is in C.

I have forwarded the journal socket into the container and I can see the messages that are generated in the container on the host. We expect to use this configuration in production to centralize logging of Docker containers onto the host.

For testing tried to setup the Docker container as a remote for the host by adapting these DigitalOcean instructions. However, it fails when building the container because the Docker build system is not running systemd.

How can I parse the logs generated by unit tests? Is it possible to read the hosts journal logs inside the Docker container? Can I redirect locally generated logs in the container to a file or something? Is there some other way I'm missing?

1

There are 1 best solutions below

0
Stephen Rasku On

It turns out it's pretty straightforward to link a different library that contains the sd_journal_send() function so I wrote a mock that writes to a local file.