go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/quota/internal/luatest/testdata/policy_test.lua (about) 1 -- Copyright 2022 The LUCI Authors 2 -- 3 -- Licensed under the Apache License, Version 2.0 (the "License"); 4 -- you may not use this file except in compliance with the License. 5 -- You may obtain a copy of the License at 6 -- 7 -- http://www.apache.org/licenses/LICENSE-2.0 8 -- 9 -- Unless required by applicable law or agreed to in writing, software 10 -- distributed under the License is distributed on an "AS IS" BASIS, 11 -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 -- See the License for the specific language governing permissions and 13 -- limitations under the License. 14 15 require 'test_fixtures' 16 17 Account = G.Account 18 Policy = G.Policy 19 Utils = G.Utils 20 21 function testPolicyGetMissing() 22 local ref = PB.new("go.chromium.org.luci.server.quota.quotapb.PolicyRef", { 23 config = "policy_config", 24 key = "policy_name", 25 }) 26 lu.assertNil(Policy.get(ref)) 27 end 28 29 function testPolicyGet() 30 local ref = PB.new("go.chromium.org.luci.server.quota.quotapb.PolicyRef", { 31 config = "policy_config", 32 key = "policy_name", 33 }) 34 local policy = PB.new("go.chromium.org.luci.server.quota.quotapb.Policy", { 35 default = 20, 36 limit = 100, 37 refill = PB.new("go.chromium.org.luci.server.quota.quotapb.Policy.Refill", { 38 units = 1, 39 interval = 100, 40 }), 41 lifetime = PB.new("google.protobuf.Duration", { 42 seconds = 3600, 43 }), 44 }) 45 redis.call("HSET", ref.config, ref.key, PB.marshal(policy)) 46 47 local expectedPolicy = "\132\001\020\002d\003\146\001d\005\145\205\014\016" 48 lu.assertEquals(redis.DATA[ref.config][ref.key], expectedPolicy) 49 50 local policy = Policy.get(ref) 51 lu.assertEquals(policy.pb.default, 20) 52 lu.assertEquals(policy.pb.limit, 100) 53 lu.assertEquals(policy.pb.refill.units, 1) 54 lu.assertEquals(policy.pb.refill.interval, 100) 55 lu.assertEquals(policy.pb.lifetime.seconds, 3600) 56 end 57 58 return lu.LuaUnit.run("-v")