chore: add mocked cache

This commit is contained in:
Jan De Dobbeleer 2021-09-23 22:57:38 +02:00 committed by Jan De Dobbeleer
parent 7738cad7cb
commit e846f2b683
3 changed files with 47 additions and 6 deletions

View file

@ -102,10 +102,8 @@ func (c *commandCache) get(command string) (string, bool) {
if !found {
return "", false
}
if command, ok := cmd.(string); ok {
return command, true
}
return "", false
command, ok := cmd.(string)
return command, ok
}
type tracer struct {

View file

@ -40,8 +40,7 @@ func (fc *fileCache) init(home string) {
}
func (fc *fileCache) close() {
fc.set("hello", "world", 200)
if dump, err := json.Marshal(fc.cache.list()); err == nil {
if dump, err := json.MarshalIndent(fc.cache.list(), "", " "); err == nil {
_ = ioutil.WriteFile(fc.home+cachePath, dump, 0644)
}
}

View file

@ -0,0 +1,44 @@
package main
import mock "github.com/stretchr/testify/mock"
// MockedCache is an autogenerated mock type for the cache type
type MockedCache struct {
mock.Mock
}
// close provides a mock function with given fields:
func (_m *MockedCache) close() {
_m.Called()
}
// get provides a mock function with given fields: key
func (_m *MockedCache) get(key string) (string, bool) {
ret := _m.Called(key)
var r0 string
if rf, ok := ret.Get(0).(func(string) string); ok {
r0 = rf(key)
} else {
r0 = ret.Get(0).(string)
}
var r1 bool
if rf, ok := ret.Get(1).(func(string) bool); ok {
r1 = rf(key)
} else {
r1 = ret.Get(1).(bool)
}
return r0, r1
}
// init provides a mock function with given fields: home
func (_m *MockedCache) init(home string) {
_m.Called(home)
}
// set provides a mock function with given fields: key, value, ttl
func (_m *MockedCache) set(key, value string, ttl int64) {
_m.Called(key, value, ttl)
}