github.com/argoproj/argo-cd/v2@v2.10.5/util/cache/mocks/cacheclient.go (about) 1 package mocks 2 3 import ( 4 "context" 5 "time" 6 7 cache "github.com/argoproj/argo-cd/v2/util/cache" 8 "github.com/stretchr/testify/mock" 9 ) 10 11 type MockCacheClient struct { 12 mock.Mock 13 BaseCache cache.CacheClient 14 ReadDelay time.Duration 15 WriteDelay time.Duration 16 } 17 18 func (c *MockCacheClient) Set(item *cache.Item) error { 19 args := c.Called(item) 20 if len(args) > 0 && args.Get(0) != nil { 21 return args.Get(0).(error) 22 } 23 if c.WriteDelay > 0 { 24 time.Sleep(c.WriteDelay) 25 } 26 return c.BaseCache.Set(item) 27 } 28 29 func (c *MockCacheClient) Get(key string, obj interface{}) error { 30 args := c.Called(key, obj) 31 if len(args) > 0 && args.Get(0) != nil { 32 return args.Get(0).(error) 33 } 34 if c.ReadDelay > 0 { 35 time.Sleep(c.ReadDelay) 36 } 37 return c.BaseCache.Get(key, obj) 38 } 39 40 func (c *MockCacheClient) Delete(key string) error { 41 args := c.Called(key) 42 if len(args) > 0 && args.Get(0) != nil { 43 return args.Get(0).(error) 44 } 45 if c.WriteDelay > 0 { 46 time.Sleep(c.WriteDelay) 47 } 48 return c.BaseCache.Delete(key) 49 } 50 51 func (c *MockCacheClient) OnUpdated(ctx context.Context, key string, callback func() error) error { 52 args := c.Called(ctx, key, callback) 53 if len(args) > 0 && args.Get(0) != nil { 54 return args.Get(0).(error) 55 } 56 return c.BaseCache.OnUpdated(ctx, key, callback) 57 } 58 59 func (c *MockCacheClient) NotifyUpdated(key string) error { 60 args := c.Called(key) 61 if len(args) > 0 && args.Get(0) != nil { 62 return args.Get(0).(error) 63 } 64 return c.BaseCache.NotifyUpdated(key) 65 }