aboutsummaryrefslogtreecommitdiff
path: root/internal/gitutil/mocks.go
blob: b58fa079b5f7a49af88eb5b570fab479365ed91e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 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)

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
	})
}