diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-03-29 20:15:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-29 20:15:42 +0800 |
commit | 4cbb43b860548da07132bcec79e42cbc038a9a36 (patch) | |
tree | 96ea979f709024a3e179c8b21aa58a26a11fa389 /internal/gitutil/mock_test.go | |
parent | 933206f1fe55dd3444315bcb51e45f7a4277909a (diff) |
gitutil: simplify mock with `t.Cleanup` (#6033)
* gitutil: simplify mock with t.Cleanup
* Scope mock to tests only
Diffstat (limited to 'internal/gitutil/mock_test.go')
-rw-r--r-- | internal/gitutil/mock_test.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/internal/gitutil/mock_test.go b/internal/gitutil/mock_test.go new file mode 100644 index 00000000..161d4474 --- /dev/null +++ b/internal/gitutil/mock_test.go @@ -0,0 +1,66 @@ +// Copyright 2020 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gitutil + +import ( + "testing" + + "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) + + 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) +} + +func SetMockModuleStore(t *testing.T, mock ModuleStore) { + before := Module + Module = mock + t.Cleanup(func() { + Module = before + }) +} |