mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-05 10:58:37 +00:00
Remove duplicate vcs proxy interface
This is the same interface as vcs.Client so no need to have both.
This commit is contained in:
@@ -54,7 +54,7 @@ type GitlabMergeRequestGetter interface {
|
||||
|
||||
// DefaultCommandRunner is the first step when processing a comment command.
|
||||
type DefaultCommandRunner struct {
|
||||
VCSClient vcs.ClientProxy
|
||||
VCSClient vcs.Client
|
||||
GithubPullGetter GithubPullGetter
|
||||
GitlabMergeRequestGetter GitlabMergeRequestGetter
|
||||
CommitStatusUpdater CommitStatusUpdater
|
||||
|
||||
@@ -44,12 +44,12 @@ var pullLogger *logging.SimpleLogger
|
||||
var workingDir events.WorkingDir
|
||||
var pendingPlanFinder *mocks.MockPendingPlanFinder
|
||||
|
||||
func setup(t *testing.T) *vcsmocks.MockClientProxy {
|
||||
func setup(t *testing.T) *vcsmocks.MockClient {
|
||||
RegisterMockTestingT(t)
|
||||
projectCommandBuilder = mocks.NewMockProjectCommandBuilder()
|
||||
eventParsing = mocks.NewMockEventParsing()
|
||||
ghStatus = mocks.NewMockCommitStatusUpdater()
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
githubGetter = mocks.NewMockGithubPullGetter()
|
||||
gitlabGetter = mocks.NewMockGitlabMergeRequestGetter()
|
||||
logger := logmocks.NewMockSimpleLogging()
|
||||
|
||||
@@ -35,7 +35,7 @@ type CommitStatusUpdater interface {
|
||||
|
||||
// DefaultCommitStatusUpdater implements CommitStatusUpdater.
|
||||
type DefaultCommitStatusUpdater struct {
|
||||
Client vcs.ClientProxy
|
||||
Client vcs.Client
|
||||
}
|
||||
|
||||
// Update updates the commit status.
|
||||
|
||||
@@ -31,7 +31,7 @@ var status = models.SuccessCommitStatus
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
RegisterMockTestingT(t)
|
||||
client := mocks.NewMockClientProxy()
|
||||
client := mocks.NewMockClient()
|
||||
s := events.DefaultCommitStatusUpdater{Client: client}
|
||||
err := s.Update(repoModel, pullModel, status, events.PlanCommand)
|
||||
Ok(t, err)
|
||||
@@ -44,7 +44,7 @@ func TestUpdateProjectResult_Error(t *testing.T) {
|
||||
BaseRepo: repoModel,
|
||||
Pull: pullModel,
|
||||
}
|
||||
client := mocks.NewMockClientProxy()
|
||||
client := mocks.NewMockClient()
|
||||
s := events.DefaultCommitStatusUpdater{Client: client}
|
||||
err := s.UpdateProjectResult(ctx, events.PlanCommand, events.CommandResult{Error: errors.New("err")})
|
||||
Ok(t, err)
|
||||
@@ -57,7 +57,7 @@ func TestUpdateProjectResult_Failure(t *testing.T) {
|
||||
BaseRepo: repoModel,
|
||||
Pull: pullModel,
|
||||
}
|
||||
client := mocks.NewMockClientProxy()
|
||||
client := mocks.NewMockClient()
|
||||
s := events.DefaultCommitStatusUpdater{Client: client}
|
||||
err := s.UpdateProjectResult(ctx, events.PlanCommand, events.CommandResult{Failure: "failure"})
|
||||
Ok(t, err)
|
||||
@@ -127,7 +127,7 @@ func TestUpdateProjectResult(t *testing.T) {
|
||||
}
|
||||
resp := events.CommandResult{ProjectResults: results}
|
||||
|
||||
client := mocks.NewMockClientProxy()
|
||||
client := mocks.NewMockClient()
|
||||
s := events.DefaultCommitStatusUpdater{Client: client}
|
||||
err := s.UpdateProjectResult(ctx, events.PlanCommand, resp)
|
||||
Ok(t, err)
|
||||
|
||||
@@ -45,7 +45,7 @@ type ProjectCommandBuilder interface {
|
||||
type DefaultProjectCommandBuilder struct {
|
||||
ParserValidator *yaml.ParserValidator
|
||||
ProjectFinder ProjectFinder
|
||||
VCSClient vcs.ClientProxy
|
||||
VCSClient vcs.Client
|
||||
WorkingDir WorkingDir
|
||||
WorkingDirLocker WorkingDirLocker
|
||||
AllowRepoConfig bool
|
||||
|
||||
@@ -187,7 +187,7 @@ projects:
|
||||
err := ioutil.WriteFile(filepath.Join(tmpDir, "main.tf"), nil, 0600)
|
||||
Ok(t, err)
|
||||
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
When(vcsClient.GetModifiedFiles(baseRepo, pull)).ThenReturn([]string{"main.tf"}, nil)
|
||||
|
||||
builder := &events.DefaultProjectCommandBuilder{
|
||||
@@ -467,7 +467,7 @@ projects:
|
||||
err := ioutil.WriteFile(filepath.Join(tmpDir, "main.tf"), nil, 0600)
|
||||
Ok(t, err)
|
||||
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
When(vcsClient.GetModifiedFiles(baseRepo, pull)).ThenReturn([]string{"main.tf"}, nil)
|
||||
|
||||
builder := &events.DefaultProjectCommandBuilder{
|
||||
@@ -539,7 +539,7 @@ func TestDefaultProjectCommandBuilder_BuildMultiPlanNoAtlantisYAML(t *testing.T)
|
||||
matchers.AnyModelsRepo(),
|
||||
matchers.AnyModelsPullRequest(),
|
||||
AnyString())).ThenReturn(tmpDir, nil)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
When(vcsClient.GetModifiedFiles(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn([]string{"project1/main.tf", "project2/main.tf"}, nil)
|
||||
|
||||
builder := &events.DefaultProjectCommandBuilder{
|
||||
@@ -592,7 +592,7 @@ func TestDefaultProjectCommandBuilder_BuildMultiPlanNoAtlantisYAMLNoModified(t *
|
||||
matchers.AnyModelsRepo(),
|
||||
matchers.AnyModelsPullRequest(),
|
||||
AnyString())).ThenReturn(tmpDir, nil)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
When(vcsClient.GetModifiedFiles(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn([]string{}, nil)
|
||||
|
||||
builder := &events.DefaultProjectCommandBuilder{
|
||||
@@ -662,7 +662,7 @@ projects:
|
||||
matchers.AnyModelsRepo(),
|
||||
matchers.AnyModelsPullRequest(),
|
||||
AnyString())).ThenReturn(tmpDir, nil)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
When(vcsClient.GetModifiedFiles(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn([]string{
|
||||
"project1/main.tf", "project2/main.tf", "project3/main.tf",
|
||||
}, nil)
|
||||
@@ -726,7 +726,7 @@ projects:
|
||||
matchers.AnyModelsRepo(),
|
||||
matchers.AnyModelsPullRequest(),
|
||||
AnyString())).ThenReturn(tmpDir, nil)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
When(vcsClient.GetModifiedFiles(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn([]string{"main.tf"}, nil)
|
||||
|
||||
builder := &events.DefaultProjectCommandBuilder{
|
||||
|
||||
@@ -42,7 +42,7 @@ type PullCleaner interface {
|
||||
// request.
|
||||
type PullClosedExecutor struct {
|
||||
Locker locking.Locker
|
||||
VCSClient vcs.ClientProxy
|
||||
VCSClient vcs.Client
|
||||
WorkingDir WorkingDir
|
||||
Logger logging.SimpleLogging
|
||||
DB *db.BoltDB
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestCleanUpPullNoLocks(t *testing.T) {
|
||||
RegisterMockTestingT(t)
|
||||
w := mocks.NewMockWorkingDir()
|
||||
l := lockmocks.NewMockLocker()
|
||||
cp := vcsmocks.NewMockClientProxy()
|
||||
cp := vcsmocks.NewMockClient()
|
||||
tmp, cleanup := TempDir(t)
|
||||
defer cleanup()
|
||||
db, err := db.New(tmp)
|
||||
@@ -147,7 +147,7 @@ func TestCleanUpPullComments(t *testing.T) {
|
||||
for _, c := range cases {
|
||||
func() {
|
||||
w := mocks.NewMockWorkingDir()
|
||||
cp := vcsmocks.NewMockClientProxy()
|
||||
cp := vcsmocks.NewMockClient()
|
||||
l := lockmocks.NewMockLocker()
|
||||
tmp, cleanup := TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -105,6 +105,21 @@ func (mock *MockClient) UpdateStatus(repo models.Repo, pull models.PullRequest,
|
||||
return ret0
|
||||
}
|
||||
|
||||
func (mock *MockClient) MergePull(pull models.PullRequest) error {
|
||||
if mock == nil {
|
||||
panic("mock must not be nil. Use myMock := NewMockClient().")
|
||||
}
|
||||
params := []pegomock.Param{pull}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("MergePull", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 error
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
ret0 = result[0].(error)
|
||||
}
|
||||
}
|
||||
return ret0
|
||||
}
|
||||
|
||||
func (mock *MockClient) VerifyWasCalledOnce() *VerifierClient {
|
||||
return &VerifierClient{
|
||||
mock: mock,
|
||||
@@ -308,3 +323,30 @@ func (c *Client_UpdateStatus_OngoingVerification) GetAllCapturedArguments() (_pa
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierClient) MergePull(pull models.PullRequest) *Client_MergePull_OngoingVerification {
|
||||
params := []pegomock.Param{pull}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MergePull", params, verifier.timeout)
|
||||
return &Client_MergePull_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
type Client_MergePull_OngoingVerification struct {
|
||||
mock *MockClient
|
||||
methodInvocations []pegomock.MethodInvocation
|
||||
}
|
||||
|
||||
func (c *Client_MergePull_OngoingVerification) GetCapturedArguments() models.PullRequest {
|
||||
pull := c.GetAllCapturedArguments()
|
||||
return pull[len(pull)-1]
|
||||
}
|
||||
|
||||
func (c *Client_MergePull_OngoingVerification) GetAllCapturedArguments() (_param0 []models.PullRequest) {
|
||||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
|
||||
if len(params) > 0 {
|
||||
_param0 = make([]models.PullRequest, len(params[0]))
|
||||
for u, param := range params[0] {
|
||||
_param0[u] = param.(models.PullRequest)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,352 +0,0 @@
|
||||
// Code generated by pegomock. DO NOT EDIT.
|
||||
// Source: github.com/runatlantis/atlantis/server/events/vcs (interfaces: ClientProxy)
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
pegomock "github.com/petergtz/pegomock"
|
||||
models "github.com/runatlantis/atlantis/server/events/models"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MockClientProxy struct {
|
||||
fail func(message string, callerSkip ...int)
|
||||
}
|
||||
|
||||
func NewMockClientProxy() *MockClientProxy {
|
||||
return &MockClientProxy{fail: pegomock.GlobalFailHandler}
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error) {
|
||||
if mock == nil {
|
||||
panic("mock must not be nil. Use myMock := NewMockClientProxy().")
|
||||
}
|
||||
params := []pegomock.Param{repo, pull}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("GetModifiedFiles", params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 []string
|
||||
var ret1 error
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
ret0 = result[0].([]string)
|
||||
}
|
||||
if result[1] != nil {
|
||||
ret1 = result[1].(error)
|
||||
}
|
||||
}
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) CreateComment(repo models.Repo, pullNum int, comment string) error {
|
||||
if mock == nil {
|
||||
panic("mock must not be nil. Use myMock := NewMockClientProxy().")
|
||||
}
|
||||
params := []pegomock.Param{repo, pullNum, comment}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("CreateComment", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 error
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
ret0 = result[0].(error)
|
||||
}
|
||||
}
|
||||
return ret0
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) {
|
||||
if mock == nil {
|
||||
panic("mock must not be nil. Use myMock := NewMockClientProxy().")
|
||||
}
|
||||
params := []pegomock.Param{repo, pull}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsApproved", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 bool
|
||||
var ret1 error
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
ret0 = result[0].(bool)
|
||||
}
|
||||
if result[1] != nil {
|
||||
ret1 = result[1].(error)
|
||||
}
|
||||
}
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error) {
|
||||
if mock == nil {
|
||||
panic("mock must not be nil. Use myMock := NewMockClientProxy().")
|
||||
}
|
||||
params := []pegomock.Param{repo, pull}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("PullIsMergeable", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 bool
|
||||
var ret1 error
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
ret0 = result[0].(bool)
|
||||
}
|
||||
if result[1] != nil {
|
||||
ret1 = result[1].(error)
|
||||
}
|
||||
}
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, description string) error {
|
||||
if mock == nil {
|
||||
panic("mock must not be nil. Use myMock := NewMockClientProxy().")
|
||||
}
|
||||
params := []pegomock.Param{repo, pull, state, description}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("UpdateStatus", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 error
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
ret0 = result[0].(error)
|
||||
}
|
||||
}
|
||||
return ret0
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) MergePull(pull models.PullRequest) error {
|
||||
if mock == nil {
|
||||
panic("mock must not be nil. Use myMock := NewMockClientProxy().")
|
||||
}
|
||||
params := []pegomock.Param{pull}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("MergePull", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 error
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
ret0 = result[0].(error)
|
||||
}
|
||||
}
|
||||
return ret0
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) VerifyWasCalledOnce() *VerifierClientProxy {
|
||||
return &VerifierClientProxy{
|
||||
mock: mock,
|
||||
invocationCountMatcher: pegomock.Times(1),
|
||||
}
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierClientProxy {
|
||||
return &VerifierClientProxy{
|
||||
mock: mock,
|
||||
invocationCountMatcher: invocationCountMatcher,
|
||||
}
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierClientProxy {
|
||||
return &VerifierClientProxy{
|
||||
mock: mock,
|
||||
invocationCountMatcher: invocationCountMatcher,
|
||||
inOrderContext: inOrderContext,
|
||||
}
|
||||
}
|
||||
|
||||
func (mock *MockClientProxy) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierClientProxy {
|
||||
return &VerifierClientProxy{
|
||||
mock: mock,
|
||||
invocationCountMatcher: invocationCountMatcher,
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
type VerifierClientProxy struct {
|
||||
mock *MockClientProxy
|
||||
invocationCountMatcher pegomock.Matcher
|
||||
inOrderContext *pegomock.InOrderContext
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func (verifier *VerifierClientProxy) GetModifiedFiles(repo models.Repo, pull models.PullRequest) *ClientProxy_GetModifiedFiles_OngoingVerification {
|
||||
params := []pegomock.Param{repo, pull}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetModifiedFiles", params, verifier.timeout)
|
||||
return &ClientProxy_GetModifiedFiles_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
type ClientProxy_GetModifiedFiles_OngoingVerification struct {
|
||||
mock *MockClientProxy
|
||||
methodInvocations []pegomock.MethodInvocation
|
||||
}
|
||||
|
||||
func (c *ClientProxy_GetModifiedFiles_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest) {
|
||||
repo, pull := c.GetAllCapturedArguments()
|
||||
return repo[len(repo)-1], pull[len(pull)-1]
|
||||
}
|
||||
|
||||
func (c *ClientProxy_GetModifiedFiles_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest) {
|
||||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
|
||||
if len(params) > 0 {
|
||||
_param0 = make([]models.Repo, len(params[0]))
|
||||
for u, param := range params[0] {
|
||||
_param0[u] = param.(models.Repo)
|
||||
}
|
||||
_param1 = make([]models.PullRequest, len(params[1]))
|
||||
for u, param := range params[1] {
|
||||
_param1[u] = param.(models.PullRequest)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierClientProxy) CreateComment(repo models.Repo, pullNum int, comment string) *ClientProxy_CreateComment_OngoingVerification {
|
||||
params := []pegomock.Param{repo, pullNum, comment}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CreateComment", params, verifier.timeout)
|
||||
return &ClientProxy_CreateComment_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
type ClientProxy_CreateComment_OngoingVerification struct {
|
||||
mock *MockClientProxy
|
||||
methodInvocations []pegomock.MethodInvocation
|
||||
}
|
||||
|
||||
func (c *ClientProxy_CreateComment_OngoingVerification) GetCapturedArguments() (models.Repo, int, string) {
|
||||
repo, pullNum, comment := c.GetAllCapturedArguments()
|
||||
return repo[len(repo)-1], pullNum[len(pullNum)-1], comment[len(comment)-1]
|
||||
}
|
||||
|
||||
func (c *ClientProxy_CreateComment_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []int, _param2 []string) {
|
||||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
|
||||
if len(params) > 0 {
|
||||
_param0 = make([]models.Repo, len(params[0]))
|
||||
for u, param := range params[0] {
|
||||
_param0[u] = param.(models.Repo)
|
||||
}
|
||||
_param1 = make([]int, len(params[1]))
|
||||
for u, param := range params[1] {
|
||||
_param1[u] = param.(int)
|
||||
}
|
||||
_param2 = make([]string, len(params[2]))
|
||||
for u, param := range params[2] {
|
||||
_param2[u] = param.(string)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) *ClientProxy_PullIsApproved_OngoingVerification {
|
||||
params := []pegomock.Param{repo, pull}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PullIsApproved", params, verifier.timeout)
|
||||
return &ClientProxy_PullIsApproved_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
type ClientProxy_PullIsApproved_OngoingVerification struct {
|
||||
mock *MockClientProxy
|
||||
methodInvocations []pegomock.MethodInvocation
|
||||
}
|
||||
|
||||
func (c *ClientProxy_PullIsApproved_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest) {
|
||||
repo, pull := c.GetAllCapturedArguments()
|
||||
return repo[len(repo)-1], pull[len(pull)-1]
|
||||
}
|
||||
|
||||
func (c *ClientProxy_PullIsApproved_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest) {
|
||||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
|
||||
if len(params) > 0 {
|
||||
_param0 = make([]models.Repo, len(params[0]))
|
||||
for u, param := range params[0] {
|
||||
_param0[u] = param.(models.Repo)
|
||||
}
|
||||
_param1 = make([]models.PullRequest, len(params[1]))
|
||||
for u, param := range params[1] {
|
||||
_param1[u] = param.(models.PullRequest)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierClientProxy) PullIsMergeable(repo models.Repo, pull models.PullRequest) *ClientProxy_PullIsMergeable_OngoingVerification {
|
||||
params := []pegomock.Param{repo, pull}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PullIsMergeable", params, verifier.timeout)
|
||||
return &ClientProxy_PullIsMergeable_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
type ClientProxy_PullIsMergeable_OngoingVerification struct {
|
||||
mock *MockClientProxy
|
||||
methodInvocations []pegomock.MethodInvocation
|
||||
}
|
||||
|
||||
func (c *ClientProxy_PullIsMergeable_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest) {
|
||||
repo, pull := c.GetAllCapturedArguments()
|
||||
return repo[len(repo)-1], pull[len(pull)-1]
|
||||
}
|
||||
|
||||
func (c *ClientProxy_PullIsMergeable_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest) {
|
||||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
|
||||
if len(params) > 0 {
|
||||
_param0 = make([]models.Repo, len(params[0]))
|
||||
for u, param := range params[0] {
|
||||
_param0[u] = param.(models.Repo)
|
||||
}
|
||||
_param1 = make([]models.PullRequest, len(params[1]))
|
||||
for u, param := range params[1] {
|
||||
_param1[u] = param.(models.PullRequest)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierClientProxy) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, description string) *ClientProxy_UpdateStatus_OngoingVerification {
|
||||
params := []pegomock.Param{repo, pull, state, description}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateStatus", params, verifier.timeout)
|
||||
return &ClientProxy_UpdateStatus_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
type ClientProxy_UpdateStatus_OngoingVerification struct {
|
||||
mock *MockClientProxy
|
||||
methodInvocations []pegomock.MethodInvocation
|
||||
}
|
||||
|
||||
func (c *ClientProxy_UpdateStatus_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest, models.CommitStatus, string) {
|
||||
repo, pull, state, description := c.GetAllCapturedArguments()
|
||||
return repo[len(repo)-1], pull[len(pull)-1], state[len(state)-1], description[len(description)-1]
|
||||
}
|
||||
|
||||
func (c *ClientProxy_UpdateStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest, _param2 []models.CommitStatus, _param3 []string) {
|
||||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
|
||||
if len(params) > 0 {
|
||||
_param0 = make([]models.Repo, len(params[0]))
|
||||
for u, param := range params[0] {
|
||||
_param0[u] = param.(models.Repo)
|
||||
}
|
||||
_param1 = make([]models.PullRequest, len(params[1]))
|
||||
for u, param := range params[1] {
|
||||
_param1[u] = param.(models.PullRequest)
|
||||
}
|
||||
_param2 = make([]models.CommitStatus, len(params[2]))
|
||||
for u, param := range params[2] {
|
||||
_param2[u] = param.(models.CommitStatus)
|
||||
}
|
||||
_param3 = make([]string, len(params[3]))
|
||||
for u, param := range params[3] {
|
||||
_param3[u] = param.(string)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierClientProxy) MergePull(pull models.PullRequest) *ClientProxy_MergePull_OngoingVerification {
|
||||
params := []pegomock.Param{pull}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MergePull", params, verifier.timeout)
|
||||
return &ClientProxy_MergePull_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
type ClientProxy_MergePull_OngoingVerification struct {
|
||||
mock *MockClientProxy
|
||||
methodInvocations []pegomock.MethodInvocation
|
||||
}
|
||||
|
||||
func (c *ClientProxy_MergePull_OngoingVerification) GetCapturedArguments() models.PullRequest {
|
||||
pull := c.GetAllCapturedArguments()
|
||||
return pull[len(pull)-1]
|
||||
}
|
||||
|
||||
func (c *ClientProxy_MergePull_OngoingVerification) GetAllCapturedArguments() (_param0 []models.PullRequest) {
|
||||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
|
||||
if len(params) > 0 {
|
||||
_param0 = make([]models.PullRequest, len(params[0]))
|
||||
for u, param := range params[0] {
|
||||
_param0[u] = param.(models.PullRequest)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -17,28 +17,15 @@ import (
|
||||
"github.com/runatlantis/atlantis/server/events/models"
|
||||
)
|
||||
|
||||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_proxy.go ClientProxy
|
||||
|
||||
// ClientProxy proxies calls to the correct VCS client depending on which
|
||||
// VCS host is required.
|
||||
type ClientProxy interface {
|
||||
GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error)
|
||||
CreateComment(repo models.Repo, pullNum int, comment string) error
|
||||
PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error)
|
||||
PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error)
|
||||
UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, description string) error
|
||||
MergePull(pull models.PullRequest) error
|
||||
}
|
||||
|
||||
// DefaultClientProxy proxies calls to the correct VCS client depending on which
|
||||
// VCS host is required.
|
||||
type DefaultClientProxy struct {
|
||||
type ClientProxy struct {
|
||||
// clients maps from the vcs host type to the client that implements the
|
||||
// api for that host type, ex. github -> github client.
|
||||
clients map[models.VCSHostType]Client
|
||||
}
|
||||
|
||||
func NewDefaultClientProxy(githubClient Client, gitlabClient Client, bitbucketCloudClient Client, bitbucketServerClient Client) *DefaultClientProxy {
|
||||
func NewClientProxy(githubClient Client, gitlabClient Client, bitbucketCloudClient Client, bitbucketServerClient Client) *ClientProxy {
|
||||
if githubClient == nil {
|
||||
githubClient = &NotConfiguredVCSClient{}
|
||||
}
|
||||
@@ -51,7 +38,7 @@ func NewDefaultClientProxy(githubClient Client, gitlabClient Client, bitbucketCl
|
||||
if bitbucketServerClient == nil {
|
||||
bitbucketServerClient = &NotConfiguredVCSClient{}
|
||||
}
|
||||
return &DefaultClientProxy{
|
||||
return &ClientProxy{
|
||||
clients: map[models.VCSHostType]Client{
|
||||
models.Github: githubClient,
|
||||
models.Gitlab: gitlabClient,
|
||||
@@ -61,26 +48,26 @@ func NewDefaultClientProxy(githubClient Client, gitlabClient Client, bitbucketCl
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DefaultClientProxy) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error) {
|
||||
func (d *ClientProxy) GetModifiedFiles(repo models.Repo, pull models.PullRequest) ([]string, error) {
|
||||
return d.clients[repo.VCSHost.Type].GetModifiedFiles(repo, pull)
|
||||
}
|
||||
|
||||
func (d *DefaultClientProxy) CreateComment(repo models.Repo, pullNum int, comment string) error {
|
||||
func (d *ClientProxy) CreateComment(repo models.Repo, pullNum int, comment string) error {
|
||||
return d.clients[repo.VCSHost.Type].CreateComment(repo, pullNum, comment)
|
||||
}
|
||||
|
||||
func (d *DefaultClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) {
|
||||
func (d *ClientProxy) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool, error) {
|
||||
return d.clients[repo.VCSHost.Type].PullIsApproved(repo, pull)
|
||||
}
|
||||
|
||||
func (d *DefaultClientProxy) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error) {
|
||||
func (d *ClientProxy) PullIsMergeable(repo models.Repo, pull models.PullRequest) (bool, error) {
|
||||
return d.clients[repo.VCSHost.Type].PullIsMergeable(repo, pull)
|
||||
}
|
||||
|
||||
func (d *DefaultClientProxy) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, description string) error {
|
||||
func (d *ClientProxy) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, description string) error {
|
||||
return d.clients[repo.VCSHost.Type].UpdateStatus(repo, pull, state, description)
|
||||
}
|
||||
|
||||
func (d *DefaultClientProxy) MergePull(pull models.PullRequest) error {
|
||||
func (d *ClientProxy) MergePull(pull models.PullRequest) error {
|
||||
return d.clients[pull.BaseRepo.VCSHost.Type].MergePull(pull)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ type EventsController struct {
|
||||
// SupportedVCSHosts is which VCS hosts Atlantis was configured upon
|
||||
// startup to support.
|
||||
SupportedVCSHosts []models.VCSHostType
|
||||
VCSClient vcs.ClientProxy
|
||||
VCSClient vcs.Client
|
||||
TestingMode bool
|
||||
// BitbucketWebhookSecret is the secret added to this webhook via the Bitbucket
|
||||
// UI that identifies this call as coming from Bitbucket. If empty, no
|
||||
|
||||
@@ -348,13 +348,13 @@ func TestGitHubWorkflow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setupE2E(t *testing.T) (server.EventsController, *vcsmocks.MockClientProxy, *mocks.MockGithubPullGetter, *events.FileWorkspace) {
|
||||
func setupE2E(t *testing.T) (server.EventsController, *vcsmocks.MockClient, *mocks.MockGithubPullGetter, *events.FileWorkspace) {
|
||||
allowForkPRs := false
|
||||
dataDir, cleanup := TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
// Mocks.
|
||||
e2eVCSClient := vcsmocks.NewMockClientProxy()
|
||||
e2eVCSClient := vcsmocks.NewMockClient()
|
||||
e2eStatusUpdater := mocks.NewMockCommitStatusUpdater()
|
||||
e2eGithubGetter := mocks.NewMockGithubPullGetter()
|
||||
e2eGitlabGetter := mocks.NewMockGitlabMergeRequestGetter()
|
||||
|
||||
@@ -184,7 +184,7 @@ func TestPost_GithubCommentInvalidCommand(t *testing.T) {
|
||||
func TestPost_GitlabCommentNotWhitelisted(t *testing.T) {
|
||||
t.Log("when the event is a gitlab comment from a repo that isn't whitelisted we comment with an error")
|
||||
RegisterMockTestingT(t)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
e := server.EventsController{
|
||||
Logger: logging.NewNoopLogger(),
|
||||
CommentParser: &events.CommentParser{},
|
||||
@@ -212,7 +212,7 @@ func TestPost_GitlabCommentNotWhitelisted(t *testing.T) {
|
||||
func TestPost_GitlabCommentNotWhitelistedWithSilenceErrors(t *testing.T) {
|
||||
t.Log("when the event is a gitlab comment from a repo that isn't whitelisted and we are silencing errors, do not comment with an error")
|
||||
RegisterMockTestingT(t)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
e := server.EventsController{
|
||||
Logger: logging.NewNoopLogger(),
|
||||
CommentParser: &events.CommentParser{},
|
||||
@@ -241,7 +241,7 @@ func TestPost_GitlabCommentNotWhitelistedWithSilenceErrors(t *testing.T) {
|
||||
func TestPost_GithubCommentNotWhitelisted(t *testing.T) {
|
||||
t.Log("when the event is a github comment from a repo that isn't whitelisted we comment with an error")
|
||||
RegisterMockTestingT(t)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
e := server.EventsController{
|
||||
Logger: logging.NewNoopLogger(),
|
||||
GithubRequestValidator: &server.DefaultGithubRequestValidator{},
|
||||
@@ -270,7 +270,7 @@ func TestPost_GithubCommentNotWhitelisted(t *testing.T) {
|
||||
func TestPost_GithubCommentNotWhitelistedWithSilenceErrors(t *testing.T) {
|
||||
t.Log("when the event is a github comment from a repo that isn't whitelisted and we are silencing errors, do not comment with an error")
|
||||
RegisterMockTestingT(t)
|
||||
vcsClient := vcsmocks.NewMockClientProxy()
|
||||
vcsClient := vcsmocks.NewMockClient()
|
||||
e := server.EventsController{
|
||||
Logger: logging.NewNoopLogger(),
|
||||
GithubRequestValidator: &server.DefaultGithubRequestValidator{},
|
||||
@@ -581,7 +581,7 @@ func TestPost_PullOpenedOrUpdated(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setup(t *testing.T) (server.EventsController, *mocks.MockGithubRequestValidator, *mocks.MockGitlabRequestParserValidator, *emocks.MockEventParsing, *emocks.MockCommandRunner, *emocks.MockPullCleaner, *vcsmocks.MockClientProxy, *emocks.MockCommentParsing) {
|
||||
func setup(t *testing.T) (server.EventsController, *mocks.MockGithubRequestValidator, *mocks.MockGitlabRequestParserValidator, *emocks.MockEventParsing, *emocks.MockCommandRunner, *emocks.MockPullCleaner, *vcsmocks.MockClient, *emocks.MockCommentParsing) {
|
||||
RegisterMockTestingT(t)
|
||||
v := mocks.NewMockGithubRequestValidator()
|
||||
gl := mocks.NewMockGitlabRequestParserValidator()
|
||||
@@ -589,7 +589,7 @@ func setup(t *testing.T) (server.EventsController, *mocks.MockGithubRequestValid
|
||||
cp := emocks.NewMockCommentParsing()
|
||||
cr := emocks.NewMockCommandRunner()
|
||||
c := emocks.NewMockPullCleaner()
|
||||
vcsmock := vcsmocks.NewMockClientProxy()
|
||||
vcsmock := vcsmocks.NewMockClient()
|
||||
repoWhitelistChecker, err := events.NewRepoWhitelistChecker("*")
|
||||
Ok(t, err)
|
||||
e := server.EventsController{
|
||||
|
||||
@@ -20,7 +20,7 @@ type LocksController struct {
|
||||
AtlantisURL *url.URL
|
||||
Locker locking.Locker
|
||||
Logger *logging.SimpleLogger
|
||||
VCSClient vcs.ClientProxy
|
||||
VCSClient vcs.Client
|
||||
LockDetailTemplate TemplateWriter
|
||||
WorkingDir events.WorkingDir
|
||||
WorkingDirLocker events.WorkingDirLocker
|
||||
|
||||
@@ -175,7 +175,7 @@ func TestDeleteLock_OldFormat(t *testing.T) {
|
||||
t.Log("If the lock doesn't have BaseRepo set it is deleted successfully")
|
||||
RegisterMockTestingT(t)
|
||||
|
||||
cp := vcsmocks.NewMockClientProxy()
|
||||
cp := vcsmocks.NewMockClient()
|
||||
l := mocks.NewMockLocker()
|
||||
When(l.Unlock("id")).ThenReturn(&models.ProjectLock{}, nil)
|
||||
lc := server.LocksController{
|
||||
@@ -195,7 +195,7 @@ func TestDeleteLock_CommentFailed(t *testing.T) {
|
||||
t.Log("If the commenting fails we return an error")
|
||||
RegisterMockTestingT(t)
|
||||
|
||||
cp := vcsmocks.NewMockClientProxy()
|
||||
cp := vcsmocks.NewMockClient()
|
||||
workingDir := mocks2.NewMockWorkingDir()
|
||||
workingDirLocker := events.NewDefaultWorkingDirLocker()
|
||||
When(cp.CreateComment(AnyRepo(), AnyInt(), AnyString())).ThenReturn(errors.New("err"))
|
||||
@@ -228,7 +228,7 @@ func TestDeleteLock_CommentSuccess(t *testing.T) {
|
||||
t.Log("We should comment back on the pull request if the lock is deleted")
|
||||
RegisterMockTestingT(t)
|
||||
|
||||
cp := vcsmocks.NewMockClientProxy()
|
||||
cp := vcsmocks.NewMockClient()
|
||||
l := mocks.NewMockLocker()
|
||||
workingDir := mocks2.NewMockWorkingDir()
|
||||
workingDirLocker := events.NewDefaultWorkingDirLocker()
|
||||
|
||||
@@ -163,7 +163,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "initializing webhooks")
|
||||
}
|
||||
vcsClient := vcs.NewDefaultClientProxy(githubClient, gitlabClient, bitbucketCloudClient, bitbucketServerClient)
|
||||
vcsClient := vcs.NewClientProxy(githubClient, gitlabClient, bitbucketCloudClient, bitbucketServerClient)
|
||||
commitStatusUpdater := &events.DefaultCommitStatusUpdater{Client: vcsClient}
|
||||
terraformClient, err := terraform.NewClient(userConfig.DataDir, userConfig.TFEToken)
|
||||
// The flag.Lookup call is to detect if we're running in a unit test. If we
|
||||
|
||||
Reference in New Issue
Block a user