diff options
author | Michael Muré <batolettre@gmail.com> | 2019-11-01 22:16:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-01 22:16:57 +0000 |
commit | f5193cc76dd1a1c1bb55194a64ef90bae2278115 (patch) | |
tree | 74c5f184df4fb27bec0d6f809ce9816ec133d80f /repository/mock_repo.go | |
parent | 11b4a1beb7e1ab8809515a5ce21e8708fba7f300 (diff) | |
parent | f9f82957a78ea0d3cacddbc6914ce98b94ddf7bd (diff) | |
download | git-bug-f5193cc76dd1a1c1bb55194a64ef90bae2278115.tar.gz |
Merge pull request #240 from MichaelMure/repo-config
repository config interface and implementation rework
Diffstat (limited to 'repository/mock_repo.go')
-rw-r--r-- | repository/mock_repo.go | 74 |
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 |