github.com/MetalBlockchain/metalgo@v1.11.9/cache/metercacher/cache_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package metercacher 5 6 import ( 7 "testing" 8 9 "github.com/prometheus/client_golang/prometheus" 10 "github.com/stretchr/testify/require" 11 12 "github.com/MetalBlockchain/metalgo/cache" 13 "github.com/MetalBlockchain/metalgo/ids" 14 ) 15 16 func TestInterface(t *testing.T) { 17 type scenario struct { 18 description string 19 setup func(size int) cache.Cacher[ids.ID, int64] 20 } 21 22 scenarios := []scenario{ 23 { 24 description: "cache LRU", 25 setup: func(size int) cache.Cacher[ids.ID, int64] { 26 return &cache.LRU[ids.ID, int64]{Size: size} 27 }, 28 }, 29 { 30 description: "sized cache LRU", 31 setup: func(size int) cache.Cacher[ids.ID, int64] { 32 return cache.NewSizedLRU[ids.ID, int64](size*cache.TestIntSize, cache.TestIntSizeFunc) 33 }, 34 }, 35 } 36 37 for _, scenario := range scenarios { 38 for _, test := range cache.CacherTests { 39 baseCache := scenario.setup(test.Size) 40 c, err := New("", prometheus.NewRegistry(), baseCache) 41 require.NoError(t, err) 42 test.Func(t, c) 43 } 44 } 45 }