go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/lucicfg/testdata/swarming/cache.star (about) 1 load("@stdlib//internal/luci/lib/swarming.star", "swarming") 2 3 def test_cache_ctor(): 4 def eq(c, path, name, wait): 5 assert.eq(c.path, path) 6 assert.eq(c.name, name) 7 assert.eq(c.wait_for_warm_cache, wait) 8 9 eq(swarming.cache("path"), "path", "path", None) 10 eq( 11 swarming.cache( 12 "path", 13 name = "name", 14 wait_for_warm_cache = 5 * time.minute, 15 ), 16 "path", 17 "name", 18 5 * time.minute, 19 ) 20 21 assert.fails(lambda: swarming.cache("", name = "n"), "must not be empty") 22 assert.fails(lambda: swarming.cache("p", name = ""), "must not be empty") 23 24 # Duration validation. 25 assert.fails( 26 lambda: swarming.cache("p", name = "n", wait_for_warm_cache = 300), 27 "got int, want duration", 28 ) 29 assert.fails( 30 lambda: swarming.cache("p", name = "n", wait_for_warm_cache = time.zero), 31 "0s should be >= 1m0s", 32 ) 33 assert.fails( 34 lambda: swarming.cache("p", name = "n", wait_for_warm_cache = 61 * time.second), 35 "losing precision when truncating 1m1s to 1m0s units", 36 ) 37 38 def test_validate_caches(): 39 call = lambda c: swarming.validate_caches("caches", c) 40 41 c1 = swarming.cache("c1") 42 c2 = swarming.cache("c2", name = "n") 43 c3 = swarming.cache("c3", name = "n") 44 45 assert.eq(call([c1, c2]), [c1, c2]) 46 assert.eq(call(None), []) 47 48 assert.fails(lambda: call([c1, c1]), "use same path") 49 assert.fails(lambda: call([c2, c3]), "use same name") 50 51 test_cache_ctor() 52 test_validate_caches()