-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
mock.go
95 lines (82 loc) · 3.15 KB
/
mock.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package github
import (
"context"
"errors"
"io"
"net/http"
"net/url"
"strings"
"github.com/google/go-github/v56/github"
)
var (
errReleaseNotFound = errors.New("release isn't found")
errTagNotFound = errors.New("tag isn't found")
errAssetNotFound = errors.New("asset isn't found")
errContentNotFound = errors.New("content isn't found")
errGetTar = errors.New("failed to get tar")
errGetRepo = errors.New("failed to get repo")
errListAssets = errors.New("failed to list assets")
)
type MockRepositoriesService struct {
Releases []*github.RepositoryRelease
Content *github.RepositoryContent
Repo *github.Repository
Tags []*github.RepositoryTag
Asset string
Assets []*github.ReleaseAsset
URL *url.URL
}
func (m *MockRepositoriesService) GetLatestRelease(ctx context.Context, repoOwner, repoName string) (*github.RepositoryRelease, *github.Response, error) {
if len(m.Releases) == 0 {
return nil, nil, errReleaseNotFound
}
return m.Releases[0], nil, nil
}
func (m *MockRepositoriesService) GetContents(ctx context.Context, repoOwner, repoName, path string, opt *github.RepositoryContentGetOptions) (*github.RepositoryContent, []*github.RepositoryContent, *github.Response, error) {
if m.Content == nil {
return m.Content, nil, nil, errContentNotFound
}
return m.Content, nil, nil, nil
}
func (m *MockRepositoriesService) GetReleaseByTag(ctx context.Context, owner, repoName, version string) (*github.RepositoryRelease, *github.Response, error) {
if len(m.Releases) == 0 {
return nil, nil, errReleaseNotFound
}
return m.Releases[0], nil, nil
}
func (m *MockRepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, repoName string, assetID int64, httpClient *http.Client) (io.ReadCloser, string, error) {
if m.Asset == "" {
return nil, "", errAssetNotFound
}
return io.NopCloser(strings.NewReader(m.Asset)), "", nil
}
func (m *MockRepositoriesService) ListReleases(ctx context.Context, owner, repo string, opts *github.ListOptions) ([]*github.RepositoryRelease, *github.Response, error) {
if m.Releases == nil {
return nil, nil, errReleaseNotFound
}
return m.Releases, nil, nil
}
func (m *MockRepositoriesService) ListTags(ctx context.Context, owner string, repo string, opts *github.ListOptions) ([]*github.RepositoryTag, *github.Response, error) {
if m.Tags == nil {
return nil, nil, errTagNotFound
}
return m.Tags, nil, nil
}
func (m *MockRepositoriesService) GetArchiveLink(ctx context.Context, owner, repo string, archiveformat github.ArchiveFormat, opts *github.RepositoryContentGetOptions, maxRedirects int) (*url.URL, *github.Response, error) {
if m.URL == nil {
return nil, nil, errGetTar
}
return m.URL, nil, nil
}
func (m *MockRepositoriesService) Get(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error) {
if m.Repo == nil {
return nil, nil, errGetRepo
}
return m.Repo, nil, nil
}
func (m *MockRepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo string, id int64, opts *github.ListOptions) ([]*github.ReleaseAsset, *github.Response, error) {
if m.Assets == nil {
return nil, nil, errListAssets
}
return m.Assets, nil, nil
}