github.com/argoproj/argo-cd/v3@v3.2.1/util/cache/mocks/cacheclient.go (about)

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