go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/lucicfg/testdata/cq/user_limit.star (about) 1 luci.project(name = "foo") 2 3 # name character checks 4 def fail(name, msg): 5 assert.fails(lambda: cq.user_limit(name = name), msg) 6 7 cq.user_limit(name = "this_is_a_good_name", users = ["foo@example.com"]) 8 cq.user_limit(name = "foo-abc@example.com", groups = ["engineers"]) 9 fail("", "must not be empty") 10 fail("@a", "should match \"\\^\\[") 11 fail("Abc Def", "should match \"\\^\\[") 12 13 # name uniqueness checks 14 def cq_group(name, user_limits, user_limits_default): 15 luci.cq_group( 16 name = name, 17 watch = [cq.refset("https://example.googlesource.com/proj/repo")], 18 acls = [acl.entry(acl.CQ_COMMITTER, groups = ["committers"])], 19 user_limits = user_limits, 20 user_limit_default = user_limits_default, 21 ) 22 23 p1 = cq.user_limit(name = "user_limits", users = ["someone@example.com"]) 24 p2 = cq.user_limit(name = "group_limits", groups = ["abc"]) 25 p3 = cq.user_limit(name = "no_principal_limits") 26 27 # cq.user_limit(s) can be passed to multiple cq_group(s), 28 # 29 # However, it doesn't mean that runs and tryjobs of all the cq_group(s) will be 30 # tracked together under the same limit. runs and tryjobs are tracked separately 31 # for each cq_group. 32 cq_group("cq 1", [p1, p2], p3) 33 cq_group("cq 2", [p1, p2], None) 34 35 # However, duplicate limit names within a cq_group is not allowed. 36 assert.fails( 37 lambda: cq_group("cq 3", [p1, p1], None), 38 "user_limits\\[1\\]: duplicate limit name 'user_limits'", 39 ) 40 assert.fails( 41 lambda: cq_group("cq 3", [p1, p2], cq.user_limit(name = p1.name)), 42 "user_limit_default: limit name 'user_limits' is already used in user_limits", 43 ) 44 45 # All the policies in `user_limits` must have a user or group. 46 assert.fails( 47 lambda: cq_group("cq 3", [p3], None), 48 "user_limits\\[0\\]: must specify at least one user or group", 49 ) 50 51 # The limits in `user_limit_default` must not have a user and group. 52 assert.fails( 53 lambda: cq_group("cq 3", [p1], p2), 54 "user_limit_default: must not specify user or group", 55 )