|
15 | 15 |
|
16 | 16 | load("@rules_pkg//:pkg.bzl", "pkg_tar") |
17 | 17 | load("@repo_absolute_path//:build_root.bzl", "BUILD_WORKSPACE_DIRECTORY") |
| 18 | +load("@io_bazel_rules_go//go:def.bzl", "go_test") |
18 | 19 | load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball") |
19 | 20 |
|
20 | 21 | common_tags = [ |
@@ -48,6 +49,85 @@ def docker_compose_test( |
48 | 49 | **kwargs, |
49 | 50 | ) |
50 | 51 |
|
| 52 | +def go_docker_compose_test( |
| 53 | + name, |
| 54 | + docker_compose_file, |
| 55 | + docker_compose_test_container, |
| 56 | + pre_compose_up_script = "", |
| 57 | + extra_docker_compose_up_args = "", |
| 58 | + local_image_targets = "", |
| 59 | + test_image_base = None, |
| 60 | + test_srcs = [], |
| 61 | + test_deps = [], |
| 62 | + data = [], |
| 63 | + tags = [], |
| 64 | + size = "large", |
| 65 | + **kwargs, |
| 66 | +): |
| 67 | + tags = common_tags + tags |
| 68 | + data = data + [ docker_compose_file ] |
| 69 | + if len(pre_compose_up_script): |
| 70 | + data = data + [ pre_compose_up_script ] |
| 71 | + if test_image_base == None: |
| 72 | + fail("if you are defining test_srcs, you need to provide a test_image_base") |
| 73 | + |
| 74 | + go_test( |
| 75 | + name = name + ".go_test", |
| 76 | + srcs = test_srcs, |
| 77 | + deps = test_deps, |
| 78 | + tags = tags, |
| 79 | + testonly = True, |
| 80 | + ) |
| 81 | + |
| 82 | + compiled_tests_target = ":" + name + ".go_test" |
| 83 | + |
| 84 | + pkg_tar( |
| 85 | + name = name + ".compiled_go_test_target", |
| 86 | + srcs = [compiled_tests_target], |
| 87 | + package_dir = "/tests", |
| 88 | + tags = tags, |
| 89 | + testonly = True, |
| 90 | + ) |
| 91 | + |
| 92 | + oci_image( |
| 93 | + name = name + ".oci_image", |
| 94 | + base = test_image_base, |
| 95 | + tars = [ |
| 96 | + name + ".compiled_go_test_target", |
| 97 | + ], |
| 98 | + tags = tags, |
| 99 | + testonly = True, |
| 100 | + ) |
| 101 | + |
| 102 | + oci_tarball( |
| 103 | + name = docker_compose_test_container, |
| 104 | + image = name + ".oci_image", |
| 105 | + repo_tags = ["%s:%s" % (native.package_name(), docker_compose_test_container)], |
| 106 | + tags = tags, |
| 107 | + testonly = True, |
| 108 | + ) |
| 109 | + |
| 110 | + # this builds & installs the test image. |
| 111 | + native.sh_binary( |
| 112 | + name = name + ".integration_test_image_fixture", |
| 113 | + srcs = [docker_compose_test_container], |
| 114 | + testonly = True, |
| 115 | + ) |
| 116 | + |
| 117 | + data.append(name + ".integration_test_image_fixture") |
| 118 | + if len(local_image_targets): |
| 119 | + local_image_targets += "," |
| 120 | + local_image_targets += "%s:%s" % (native.package_name(), docker_compose_test_container) |
| 121 | + native.sh_test( |
| 122 | + name = name, |
| 123 | + srcs = ["@rules_docker_compose_test//docker_compose_test:docker_compose_test.sh"], |
| 124 | + env = _get_env(docker_compose_file, local_image_targets, docker_compose_test_container, pre_compose_up_script, extra_docker_compose_up_args), |
| 125 | + size = size, |
| 126 | + tags = tags, |
| 127 | + data = data, |
| 128 | + **kwargs, |
| 129 | + ) |
| 130 | + |
51 | 131 |
|
52 | 132 | def junit_docker_compose_test( |
53 | 133 | name, |
|
0 commit comments