aboutsummaryrefslogtreecommitdiffstats
path: root/repository/mock_repo.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-23 18:02:54 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-26 19:14:22 +0200
commit88ad7e606f1cbf9e47b968a208e3510f7f9a81c5 (patch)
tree00e847500b34c6f9a721c71474993d1c08ae8fb1 /repository/mock_repo.go
parent2dd0dbb1344ae9293aae05346f977b5d5907934b (diff)
downloadgit-bug-88ad7e606f1cbf9e47b968a208e3510f7f9a81c5.tar.gz
repository: remove tie to Bug, improved and reusable testing
- allow the creation of arbitrary Lamport clocks, freeing the way to new entities and removing Bug specific (upper layer) code. - generalize the memory-only and persisted Lamport clocks behind a common interface - rework the tests to provide reusable testing code for a Repo, a Clock, a Config, opening a path to add a new Repo implementation more easily - test previously untested components with those new tests Note: one problem found during this endeavor is that `identity.Version` also need to store one time + Lamport time for each other Entity (Bug, config, PR ...). This could possibly done without breaking change but it would be much easier to wait for https://github.com/MichaelMure/git-bug-migration to happen.
Diffstat (limited to 'repository/mock_repo.go')
-rw-r--r--repository/mock_repo.go45
1 files changed, 12 insertions, 33 deletions
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 89d0f395..04d9355e 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -9,6 +9,7 @@ import (
)
var _ ClockedRepo = &mockRepoForTest{}
+var _ TestedRepo = &mockRepoForTest{}
// mockRepoForTest defines an instance of Repo that can be used for testing.
type mockRepoForTest struct {
@@ -18,8 +19,7 @@ type mockRepoForTest struct {
trees map[git.Hash]string
commits map[git.Hash]commit
refs map[string]git.Hash
- createClock lamport.Clock
- editClock lamport.Clock
+ clocks map[string]lamport.Clock
}
type commit struct {
@@ -35,8 +35,7 @@ func NewMockRepoForTest() *mockRepoForTest {
trees: make(map[git.Hash]string),
commits: make(map[git.Hash]commit),
refs: make(map[string]git.Hash),
- createClock: lamport.NewClock(),
- editClock: lamport.NewClock(),
+ clocks: make(map[string]lamport.Clock),
}
}
@@ -213,36 +212,16 @@ func (r *mockRepoForTest) GetTreeHash(commit git.Hash) (git.Hash, error) {
panic("implement me")
}
-func (r *mockRepoForTest) LoadClocks() error {
- return nil
-}
-
-func (r *mockRepoForTest) WriteClocks() error {
- return nil
-}
-
-func (r *mockRepoForTest) CreateTime() lamport.Time {
- return r.createClock.Time()
-}
-
-func (r *mockRepoForTest) CreateTimeIncrement() (lamport.Time, error) {
- return r.createClock.Increment(), nil
-}
-
-func (r *mockRepoForTest) EditTime() lamport.Time {
- return r.editClock.Time()
-}
-
-func (r *mockRepoForTest) EditTimeIncrement() (lamport.Time, error) {
- return r.editClock.Increment(), nil
-}
+func (r *mockRepoForTest) GetOrCreateClock(name string) (lamport.Clock, error) {
+ if c, ok := r.clocks[name]; ok {
+ return c, nil
+ }
-func (r *mockRepoForTest) WitnessCreate(time lamport.Time) error {
- r.createClock.Witness(time)
- return nil
+ c := lamport.NewMemClock()
+ r.clocks[name] = c
+ return c, nil
}
-func (r *mockRepoForTest) WitnessEdit(time lamport.Time) error {
- r.editClock.Witness(time)
- return nil
+func (r *mockRepoForTest) AddRemote(name string, url string) error {
+ panic("implement me")
}