-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtesting.bzl
84 lines (79 loc) · 2.07 KB
/
testing.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
def _docker_run_impl(ctx):
out = ctx.actions.declare_file(ctx.label.name)
args = ctx.actions.args()
args.add(out)
args.add(ctx.attr.cmd)
args.add(ctx.file.tar)
args.add(ctx.attr.image)
ctx.actions.run(
outputs = [out],
inputs = [ctx.file.tar],
executable = ctx.file._script,
arguments = [args],
)
return DefaultInfo(files = depset([out]))
docker_run = rule(
attrs = {
"tar": attr.label(
mandatory = True,
allow_single_file = True,
),
"image": attr.string(
mandatory = True,
),
"cmd": attr.string(
mandatory = True,
),
"_script": attr.label(
default = "//:docker_run.sh",
allow_single_file = True,
),
},
implementation = _docker_run_impl,
)
def _diff_test_impl(ctx):
ctx.actions.expand_template(
template = ctx.file._template,
output = ctx.outputs.file,
substitutions = {
"{RESULT}": ctx.file.result.short_path,
"{GOLDEN}": ctx.attr.golden,
},
)
return DefaultInfo(runfiles = ctx.runfiles(files = ctx.files.result))
diff_test_expand = rule(
attrs = {
"result": attr.label(
mandatory = True,
allow_single_file = True,
),
"golden": attr.string(
mandatory = True,
),
"_template": attr.label(
default = "//:diff_test.sh",
allow_single_file = True,
),
},
outputs = {"file": "%{name}.sh"},
implementation = _diff_test_impl,
)
def docker_diff(name,cmd, golden, tar=":rpms", image="", base=""):
docker_run(
name = name + "_run",
testonly = True,
tar = tar,
image = image,
cmd = cmd,
)
diff_test_expand(
name = name + "_diff",
result = ":%s_run" % name,
golden = golden,
testonly = True,
)
native.sh_test(
name = name + "_diff_test",
srcs = [":{}_diff".format(name)],
data = [tar, ":{}_run".format(name)],
)