diff options
Diffstat (limited to 'repository/mock_repo.go')
-rw-r--r-- | repository/mock_repo.go | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/repository/mock_repo.go b/repository/mock_repo.go index 50907876..23d3ef7d 100644 --- a/repository/mock_repo.go +++ b/repository/mock_repo.go @@ -4,32 +4,33 @@ import ( "crypto/sha1" "fmt" - "github.com/MichaelMure/git-bug/util" + "github.com/MichaelMure/git-bug/util/git" + "github.com/MichaelMure/git-bug/util/lamport" ) // mockRepoForTest defines an instance of Repo that can be used for testing. type mockRepoForTest struct { - blobs map[util.Hash][]byte - trees map[util.Hash]string - commits map[util.Hash]commit - refs map[string]util.Hash - createClock util.LamportClock - editClock util.LamportClock + blobs map[git.Hash][]byte + trees map[git.Hash]string + commits map[git.Hash]commit + refs map[string]git.Hash + createClock lamport.Clock + editClock lamport.Clock } type commit struct { - treeHash util.Hash - parent util.Hash + treeHash git.Hash + parent git.Hash } func NewMockRepoForTest() Repo { return &mockRepoForTest{ - blobs: make(map[util.Hash][]byte), - trees: make(map[util.Hash]string), - commits: make(map[util.Hash]commit), - refs: make(map[string]util.Hash), - createClock: util.NewLamportClock(), - editClock: util.NewLamportClock(), + blobs: make(map[git.Hash][]byte), + trees: make(map[git.Hash]string), + commits: make(map[git.Hash]commit), + refs: make(map[string]git.Hash), + createClock: lamport.NewClock(), + editClock: lamport.NewClock(), } } @@ -61,14 +62,14 @@ func (r *mockRepoForTest) FetchRefs(remote string, refSpec string) (string, erro return "", nil } -func (r *mockRepoForTest) StoreData(data []byte) (util.Hash, error) { +func (r *mockRepoForTest) StoreData(data []byte) (git.Hash, error) { rawHash := sha1.Sum(data) - hash := util.Hash(fmt.Sprintf("%x", rawHash)) + hash := git.Hash(fmt.Sprintf("%x", rawHash)) r.blobs[hash] = data return hash, nil } -func (r *mockRepoForTest) ReadData(hash util.Hash) ([]byte, error) { +func (r *mockRepoForTest) ReadData(hash git.Hash) ([]byte, error) { data, ok := r.blobs[hash] if !ok { @@ -78,27 +79,27 @@ func (r *mockRepoForTest) ReadData(hash util.Hash) ([]byte, error) { return data, nil } -func (r *mockRepoForTest) StoreTree(entries []TreeEntry) (util.Hash, error) { +func (r *mockRepoForTest) StoreTree(entries []TreeEntry) (git.Hash, error) { buffer := prepareTreeEntries(entries) rawHash := sha1.Sum(buffer.Bytes()) - hash := util.Hash(fmt.Sprintf("%x", rawHash)) + hash := git.Hash(fmt.Sprintf("%x", rawHash)) r.trees[hash] = buffer.String() return hash, nil } -func (r *mockRepoForTest) StoreCommit(treeHash util.Hash) (util.Hash, error) { +func (r *mockRepoForTest) StoreCommit(treeHash git.Hash) (git.Hash, error) { rawHash := sha1.Sum([]byte(treeHash)) - hash := util.Hash(fmt.Sprintf("%x", rawHash)) + hash := git.Hash(fmt.Sprintf("%x", rawHash)) r.commits[hash] = commit{ treeHash: treeHash, } return hash, nil } -func (r *mockRepoForTest) StoreCommitWithParent(treeHash util.Hash, parent util.Hash) (util.Hash, error) { +func (r *mockRepoForTest) StoreCommitWithParent(treeHash git.Hash, parent git.Hash) (git.Hash, error) { rawHash := sha1.Sum([]byte(treeHash + parent)) - hash := util.Hash(fmt.Sprintf("%x", rawHash)) + hash := git.Hash(fmt.Sprintf("%x", rawHash)) r.commits[hash] = commit{ treeHash: treeHash, parent: parent, @@ -106,7 +107,7 @@ func (r *mockRepoForTest) StoreCommitWithParent(treeHash util.Hash, parent util. return hash, nil } -func (r *mockRepoForTest) UpdateRef(ref string, hash util.Hash) error { +func (r *mockRepoForTest) UpdateRef(ref string, hash git.Hash) error { r.refs[ref] = hash return nil } @@ -139,8 +140,8 @@ func (r *mockRepoForTest) ListRefs(refspec string) ([]string, error) { return keys, nil } -func (r *mockRepoForTest) ListCommits(ref string) ([]util.Hash, error) { - var hashes []util.Hash +func (r *mockRepoForTest) ListCommits(ref string) ([]git.Hash, error) { + var hashes []git.Hash hash := r.refs[ref] @@ -151,14 +152,14 @@ func (r *mockRepoForTest) ListCommits(ref string) ([]util.Hash, error) { break } - hashes = append([]util.Hash{hash}, hashes...) + hashes = append([]git.Hash{hash}, hashes...) hash = commit.parent } return hashes, nil } -func (r *mockRepoForTest) ListEntries(hash util.Hash) ([]TreeEntry, error) { +func (r *mockRepoForTest) ListEntries(hash git.Hash) ([]TreeEntry, error) { var data string data, ok := r.trees[hash] @@ -181,11 +182,11 @@ func (r *mockRepoForTest) ListEntries(hash util.Hash) ([]TreeEntry, error) { return readTreeEntries(data) } -func (r *mockRepoForTest) FindCommonAncestor(hash1 util.Hash, hash2 util.Hash) (util.Hash, error) { +func (r *mockRepoForTest) FindCommonAncestor(hash1 git.Hash, hash2 git.Hash) (git.Hash, error) { panic("implement me") } -func (r *mockRepoForTest) GetTreeHash(commit util.Hash) (util.Hash, error) { +func (r *mockRepoForTest) GetTreeHash(commit git.Hash) (git.Hash, error) { panic("implement me") } @@ -197,20 +198,20 @@ func (r *mockRepoForTest) WriteClocks() error { return nil } -func (r *mockRepoForTest) CreateTimeIncrement() (util.LamportTime, error) { +func (r *mockRepoForTest) CreateTimeIncrement() (lamport.Time, error) { return r.createClock.Increment(), nil } -func (r *mockRepoForTest) EditTimeIncrement() (util.LamportTime, error) { +func (r *mockRepoForTest) EditTimeIncrement() (lamport.Time, error) { return r.editClock.Increment(), nil } -func (r *mockRepoForTest) CreateWitness(time util.LamportTime) error { +func (r *mockRepoForTest) CreateWitness(time lamport.Time) error { r.createClock.Witness(time) return nil } -func (r *mockRepoForTest) EditWitness(time util.LamportTime) error { +func (r *mockRepoForTest) EditWitness(time lamport.Time) error { r.editClock.Witness(time) return nil } |