-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathtestwebvcs.go
126 lines (104 loc) · 3.72 KB
/
testwebvcs.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package provider
import (
"context"
"fmt"
"net/http"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
"github.com/openshift-pipelines/pipelines-as-code/pkg/changedfiles"
"github.com/openshift-pipelines/pipelines-as-code/pkg/events"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
"go.uber.org/zap"
)
var _ provider.Interface = (*TestProviderImp)(nil)
type TestProviderImp struct {
AllowIT bool
Event *info.Event
TektonDirTemplate string
CreateStatusErorring bool
FilesInsideRepo map[string]string
WantProviderRemoteTask bool
PolicyDisallowing bool
AllowedInOwnersFile bool
WantAllChangedFiles []string
WantAddedFiles []string
WantDeletedFiles []string
WantModifiedFiles []string
WantRenamedFiles []string
pacInfo *info.PacOpts
}
func (v *TestProviderImp) SetPacInfo(pacInfo *info.PacOpts) {
v.pacInfo = pacInfo
}
func (v *TestProviderImp) CheckPolicyAllowing(_ context.Context, _ *info.Event, _ []string) (bool, string) {
if v.PolicyDisallowing {
return false, "policy disallowing"
}
return true, ""
}
func (v *TestProviderImp) IsAllowedOwnersFile(_ context.Context, _ *info.Event) (bool, error) {
return v.AllowedInOwnersFile, nil
}
func (v *TestProviderImp) SetLogger(_ *zap.SugaredLogger) {
}
func (v *TestProviderImp) Validate(_ context.Context, _ *params.Run, _ *info.Event) error {
return nil
}
func (v *TestProviderImp) Detect(_ *http.Request, _ string, _ *zap.SugaredLogger) (bool, bool, *zap.SugaredLogger, string, error) {
return true, true, nil, "", nil
}
func (v *TestProviderImp) ParsePayload(_ context.Context, _ *params.Run, _ *http.Request, _ string) (*info.Event, error) {
return v.Event, nil
}
func (v *TestProviderImp) GetConfig() *info.ProviderConfig {
return &info.ProviderConfig{}
}
func (v *TestProviderImp) GetCommitInfo(_ context.Context, _ *info.Event) error {
return nil
}
func (v *TestProviderImp) SetClient(_ context.Context, _ *params.Run, _ *info.Event, _ *v1alpha1.Repository, _ *events.EventEmitter) error {
return nil
}
func (v *TestProviderImp) IsAllowed(_ context.Context, _ *info.Event) (bool, error) {
if v.AllowIT {
return true, nil
}
return false, nil
}
func (v *TestProviderImp) GetTaskURI(_ context.Context, _ *info.Event, _ string) (bool, string, error) {
return v.WantProviderRemoteTask, "", nil
}
func (v *TestProviderImp) CreateStatus(_ context.Context, _ *info.Event, _ provider.StatusOpts) error {
if v.CreateStatusErorring {
return fmt.Errorf("some provider error occurred while reporting status")
}
return nil
}
func (v *TestProviderImp) GetTektonDir(_ context.Context, _ *info.Event, _, _ string) (string, error) {
return v.TektonDirTemplate, nil
}
func (v *TestProviderImp) GetFileInsideRepo(_ context.Context, _ *info.Event, file, _ string) (string, error) {
if val, ok := v.FilesInsideRepo[file]; ok {
return val, nil
}
return "", fmt.Errorf("could not find %s in tests", file)
}
func (v *TestProviderImp) GetFiles(_ context.Context, _ *info.Event) (changedfiles.ChangedFiles, error) {
if v == nil {
return changedfiles.ChangedFiles{}, nil
}
return changedfiles.ChangedFiles{
All: v.WantAllChangedFiles,
Added: v.WantAddedFiles,
Deleted: v.WantDeletedFiles,
Modified: v.WantModifiedFiles,
Renamed: v.WantRenamedFiles,
}, nil
}
func (v *TestProviderImp) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
return "", nil
}
func (v *TestProviderImp) GetTemplate(commentType provider.CommentType) string {
return provider.GetHTMLTemplate(commentType)
}