mirrored from https://chromium.googlesource.com/infra/luci/recipes-py
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathluci_context.py
61 lines (52 loc) · 1.95 KB
/
luci_context.py
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
# Copyright 2020 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
from PB.go.chromium.org.luci.lucictx import sections as sections_pb2
DEPS = [
'assertions',
'context',
'path',
'step',
]
def RunSteps(api):
def assert_msg_equal(expected, actual):
api.assertions.assertEqual(
expected.SerializeToString(deterministic=True),
actual.SerializeToString(deterministic=True)
)
api.step('start', ['echo', 'hello'])
assert_msg_equal(sections_pb2.LUCIExe(cache_dir='/path/to/cache'),
api.context.luciexe)
api.assertions.assertEqual(
'invocations/inv', api.context.resultdb_invocation_name)
api.assertions.assertEqual('proj:realm', api.context.realm)
with api.context(env={'UNRELATED_CHANGE': 1}):
api.assertions.assertEqual('proj:realm', api.context.realm)
with api.context(realm='proj:another'):
api.assertions.assertEqual('proj:another', api.context.realm)
with api.context(realm=''):
api.assertions.assertEqual(None, api.context.realm)
with api.context(
luciexe=sections_pb2.LUCIExe(cache_dir='/path/to/new_cache')):
api.step('new luciexe', ['echo', 'new', 'luciexe'])
assert_msg_equal(sections_pb2.LUCIExe(cache_dir='/path/to/new_cache'),
api.context.luciexe)
api.step('end', ['echo', 'bye'])
assert_msg_equal(sections_pb2.LUCIExe(cache_dir='/path/to/cache'),
api.context.luciexe)
def GenTests(api):
yield (
api.test('basic')
+ api.context.luci_context(
luciexe=sections_pb2.LUCIExe(cache_dir='/path/to/cache'),
realm=sections_pb2.Realm(name='proj:realm'),
resultdb=sections_pb2.ResultDB(
current_invocation=sections_pb2.ResultDBInvocation(
name='invocations/inv',
update_token='token',
),
hostname='rdbhost',
)
)
)
assert api.context.realm is None