aboutsummaryrefslogtreecommitdiff
path: root/internal/gitutil/mock.go
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-29 19:37:28 +0800
committerGitHub <noreply@github.com>2020-03-29 19:37:28 +0800
commit933206f1fe55dd3444315bcb51e45f7a4277909a (patch)
tree0ce2213e9d9bc1bcbac010a51fdea5c8d1c11585 /internal/gitutil/mock.go
parent9356231e6488edfd281f18ab191b2f93907b61d7 (diff)
gitutil: refactor the way to mock (#6032)
* Refactor the mock module store * Only test on 1.14.x
Diffstat (limited to 'internal/gitutil/mock.go')
-rw-r--r--internal/gitutil/mock.go57
1 files changed, 45 insertions, 12 deletions
diff --git a/internal/gitutil/mock.go b/internal/gitutil/mock.go
index 6cd90dfa..73727c31 100644
--- a/internal/gitutil/mock.go
+++ b/internal/gitutil/mock.go
@@ -8,16 +8,49 @@ import (
"github.com/gogs/git-module"
)
+var _ ModuleStore = (*MockModuleStore)(nil)
+
+// MockModuleStore is a mock implementation of ModuleStore interface.
type MockModuleStore struct {
- RepoAddRemote func(repoPath, name, url string, opts ...git.AddRemoteOptions) error
- RepoDiffNameOnly func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
- RepoLog func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
- RepoMergeBase func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
- RepoRemoveRemote func(repoPath, name string, opts ...git.RemoveRemoteOptions) error
- RepoTags func(repoPath string, opts ...git.TagsOptions) ([]string, error)
-}
-
-// MockModule holds mock implementation of each method for Modulers interface.
-// When the field is non-nil, it is considered mocked. Otherwise, the real
-// implementation will be executed.
-var MockModule MockModuleStore
+ repoAddRemote func(repoPath, name, url string, opts ...git.AddRemoteOptions) error
+ repoDiffNameOnly func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
+ repoLog func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
+ repoMergeBase func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
+ repoRemoveRemote func(repoPath, name string, opts ...git.RemoveRemoteOptions) error
+ repoTags func(repoPath string, opts ...git.TagsOptions) ([]string, error)
+
+ pullRequestMeta func(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
+ listTagsAfter func(repoPath, after string, limit int) (*TagsPage, error)
+}
+
+func (m *MockModuleStore) RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error {
+ return m.repoAddRemote(repoPath, name, url, opts...)
+}
+
+func (m *MockModuleStore) RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
+ return m.repoDiffNameOnly(repoPath, base, head, opts...)
+}
+
+func (m *MockModuleStore) RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
+ return m.repoLog(repoPath, rev, opts...)
+}
+
+func (m *MockModuleStore) RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
+ return m.repoMergeBase(repoPath, base, head, opts...)
+}
+
+func (m *MockModuleStore) RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error {
+ return m.repoRemoveRemote(repoPath, name, opts...)
+}
+
+func (m *MockModuleStore) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {
+ return m.repoTags(repoPath, opts...)
+}
+
+func (m *MockModuleStore) PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error) {
+ return m.pullRequestMeta(headPath, basePath, headBranch, baseBranch)
+}
+
+func (m *MockModuleStore) ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error) {
+ return m.listTagsAfter(repoPath, after, limit)
+}