dzbarsky / rules_itest

Bazel rules for integration testing services
MIT License
18 stars 6 forks source link

Allow for named ports on itest_service_group #33

Closed darkrift closed 1 month ago

darkrift commented 1 month ago

Whenever you have complex initial setup (a service, with tasks to configure said service) hidden behind a macro, the test that refers to those services ends up depending on a service group that is named differently than the named port to connect to.

Example: a kafka broker with multiple itest_itask to create the necessary topics.

You would define an itest_service for the broker name kafka_broker, the itest_itasks for the topics and an itest_service_group to group all of them together.

The SUT then depends on the itest_service_group (for instance kafka_service_group), but the named port replacement is going to be that of the broker kafka_broker

    itest_service(
        name = "SUT",
        env = {
            "KAFKA_ADDRESS": "127.0.0.1:$${@@//<package>:kafka_broker:main_port}",
        },
        deps = [
            "//<package>:kafka_service_group",
        ],
...
    )

An idea could be to allow itest_service_group to define named ports that would only be used by the dependencies to unify the exposed target to depend on and the port names

dzbarsky commented 1 month ago

Want to see if https://github.com/dzbarsky/rules_itest/commit/edd88931960c1fb346ee5a53df5b0ac1d07df751 works for you?

We actually don't restrict the named ports to just the dependencies - in general, the entire port mapping is global (that's pretty handy for cases when you have optional dependencies, want to arrange services into groups for parallel startup, etc). So this mostly "just worked" when adding the attributes

darkrift commented 1 month ago

It does ! Thanks alot 😃