Skip to content

Commit

Permalink
Updating python acceptance tests to accept multiple builders
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 570779908
Change-Id: If140fcfe6a5ea8b60b50fbba56ee6668fc9bb8fb
  • Loading branch information
Sriram Mahavadi authored and copybara-github committed Oct 4, 2023
1 parent 5f0efdd commit 74c408b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
31 changes: 20 additions & 11 deletions builders/python/acceptance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,15 @@ acceptance_test_suite(
],
builder = "//builders/python:builder.tar",
rundir = ".",
runtime_to_builder_map = {
"python310": "//builders/python:builder_22.tar",
"python311": "//builders/python:builder_22.tar",
"python312": "//builders/python:builder_22.tar",
},
testdata = "//builders/testdata/python:generic",
versions = VERSIONS_WITH_GCP_SUPPORT,
)

acceptance_test_suite(
name = "gcp_test_builder_22",
srcs = [
"gcp_test.go",
],
builder = "//builders/python:builder_22.tar",
rundir = ".",
testdata = "//builders/testdata/python:generic",
versions = {"python311": "3.11.6"},
)

acceptance_test_suite(
name = "gae_test",
srcs = [
Expand All @@ -63,6 +57,11 @@ acceptance_test_suite(
argsmap = pythonargs(),
builder = "//builders/python:builder.tar",
rundir = ".",
runtime_to_builder_map = {
"python310": "//builders/python:builder_22.tar",
"python311": "//builders/python:builder_22.tar",
"python312": "//builders/python:builder_22.tar",
},
testdata = "//builders/testdata/python:appengine",
versions = VERSIONS_WITH_GAE_SUPPORT,
)
Expand All @@ -74,6 +73,11 @@ acceptance_test_suite(
],
builder = "//builders/python:builder.tar",
rundir = ".",
runtime_to_builder_map = {
"python310": "//builders/python:builder_22.tar",
"python311": "//builders/python:builder_22.tar",
"python312": "//builders/python:builder_22.tar",
},
testdata = "//builders/testdata/python:functions",
versions = VERSIONS_WITH_GCF_SUPPORT,
)
Expand All @@ -83,6 +87,11 @@ acceptance_test_suite(
srcs = ["flex_test.go"],
builder = "//builders/python:builder.tar",
rundir = ".",
runtime_to_builder_map = {
"python310": "//builders/python:builder_22.tar",
"python311": "//builders/python:builder_22.tar",
"python312": "//builders/python:builder_22.tar",
},
testdata = "//builders/testdata/python:flex",
versions = VERSIONS_WITH_FLEX_SUPPORT,
)
Expand Down
30 changes: 19 additions & 11 deletions internal/acceptance/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def acceptance_test_suite(
name,
srcs,
testdata,
builder,
builder = None,
structure_test_config = ":config.yaml",
versions = {},
runtime_to_builder_map = None,
args = None,
deps = None,
argsmap = None,
Expand All @@ -51,29 +52,30 @@ def acceptance_test_suite(
argsmap: version specific arguments map where the key is the version and the value is a list of flags that will be passed to the acceptance test framework
**kwargs: this argument captures all additional arguments and forwards them to the generated go_test rule
"""

test_args = _build_args(args, name, testdata, builder, structure_test_config)
data = _build_data(structure_test_config, builder, testdata)
deps = _build_deps(deps)

_build_tests(name, srcs, test_args, data, deps, versions, argsmap, **kwargs)
_build_tests(name, srcs, args, testdata, builder, structure_test_config, deps, versions, runtime_to_builder_map, argsmap, **kwargs)
_cloudbuild_targets(name, srcs, structure_test_config, builder, args, deps, versions, argsmap, testdata)

def _build_tests(name, srcs, args, data, deps, versions, argsmap, **kwargs):
def _build_tests(name, srcs, args, testdata, builder, structure_test_config, deps, versions, runtime_to_builder_map, argsmap, **kwargs):
# if there are no versions passed in then create a go_test(...) rule directly without changing
# the name of the test
if versions == {}:
_new_go_test_for_single_version(name, srcs, args, data, deps, **kwargs)
test_args = _build_args(args, name, testdata, builder, structure_test_config)
data = _build_data(structure_test_config, builder, testdata)
_new_go_test_for_single_version(name, srcs, test_args, data, deps, **kwargs)
else:
_new_go_test_for_versions(versions, name, srcs, args, data, deps, argsmap, **kwargs)
_new_go_test_for_versions(versions, name, srcs, args, testdata, builder, structure_test_config, runtime_to_builder_map, deps, argsmap, **kwargs)

def _new_go_test_for_versions(versions, name, srcs, args, data, deps, argsmap, **kwargs):
def _new_go_test_for_versions(versions, name, srcs, args, testdata, builder, structure_test_config, runtime_to_builder_map, deps, argsmap, **kwargs):
tests = []
if type(versions) == type({}):
for _n, v in versions.items():
selected_builder = _select_builder(builder, runtime_to_builder_map, _n)
test_args = _build_args(args, name, testdata, selected_builder, structure_test_config)
data = _build_data(structure_test_config, selected_builder, testdata)
ver_name = v + "_" + name
tests.append(ver_name)
ver_args = list(args)
ver_args = list(test_args)
ver_args.append("-runtime-version=" + v)

if argsmap != None and argsmap.get(v) != None:
Expand All @@ -93,6 +95,12 @@ def _new_go_test_for_versions(versions, name, srcs, args, data, deps, argsmap, *
if len(tests) > 0:
_new_bin_filegroup_alias(name, tests[0])

def _select_builder(builder, runtime_to_builder_map, runtime):
selected_builder = builder
if runtime_to_builder_map != None and runtime in runtime_to_builder_map:
selected_builder = runtime_to_builder_map[runtime]
return selected_builder

def _new_go_test_for_single_version(name, srcs, args, data, deps, **kwargs):
_new_go_test(name, srcs, args, data, deps, **kwargs)
_new_bin_filegroup_alias(name, name)
Expand Down

0 comments on commit 74c408b

Please sign in to comment.