Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/dynamodb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ itest_service(
autoassign_port = True,
exe = ":bin",
health_check = ":health_check",
visibility = ["//visibility:public"],
)

go_library(
Expand Down
24 changes: 24 additions & 0 deletions examples/redis/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,27 @@ itest_service(
"PING",
],
)

itest_service(
name = "redis_network",
args = [
"--port",
"$${PORT}",
"--dir",
"$${TMPDIR}",
],
autoassign_port = True,
exe = "@com_github_redis_redis//:redis",
health_check = "@com_github_redis_redis//:redis_cli",
health_check_args = [
"-h",
"localhost",
"-p",
"$${PORT}",
"PING",
],
tags = [
"requires-network",
],
visibility = ["//visibility:public"],
)
15 changes: 15 additions & 0 deletions examples/service_group/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@rules_itest//:itest.bzl", "itest_service_group", "port_alias")

itest_service_group(
name = "service_group",
port_aliases = {
"dynamodb": port_alias("//dynamodb"),
"mysql": port_alias("//mysql:mysql_listening_on_port"),
"redis": port_alias("//redis:redis_network"),
},
services = [
"//dynamodb:dynamodb",
"//mysql:mysql_listening_on_port",
"//redis:redis_network",
],
)
32 changes: 30 additions & 2 deletions itest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,39 @@ load(
_service_test = "service_test",
)

def _to_relative_port(label):
return str(native.package_relative_label(label))

def _to_relative_named_port(label, name):
return _to_relative_port(label + "." + name)

def port(label):
return "$${%s}" % (str(native.package_relative_label(label)))
"""This function is used to reference the auto assigned port of a service in the `args` or `env` attributes of an `itest_service` or `itest_task`.

To reference the auto assigned port in the `itest_service_group` use `port_alias` instead
"""
return "$${%s}" % _to_relative_port(label)

def named_port(label, name):
return port(label + "." + name)
"""This function is used to reference a named port of a service in the `args` or `env` attributes of an `itest_service` or `itest_task`.

To reference a named port in the `itest_service_group` use `named_port_alias` instead
"""
return port(_to_relative_named_port(label, name))

def port_alias(label):
"""This function is used to reference the auto assigned port of a service in the `aliases` attribute of an `itest_service_group`.

To reference the auto assigned port in `itest_service` or `itest_task` use `port` instead
"""
return _to_relative_port(label)

def named_port_alias(label, name):
"""This function is used to reference a named port of a service in the `aliases` attribute of an `itest_service_group`.

To reference a named port in `itest_service` or `itest_task` use `named_port` instead
"""
return _to_relative_named_port(label, name)

def itest_service(name, tags = [], hygienic = True, named_ports = [], **kwargs):
if "port" in kwargs:
Expand Down
6 changes: 4 additions & 2 deletions private/itest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ _itest_service_attrs = _itest_binary_attrs | {
For example, the following Bash command:
`PORT=$($GET_ASSIGNED_PORT_BIN @@//label/for:service)`""",
),
"port": attr.label(doc="Internal"),
"port": attr.label(doc = "Internal"),
"named_ports": attr.label_keyed_string_dict(
doc = """For each element of the list, the service manager will pick a free port and assign it to the service.
The port's fully-qualified name is the service's fully-qualified label and the port name, separated by a colon.
Expand Down Expand Up @@ -375,7 +375,9 @@ _itest_service_group_attrs = _svcinit_attrs | {
"port_aliases": attr.string_dict(
doc = """Port aliases allow you to 're-export' another service's port as belonging to this service group.
This can be used to create abstractions (such as an itest_service combined with an itest_task) but not leak
their implementation through how client code accesses port names.""",
their implementation naming details through how client code accesses port names.

Use the functions `port_alias` and `named_port_alias` to reference ports from the services to alias ports for""",
),
"services": attr.label_list(
providers = [_ServiceGroupInfo],
Expand Down
Loading