gosimplenpm/internal/storage/mockfs.go

57 lines
2.0 KiB
Go
Raw Normal View History

2023-12-25 08:56:48 +00:00
package storage
import (
"gosimplenpm/internal/serviceidos"
"github.com/sirupsen/logrus"
)
type MockFs struct {
calls map[string]int
GetIndexJsonFromStoreFunc func(packageName string, registryPath string, lg *logrus.Logger) (string, bool, error)
GetTarFromStoreFunc func(packageName string, tarFileName string, registryPath string, lg *logrus.Logger) (string, error)
ReadIndexJsonFunc func(fPath string, res *serviceidos.IndexJson, lg *logrus.Logger) error
WriteIndexJsonFunc func(fPath string, res *serviceidos.IndexJson, lg *logrus.Logger) error
WritePackageToStoreFunc func(fPath string, data string, lg *logrus.Logger) error
}
func (m *MockFs) GetIndexJsonFromStore(packageName string, registryPath string, lg *logrus.Logger) (string, bool, error) {
if len(m.calls) == 0 {
m.calls = make(map[string]int)
}
m.calls["GetIndexJsonFromStore"] += 1
return m.GetIndexJsonFromStoreFunc(packageName, registryPath, lg)
}
func (m *MockFs) GetTarFromStore(packageName string, tarFileName string, registryPath string, lg *logrus.Logger) (string, error) {
if len(m.calls) == 0 {
m.calls = make(map[string]int)
}
m.calls["GetTarFromStore"] += 1
return m.GetTarFromStoreFunc(packageName, tarFileName, registryPath, lg)
}
func (m *MockFs) ReadIndexJson(fPath string, res *serviceidos.IndexJson, lg *logrus.Logger) error {
if len(m.calls) == 0 {
m.calls = make(map[string]int)
}
m.calls["ReadIndexJson"] += 1
return m.ReadIndexJsonFunc(fPath, res, lg)
}
func (m *MockFs) WriteIndexJson(fPath string, res *serviceidos.IndexJson, lg *logrus.Logger) error {
if len(m.calls) == 0 {
m.calls = make(map[string]int)
}
m.calls["WriteIndexJson"] += 1
return m.WriteIndexJsonFunc(fPath, res, lg)
}
func (m *MockFs) WritePackageToStore(fPath string, data string, lg *logrus.Logger) error {
if len(m.calls) == 0 {
m.calls = make(map[string]int)
}
m.calls["WritePackageToStore"] += 1
return m.WritePackageToStoreFunc(fPath, data, lg)
}