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
9 changes: 9 additions & 0 deletions modules/go/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ load(
"go_macro_general_mode_linker_flags_target",
"go_macro_general_mode_linker_flags_wiring_test",
"go_macro_inferred_importpath_metadata_test",
"go_macro_internal_helper_tags_loading_tests",
"go_macro_multi_service_target",
"go_macro_multi_service_wiring_test",
"go_macro_orchestrion_pin_files_provider_test",
Expand Down Expand Up @@ -799,6 +800,13 @@ go_macro_static_wiring_test(
target_under_test = ":go_macro_static_target__raw_go_test",
)

go_macro_internal_helper_tags_loading_tests(
name = "go_macro_internal_helper_tags",
disabled_target = "go_macro_disabled_raw_target",
dynamic_target = "go_macro_single_service_target",
static_target = "go_macro_static_target",
)

go_macro_static_fallback_metadata_test(
name = "go_macro_static_fallback_metadata_test",
target_under_test = ":go_macro_static_target_topt_bazel_metadata",
Expand Down Expand Up @@ -987,6 +995,7 @@ test_suite(
":go_macro_env_none_wiring_test",
":go_macro_explicit_service_wiring_test",
":go_macro_inferred_importpath_metadata_test",
":go_macro_internal_helper_tags_tests",
":go_macro_multi_service_wiring_test",
":go_macro_orchestrion_pin_files_provider_test",
":go_macro_orchestrion_pin_files_wiring_test",
Expand Down
41 changes: 40 additions & 1 deletion modules/go/tests/test_macro.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ with a lightweight fake executable rule so we can capture what the macro
forwards at analysis time without compiling Go code.
"""

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "loadingtest", "unittest")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"@datadog-rules-test-optimization-go//:topt_go_infer.bzl",
Expand Down Expand Up @@ -364,6 +364,45 @@ def go_macro_static_identity_mismatch_target(name, tags = None):
tags = tags,
)

def go_macro_internal_helper_tags_loading_tests(
name,
dynamic_target,
static_target,
disabled_target):
"""Assert generated implementation targets stay out of wildcard selection."""
env = loadingtest.make(name)

for target_kind, target_name in [
("dynamic", dynamic_target),
("static", static_target),
]:
for helper_kind, suffix in [
("payloads", "_topt_payloads"),
("metadata", "_topt_bazel_metadata"),
]:
helper = native.existing_rule(target_name + suffix)
loadingtest.equals(
env,
"%s_%s_helper_tags" % (target_kind, helper_kind),
("manual",),
helper.get("tags", []) if helper else None,
)

# Generated exports already know they are disabled during macro expansion,
# so they must continue to emit only the caller's ordinary Go test.
loadingtest.equals(
env,
"disabled_payloads_helper_absent",
None,
native.existing_rule(disabled_target + "_topt_payloads"),
)
loadingtest.equals(
env,
"disabled_metadata_helper_absent",
None,
native.existing_rule(disabled_target + "_topt_bazel_metadata"),
)

def go_macro_disabled_raw_target(name, tags = None):
"""Target under test for the strict disabled raw go_test branch."""
dd_topt_go_test(
Expand Down
6 changes: 6 additions & 0 deletions modules/go/topt_go_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ def dd_topt_go_test(
# phase, keeping runtime logic and user callsites simple.
topt_go_payloads_selector(
name = selector_name,
# The public test owns selection; this implementation detail should
# never become a top-level target through wildcard expansion.
tags = ["manual"],
embeds = embed_labels,
explicit_importpath = explicit_importpath,
fallback_importpath = fallback_importpath,
Expand All @@ -611,6 +614,9 @@ def dd_topt_go_test(
# configuration does not produce a false positive.
topt_go_bazel_metadata(
name = metadata_name,
# Keep metadata generation attached to the public test instead of
# exposing it as an independently selectable wildcard target.
tags = ["manual"],
embeds = embed_labels,
explicit_importpath = explicit_importpath or "",
fallback_importpath = fallback_importpath or "",
Expand Down
Loading