1
0

mocks.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package gitutil
  2. import (
  3. "testing"
  4. "github.com/gogs/git-module"
  5. )
  6. var _ ModuleStore = (*MockModuleStore)(nil)
  7. type MockModuleStore struct {
  8. remoteAdd func(repoPath, name, url string, opts ...git.RemoteAddOptions) error
  9. diffNameOnly func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
  10. log func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
  11. mergeBase func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
  12. remoteRemove func(repoPath, name string, opts ...git.RemoteRemoveOptions) error
  13. repoTags func(repoPath string, opts ...git.TagsOptions) ([]string, error)
  14. pullRequestMeta func(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
  15. listTagsAfter func(repoPath, after string, limit int) (*TagsPage, error)
  16. }
  17. func (m *MockModuleStore) RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error {
  18. return m.remoteAdd(repoPath, name, url, opts...)
  19. }
  20. func (m *MockModuleStore) DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
  21. return m.diffNameOnly(repoPath, base, head, opts...)
  22. }
  23. func (m *MockModuleStore) Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
  24. return m.log(repoPath, rev, opts...)
  25. }
  26. func (m *MockModuleStore) MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
  27. return m.mergeBase(repoPath, base, head, opts...)
  28. }
  29. func (m *MockModuleStore) RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error {
  30. return m.remoteRemove(repoPath, name, opts...)
  31. }
  32. func (m *MockModuleStore) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {
  33. return m.repoTags(repoPath, opts...)
  34. }
  35. func (m *MockModuleStore) PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error) {
  36. return m.pullRequestMeta(headPath, basePath, headBranch, baseBranch)
  37. }
  38. func (m *MockModuleStore) ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error) {
  39. return m.listTagsAfter(repoPath, after, limit)
  40. }
  41. func SetMockModuleStore(t *testing.T, mock ModuleStore) {
  42. before := Module
  43. Module = mock
  44. t.Cleanup(func() {
  45. Module = before
  46. })
  47. }