get.porter.sh/porter@v1.3.0/pkg/cache/helpers.go (about) 1 package cache 2 3 import ( 4 "get.porter.sh/porter/pkg/cnab" 5 ) 6 7 var _ BundleCache = &TestCache{} 8 9 // MockCache helps you test error scenarios, you don't need it for unit testing positive scenarios. 10 type TestCache struct { 11 cache BundleCache 12 FindBundleMock func(ref cnab.OCIReference) (CachedBundle, bool, error) 13 StoreBundleMock func(bundleReference cnab.BundleReference) (CachedBundle, error) 14 } 15 16 func NewTestCache(cache BundleCache) *TestCache { 17 return &TestCache{ 18 cache: cache, 19 } 20 } 21 22 func (c *TestCache) FindBundle(ref cnab.OCIReference) (CachedBundle, bool, error) { 23 if c.FindBundleMock != nil { 24 return c.FindBundleMock(ref) 25 } 26 return c.cache.FindBundle(ref) 27 } 28 29 func (c *TestCache) StoreBundle(bundleRef cnab.BundleReference) (CachedBundle, error) { 30 if c.StoreBundleMock != nil { 31 return c.StoreBundleMock(bundleRef) 32 } 33 return c.cache.StoreBundle(bundleRef) 34 } 35 36 func (c *TestCache) GetCacheDir() (string, error) { 37 return c.cache.GetCacheDir() 38 }