aboutsummaryrefslogtreecommitdiffstats
path: root/repository/mock_repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'repository/mock_repo.go')
-rw-r--r--repository/mock_repo.go84
1 files changed, 79 insertions, 5 deletions
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 628939aa..8a1724ef 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -4,8 +4,12 @@ import (
"crypto/sha1"
"fmt"
"strings"
+ "sync"
"github.com/99designs/keyring"
+ "github.com/blevesearch/bleve"
+ "github.com/go-git/go-billy/v5"
+ "github.com/go-git/go-billy/v5/memfs"
"github.com/MichaelMure/git-bug/util/lamport"
)
@@ -18,15 +22,21 @@ type mockRepoForTest struct {
*mockRepoConfig
*mockRepoKeyring
*mockRepoCommon
+ *mockRepoStorage
+ *mockRepoBleve
*mockRepoData
*mockRepoClock
}
+func (m *mockRepoForTest) Close() error { return nil }
+
func NewMockRepoForTest() *mockRepoForTest {
return &mockRepoForTest{
mockRepoConfig: NewMockRepoConfig(),
mockRepoKeyring: NewMockRepoKeyring(),
mockRepoCommon: NewMockRepoCommon(),
+ mockRepoStorage: NewMockRepoStorage(),
+ mockRepoBleve: newMockRepoBleve(),
mockRepoData: NewMockRepoData(),
mockRepoClock: NewMockRepoClock(),
}
@@ -86,11 +96,6 @@ func NewMockRepoCommon() *mockRepoCommon {
return &mockRepoCommon{}
}
-// GetPath returns the path to the repo.
-func (r *mockRepoCommon) GetPath() string {
- return "~/mockRepo/"
-}
-
func (r *mockRepoCommon) GetUserName() (string, error) {
return "René Descartes", nil
}
@@ -112,6 +117,62 @@ func (r *mockRepoCommon) GetRemotes() (map[string]string, error) {
}, nil
}
+var _ RepoStorage = &mockRepoStorage{}
+
+type mockRepoStorage struct {
+ localFs billy.Filesystem
+}
+
+func NewMockRepoStorage() *mockRepoStorage {
+ return &mockRepoStorage{localFs: memfs.New()}
+}
+
+func (m *mockRepoStorage) LocalStorage() billy.Filesystem {
+ return m.localFs
+}
+
+var _ RepoBleve = &mockRepoBleve{}
+
+type mockRepoBleve struct {
+ indexesMutex sync.Mutex
+ indexes map[string]bleve.Index
+}
+
+func newMockRepoBleve() *mockRepoBleve {
+ return &mockRepoBleve{
+ indexes: make(map[string]bleve.Index),
+ }
+}
+
+func (m *mockRepoBleve) GetBleveIndex(name string) (bleve.Index, error) {
+ m.indexesMutex.Lock()
+ defer m.indexesMutex.Unlock()
+
+ if index, ok := m.indexes[name]; ok {
+ return index, nil
+ }
+
+ mapping := bleve.NewIndexMapping()
+ mapping.DefaultAnalyzer = "en"
+
+ index, err := bleve.NewMemOnly(mapping)
+ if err != nil {
+ return nil, err
+ }
+
+ m.indexes[name] = index
+
+ return index, nil
+}
+
+func (m *mockRepoBleve) ClearBleveIndex(name string) error {
+ m.indexesMutex.Lock()
+ defer m.indexesMutex.Unlock()
+
+ delete(m.indexes, name)
+ return nil
+}
+
var _ RepoData = &mockRepoData{}
type commit struct {
@@ -314,7 +375,17 @@ func (r *mockRepoData) AddRemote(name string, url string) error {
panic("implement me")
}
+func (m mockRepoForTest) GetLocalRemote() string {
+ panic("implement me")
+}
+
+func (m mockRepoForTest) EraseFromDisk() error {
+ // nothing to do
+ return nil
+}
+
type mockRepoClock struct {
+ mu sync.Mutex
clocks map[string]lamport.Clock
}
@@ -325,6 +396,9 @@ func NewMockRepoClock() *mockRepoClock {
}
func (r *mockRepoClock) GetOrCreateClock(name string) (lamport.Clock, error) {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+
if c, ok := r.clocks[name]; ok {
return c, nil
}