I have wrote them and posted to my GitHub repos from the official Alpine docker image
testing_nats_msg_broker_pub_sub_client_with_protobuf_alpine/README.md at main ¡ chanvichekaouk/testing_nats_msg_broker_pub_sub_client_with_protobuf_alpine
đ§Ş Mock PublisherâBrokerâSubscriber Unit Test (Catch2 v3 + Protobuf + Alpine) This project demonstrates a mock unitâtest workflow between:
a Publisher client
a NATS message broker
a Subscriber client
using a crossâplatform Protobuf data format, tested with the Catch2 v3 framework and built on the official Alpine Linux image.
The goal is to validate message flow, multiâsubscriber behavior, and protobuf serialization/deserialization in a lightweight, reproducible environment.
đ ď¸ Compiling Tests Manually (g++) You can compile the test suite directly from the terminal:
g++ -Iinclude tests/*.cpp -o test_runners \
-I/usr/local/include -L/usr/local/lib \
-lCatch2Main -lCatch2
Run all tests under a tag:
./test_runners "[tag]"
Run only a specific section under a tag:
./test_runners "[tag]" -c "section_name"
Example:
Run all sections under the tag:
./test_runners "[multi_sub_receive_msg]"
Run only a specific section:
./test_runners "[multi_sub_receive_msg]" -c "Client connects successfully"
Another example:
./test_runners "[multi_sub_receive_msg]" -c "Multiple subscribers receive the same published message"
Screenshots


đŚUsing Protobuf Data Format
Example .proto schema:
syntax = "proto3";
message Telemetry {
int32 id = 1;
int32 temp = 2;
}
đ§ Alpine vs glibc: Why Linking Protobuf Is Harder on Alpine On most Linux distributions that use glibc, linking Protobuf with Abseil is simple. But Alpine uses musl, and Abseil depends on glibcâspecific internals such as futex.
Because musl does not provide these interfaces, Alpine maintainers must:
- patch Abseil heavily
- disable unsupported features
- split Abseil into ~130 microâlibraries
Starting with Protobuf 4.x, Abseil became a mandatory dependency, which makes linking more complex on Alpine.
On glibcâbased systems (Ubuntu, Debian, Fedora) You can link with just a few Abseil libraries:
-labsl -labsl_strings -labsl_log
On Alpine (musl) You must explicitly link the microâlibraries required by your generated Protobuf code:
-lprotobuf -lprotobuf-lite -labsl_base -labsl_strings -labsl_raw_logging_internal -labsl_log_internal_check_op -labsl_log_internal_message -labsl_log_internal_nullguard
Example:
g++ -Iinclude -Iproto \
proto/*.cc tests/*.cpp \
-o test_runners \
-lprotobuf -lprotobuf-lite \
-labsl_base -labsl_strings \
-labsl_raw_logging_internal \
-labsl_log_internal_check_op \
-labsl_log_internal_message \
-labsl_log_internal_nullguard \
-lCatch2Main -lCatch2








