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.go74
1 files changed, 18 insertions, 56 deletions
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 23534b89..26c02ede 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -3,8 +3,6 @@ package repository
import (
"crypto/sha1"
"fmt"
- "strconv"
- "strings"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/lamport"
@@ -14,13 +12,14 @@ var _ ClockedRepo = &mockRepoForTest{}
// mockRepoForTest defines an instance of Repo that can be used for testing.
type mockRepoForTest struct {
- config map[string]string
- 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
+ config map[string]string
+ globalConfig map[string]string
+ 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 {
@@ -40,6 +39,16 @@ func NewMockRepoForTest() *mockRepoForTest {
}
}
+// LocalConfig give access to the repository scoped configuration
+func (r *mockRepoForTest) LocalConfig() Config {
+ return newMemConfig(r.config)
+}
+
+// GlobalConfig give access to the git global configuration
+func (r *mockRepoForTest) GlobalConfig() Config {
+ return newMemConfig(r.globalConfig)
+}
+
// GetPath returns the path to the repo.
func (r *mockRepoForTest) GetPath() string {
return "~/mockRepo/"
@@ -66,53 +75,6 @@ func (r *mockRepoForTest) GetRemotes() (map[string]string, error) {
}, nil
}
-func (r *mockRepoForTest) StoreConfig(key string, value string) error {
- r.config[key] = value
- return nil
-}
-
-func (r *mockRepoForTest) ReadConfigs(keyPrefix string) (map[string]string, error) {
- result := make(map[string]string)
-
- for key, val := range r.config {
- if strings.HasPrefix(key, keyPrefix) {
- result[key] = val
- }
- }
-
- return result, nil
-}
-
-func (r *mockRepoForTest) ReadConfigBool(key string) (bool, error) {
- // unlike git, the mock can only store one value for the same key
- val, ok := r.config[key]
- if !ok {
- return false, ErrNoConfigEntry
- }
-
- return strconv.ParseBool(val)
-}
-
-func (r *mockRepoForTest) ReadConfigString(key string) (string, error) {
- // unlike git, the mock can only store one value for the same key
- val, ok := r.config[key]
- if !ok {
- return "", ErrNoConfigEntry
- }
-
- return val, nil
-}
-
-// RmConfigs remove all key/value pair matching the key prefix
-func (r *mockRepoForTest) RmConfigs(keyPrefix string) error {
- for key := range r.config {
- if strings.HasPrefix(key, keyPrefix) {
- delete(r.config, key)
- }
- }
- return nil
-}
-
// PushRefs push git refs to a remote
func (r *mockRepoForTest) PushRefs(remote string, refSpec string) (string, error) {
return "", nil