forked from wix/greyhound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.bzl
159 lines (137 loc) · 4.59 KB
/
tests.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_specs2_junit_test","scala_library")
load("@io_bazel_rules_scala//specs2:specs2_junit.bzl", "specs2_junit_dependencies")
target_test_classes = "target/test-classes"
_unit_prefixes = ["Test"]
_unit_suffixes = _unit_prefixes
_unit_tags = ["UT"]
_it_prefixes = ["IT", "E2E"]
_it_suffixes = _it_prefixes
_it_tags = ["IT", "E2E"]
_mixed_prefixes = _unit_prefixes + _it_prefixes
_mixed_suffixes = _mixed_prefixes
_mixed_tags = _unit_tags + _it_tags
def specs2_unit_test(extra_runtime_dirs = [target_test_classes],
extra_runtime_entries = [target_test_classes],
**kwargs):
size = kwargs.pop("size", "small")
timeout = kwargs.pop("timeout", None)
_add_test_target(
_unit_prefixes,
_unit_suffixes,
_unit_tags,
False,
size,
timeout,
extra_runtime_dirs,
extra_runtime_entries,
**kwargs
)
def specs2_ite2e_test(block_network = True,
extra_runtime_dirs = [target_test_classes],
extra_runtime_entries = [target_test_classes],
**kwargs):
timeout = kwargs.pop("timeout", _default_moderate_timeout_or_implied_from_size_attr(kwargs))
size = kwargs.pop("size", "large")
_add_test_target(
_it_prefixes,
_it_suffixes,
_it_tags,
block_network,
size,
timeout,
extra_runtime_dirs,
extra_runtime_entries,
**kwargs
)
def specs2_mixed_test(block_network = True,
extra_runtime_dirs = [target_test_classes],
extra_runtime_entries = [target_test_classes],
**kwargs):
timeout = kwargs.pop("timeout", _default_moderate_timeout_or_implied_from_size_attr(kwargs))
size = kwargs.pop("size", "large")
_add_test_target(
_mixed_prefixes,
_mixed_suffixes,
_mixed_tags,
block_network,
size,
timeout,
extra_runtime_dirs,
extra_runtime_entries,
**kwargs
)
def _add_test_target(prefixes,
suffixes,
test_tags,
block_network,
size,
timeout,
extra_runtime_dirs,
extra_runtime_entries,
**kwargs):
#extract attribute(s) common to both test and scala_library
name = kwargs.pop("name")
user_test_tags = kwargs.pop("tags", test_tags)
#Bazel idiomatic wise `data` is needed in both.
#(scala_library for other tests that might need the data in the runfiles and the test needs it so that it can do $location expansion)
data = kwargs.pop("data", [])
#extract attributes which are only for the test runtime
end_prefixes = kwargs.pop("prefixes", prefixes)
end_suffixes = kwargs.pop("suffixes", suffixes)
jvm_flags = kwargs.pop("jvm_flags", [])
flaky = kwargs.pop("flaky", None)
shard_count = kwargs.pop("shard_count", None)
args = kwargs.pop("args", None)
local = kwargs.pop("local", None)
deps = kwargs.pop("deps",[])
jvm_flags.extend([
"-Dextra.dirs=" + ":".join(extra_runtime_dirs),
])
runtime_entries = []
if extra_runtime_entries != None:
runtime_entries.extend(extra_runtime_entries)
jvm_flags.append("-Xbootclasspath/a:" + ":".join(runtime_entries))
#mitigate issue where someone explicitly adds testonly in their kwargs and so we get it twice
testonly = kwargs.pop("testonly", 1)
junit_specs2_deps = specs2_junit_dependencies() + [
"//external:io_bazel_rules_scala/dependency/junit/junit",
"//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core",
]
scala_library(
name = name,
tags = user_test_tags,
data = data,
testonly = testonly,
deps = junit_specs2_deps + deps,
**kwargs
)
scala_specs2_junit_test(
name = name + "_test_runner",
prefixes = end_prefixes,
suffixes = end_suffixes,
deps = deps,
runtime_deps = [":" + name],
tests_from = [":" + name],
jvm_flags = jvm_flags,
size = size,
timeout = timeout,
flaky = flaky,
shard_count = shard_count,
args = args,
local = local,
data = data,
tags = user_test_tags,
exec_compatible_with = _constraint_by_size(size)
)
def _constraint_by_size(size):
large_machine_constraint = None
if size in ["large", "enormous"]:
return large_machine_constraint
else:
return None
def _default_moderate_timeout_or_implied_from_size_attr(kwargs):
if 'size' in kwargs:
#let bazel imply timeout from the size
default_timeout = None
else:
default_timeout = "moderate"