Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][infra][2/5] feat: bazel rules support for integration test #393

Merged
merged 29 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9ad33d2
add goldens files for redis client lib
xiaozhenliu-gg5 Oct 8, 2020
20a548a
add bazel file
xiaozhenliu-gg5 Oct 8, 2020
cad27bb
format
xiaozhenliu-gg5 Oct 8, 2020
0b740d5
Merge branch 'master' into add_redis_goldens
xiaozhenliu-gg5 Oct 8, 2020
589841a
Merge branch 'master' of github.com:googleapis/gapic-generator-java i…
xiaozhenliu-gg5 Oct 8, 2020
8e1edfb
add todo comment for Redis client lib goldens
xiaozhenliu-gg5 Oct 9, 2020
59d9eb1
Merge branch 'add_redis_goldens' of github.com:googleapis/gapic-gener…
xiaozhenliu-gg5 Oct 9, 2020
5477463
add README to integration test goldens folder
xiaozhenliu-gg5 Oct 9, 2020
5de4d5a
Merge branch 'master' into add_redis_goldens
xiaozhenliu-gg5 Oct 9, 2020
3ec0803
Merge branch 'master' into add_redis_goldens
xiaozhenliu-gg5 Oct 9, 2020
8ef95c7
Merge branch 'master' into add_redis_goldens
xiaozhenliu-gg5 Oct 10, 2020
a7659fb
Merge branch 'master' into add_redis_goldens
xiaozhenliu-gg5 Oct 10, 2020
d36f040
update redis goldens using micro
xiaozhenliu-gg5 Oct 10, 2020
bc3f47e
Merge branch 'add_redis_goldens' of github.com:googleapis/gapic-gener…
xiaozhenliu-gg5 Oct 10, 2020
b38559a
add bazel rules
xiaozhenliu-gg5 Oct 12, 2020
62bdbc9
remove package-info
xiaozhenliu-gg5 Oct 12, 2020
bc43026
add bazel rules for integration test
xiaozhenliu-gg5 Oct 13, 2020
4ae798d
take api name as arg
xiaozhenliu-gg5 Oct 13, 2020
8b97ac2
Merge branch 'master' of github.com:googleapis/gapic-generator-java i…
xiaozhenliu-gg5 Oct 13, 2020
5e65c2d
feedback
xiaozhenliu-gg5 Oct 13, 2020
c799270
Merge branch 'master' into redis_integration_test
xiaozhenliu-gg5 Oct 13, 2020
c23d309
Merge branch 'master' of github.com:googleapis/gapic-generator-java i…
xiaozhenliu-gg5 Oct 13, 2020
658f4b7
work
xiaozhenliu-gg5 Oct 14, 2020
8b79f53
Merge branch 'redis_integration_test' of github.com:googleapis/gapic-…
xiaozhenliu-gg5 Oct 14, 2020
cfde217
emit diff to test.log
xiaozhenliu-gg5 Oct 20, 2020
23154f1
fix diff command
xiaozhenliu-gg5 Oct 20, 2020
9cf077e
rename
xiaozhenliu-gg5 Oct 20, 2020
d59b426
add api name to outputs
xiaozhenliu-gg5 Oct 20, 2020
a574038
Merge branch 'master' into redis_integration_test
xiaozhenliu-gg5 Oct 21, 2020
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
82 changes: 82 additions & 0 deletions rules_bazel/java/java_integration_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
def _compare_with_goldens_test_impl(ctx):
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
diff_output = ctx.outputs.diff_output
check_diff_script = ctx.outputs.check_diff_script
input = ctx.attr.api_target
srcs = ctx.files.srcs
api_name = ctx.attr.name

script = """
mkdir codegen_tmp
unzip -j {input} -d codegen_tmp
unzip -j {input_resource_name} -d codegen_tmp
unzip -j {input_test} -d codegen_tmp
cd codegen_tmp
# Remove unneeded non-Java files, like MANIFEST
rm -rf $(find . -type f ! -name "*.java")
cd ..
diff codegen_tmp test/integration/goldens/{api_name}/ > {diff_output}
""".format(
diff_output = diff_output.path,
input = input[0][JavaInfo].source_jars[0].path,
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
input_resource_name = input[1][JavaInfo].source_jars[0].path,
input_test = input[2][JavaInfo].source_jars[0].path,
api_name = api_name
)
ctx.actions.run_shell(
inputs = srcs + [
input[0][JavaInfo].source_jars[0],
input[1][JavaInfo].source_jars[0],
input[2][JavaInfo].source_jars[0],
],
outputs = [diff_output],
command = script,
)


check_diff_script_content = """
cd ${{BUILD_WORKSPACE_DIRECTORY}}
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
if [ -s {diff_output} ]
then
cat {diff_output}
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
exit 1
else
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
exit 0
fi
""".format(
diff_output = diff_output.path,
)
ctx.actions.write(
output = check_diff_script,
content = check_diff_script_content,
is_executable = True,
)
return [DefaultInfo(executable = check_diff_script)]


compare_with_goldens_test = rule(
attrs = {
"api_target": attr.label_list(),
"srcs": attr.label_list(
allow_files = True,
mandatory = True,
),
},
outputs = {
"diff_output": "%{name}_diff.txt",
"check_diff_script": "check_diff_script.sh",
},
implementation = _compare_with_goldens_test_impl,
test = True,
)


def integration_test(name, target, data):
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
compare_with_goldens_test(
name = name,
api_target = [
target,
"%s_resource_name" % target,
"%s_test" % target
],
srcs = data,
)
11 changes: 11 additions & 0 deletions test/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ load(
java_gapic_library = "java_gapic_library2",
)

load(
"//:rules_bazel/java/java_integration_test.bzl",
"integration_test",
)

package(default_visibility = ["//visibility:public"])

####################################################
Expand Down Expand Up @@ -50,3 +55,9 @@ java_gapic_library(
"@com_google_googleapis//google/cloud/redis/v1:redis_java_proto",
],
)

integration_test(
name = "redis",
target = ":redis_java_gapic",
data = ["//test/integration/goldens/redis:goldens_files"],
)