mock_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package gitutil
  5. import (
  6. "testing"
  7. "github.com/gogs/git-module"
  8. )
  9. var _ ModuleStore = (*MockModuleStore)(nil)
  10. // MockModuleStore is a mock implementation of ModuleStore interface.
  11. type MockModuleStore struct {
  12. repoAddRemote func(repoPath, name, url string, opts ...git.AddRemoteOptions) error
  13. repoDiffNameOnly func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
  14. repoLog func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
  15. repoMergeBase func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
  16. repoRemoveRemote func(repoPath, name string, opts ...git.RemoveRemoteOptions) error
  17. repoTags func(repoPath string, opts ...git.TagsOptions) ([]string, error)
  18. pullRequestMeta func(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
  19. listTagsAfter func(repoPath, after string, limit int) (*TagsPage, error)
  20. }
  21. func (m *MockModuleStore) RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error {
  22. return m.repoAddRemote(repoPath, name, url, opts...)
  23. }
  24. func (m *MockModuleStore) RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
  25. return m.repoDiffNameOnly(repoPath, base, head, opts...)
  26. }
  27. func (m *MockModuleStore) RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
  28. return m.repoLog(repoPath, rev, opts...)
  29. }
  30. func (m *MockModuleStore) RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
  31. return m.repoMergeBase(repoPath, base, head, opts...)
  32. }
  33. func (m *MockModuleStore) RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error {
  34. return m.repoRemoveRemote(repoPath, name, opts...)
  35. }
  36. func (m *MockModuleStore) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {
  37. return m.repoTags(repoPath, opts...)
  38. }
  39. func (m *MockModuleStore) PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error) {
  40. return m.pullRequestMeta(headPath, basePath, headBranch, baseBranch)
  41. }
  42. func (m *MockModuleStore) ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error) {
  43. return m.listTagsAfter(repoPath, after, limit)
  44. }
  45. func SetMockModuleStore(t *testing.T, mock ModuleStore) {
  46. before := Module
  47. Module = mock
  48. t.Cleanup(func() {
  49. Module = before
  50. })
  51. }