Skip to content

Commit

Permalink
chore(build): rm pegomock experimental feature for smooth mock genera…
Browse files Browse the repository at this point in the history
…tion (runatlantis#2886)

* disable pegomock --use-experimental-model-gen, cause random fail by segv

* make regen-mocks

* fix mock code which uses non experimental pegomock codes
  • Loading branch information
krrrr38 authored Dec 28, 2022
1 parent de953fe commit 27b9897
Show file tree
Hide file tree
Showing 206 changed files with 2,643 additions and 3,778 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Then you've likely modified an interface and now need to update the mocks.
Each interface that is mocked has a `go:generate` command above it, e.g.
```go
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder
//go:generate pegomock generate -m --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder
type ProjectCommandBuilder interface {
BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error)
Expand Down
18 changes: 9 additions & 9 deletions server/controllers/api_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func TestAPIController_Plan(t *testing.T) {
w := httptest.NewRecorder()
ac.Plan(w, req)
ResponseContains(t, w, http.StatusOK, "")
projectCommandBuilder.VerifyWasCalledOnce().BuildPlanCommands(AnyPtrToEventsCommandContext(), AnyPtrToEventsCommentCommand())
projectCommandRunner.VerifyWasCalledOnce().Plan(AnyModelsProjectCommandContext())
projectCommandBuilder.VerifyWasCalledOnce().BuildPlanCommands(AnyPtrToCommandContext(), AnyPtrToEventsCommentCommand())
projectCommandRunner.VerifyWasCalledOnce().Plan(AnyCommandProjectContext())
}

func TestAPIController_Apply(t *testing.T) {
Expand All @@ -54,9 +54,9 @@ func TestAPIController_Apply(t *testing.T) {
w := httptest.NewRecorder()
ac.Apply(w, req)
ResponseContains(t, w, http.StatusOK, "")
projectCommandBuilder.VerifyWasCalledOnce().BuildApplyCommands(AnyPtrToEventsCommandContext(), AnyPtrToEventsCommentCommand())
projectCommandRunner.VerifyWasCalledOnce().Plan(AnyModelsProjectCommandContext())
projectCommandRunner.VerifyWasCalledOnce().Apply(AnyModelsProjectCommandContext())
projectCommandBuilder.VerifyWasCalledOnce().BuildApplyCommands(AnyPtrToCommandContext(), AnyPtrToEventsCommentCommand())
projectCommandRunner.VerifyWasCalledOnce().Plan(AnyCommandProjectContext())
projectCommandRunner.VerifyWasCalledOnce().Apply(AnyCommandProjectContext())
}

func setup(t *testing.T) (controllers.APIController, *MockProjectCommandBuilder, *MockProjectCommandRunner) {
Expand All @@ -70,20 +70,20 @@ func setup(t *testing.T) (controllers.APIController, *MockProjectCommandBuilder,
Ok(t, err)

projectCommandBuilder := NewMockProjectCommandBuilder()
When(projectCommandBuilder.BuildPlanCommands(AnyPtrToEventsCommandContext(), AnyPtrToEventsCommentCommand())).
When(projectCommandBuilder.BuildPlanCommands(AnyPtrToCommandContext(), AnyPtrToEventsCommentCommand())).
ThenReturn([]command.ProjectContext{{
CommandName: command.Plan,
}}, nil)
When(projectCommandBuilder.BuildApplyCommands(AnyPtrToEventsCommandContext(), AnyPtrToEventsCommentCommand())).
When(projectCommandBuilder.BuildApplyCommands(AnyPtrToCommandContext(), AnyPtrToEventsCommentCommand())).
ThenReturn([]command.ProjectContext{{
CommandName: command.Apply,
}}, nil)

projectCommandRunner := NewMockProjectCommandRunner()
When(projectCommandRunner.Plan(AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{
When(projectCommandRunner.Plan(AnyCommandProjectContext())).ThenReturn(command.ProjectResult{
PlanSuccess: &models.PlanSuccess{},
})
When(projectCommandRunner.Apply(AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{
When(projectCommandRunner.Apply(AnyCommandProjectContext())).ThenReturn(command.ProjectResult{
ApplySuccess: "success",
})

Expand Down
2 changes: 1 addition & 1 deletion server/controllers/events/azuredevops_request_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/mcdafydd/go-azuredevops/azuredevops"
)

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_azuredevops_request_validator.go AzureDevopsRequestValidator
//go:generate pegomock generate -m --package mocks -o mocks/mock_azuredevops_request_validator.go AzureDevopsRequestValidator

// AzureDevopsRequestValidator handles checking if Azure DevOps requests
// contain a valid Basic authentication username and password.
Expand Down
9 changes: 5 additions & 4 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/vcs"
vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks"
vcsmatchers "github.com/runatlantis/atlantis/server/events/vcs/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/webhooks"
jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks"
"github.com/runatlantis/atlantis/server/logging"
Expand Down Expand Up @@ -534,9 +535,9 @@ func TestGitHubWorkflow(t *testing.T) {

if c.ExpAutomerge {
// Verify that the merge API call was made.
vcsClient.VerifyWasCalledOnce().MergePull(matchers.AnyModelsPullRequest(), matchers.AnyModelsPullRequestOptions())
vcsClient.VerifyWasCalledOnce().MergePull(matchers.AnyModelsPullRequest(), vcsmatchers.AnyModelsPullRequestOptions())
} else {
vcsClient.VerifyWasCalled(Never()).MergePull(matchers.AnyModelsPullRequest(), matchers.AnyModelsPullRequestOptions())
vcsClient.VerifyWasCalled(Never()).MergePull(matchers.AnyModelsPullRequest(), vcsmatchers.AnyModelsPullRequestOptions())
}
})
}
Expand Down Expand Up @@ -932,9 +933,9 @@ func TestGitHubWorkflowWithPolicyCheck(t *testing.T) {

if c.ExpAutomerge {
// Verify that the merge API call was made.
vcsClient.VerifyWasCalledOnce().MergePull(matchers.AnyModelsPullRequest(), matchers.AnyModelsPullRequestOptions())
vcsClient.VerifyWasCalledOnce().MergePull(matchers.AnyModelsPullRequest(), vcsmatchers.AnyModelsPullRequestOptions())
} else {
vcsClient.VerifyWasCalled(Never()).MergePull(matchers.AnyModelsPullRequest(), matchers.AnyModelsPullRequestOptions())
vcsClient.VerifyWasCalled(Never()).MergePull(matchers.AnyModelsPullRequest(), vcsmatchers.AnyModelsPullRequestOptions())
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/events/github_request_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/google/go-github/v48/github"
)

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_github_request_validator.go GithubRequestValidator
//go:generate pegomock generate -m --package mocks -o mocks/mock_github_request_validator.go GithubRequestValidator

// GithubRequestValidator handles checking if GitHub requests are signed
// properly by the secret.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const secretHeader = "X-Gitlab-Token" // #nosec

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_gitlab_request_parser_validator.go GitlabRequestParserValidator
//go:generate pegomock generate -m --package mocks -o mocks/mock_gitlab_request_parser_validator.go GitlabRequestParserValidator

// GitlabRequestParserValidator parses and validates GitLab requests.
type GitlabRequestParserValidator interface {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions server/controllers/events/mocks/matchers/slice_of_byte.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions server/controllers/events/mocks/mock_github_request_validator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions server/controllers/templates/mocks/matchers/io_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions server/controllers/templates/mocks/mock_template_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/controllers/templates/web_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"time"
)

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_template_writer.go TemplateWriter
//go:generate pegomock generate -m --package mocks -o mocks/mock_template_writer.go TemplateWriter

// TemplateWriter is an interface over html/template that's used to enable
// mocking.
Expand Down
4 changes: 2 additions & 2 deletions server/core/locking/apply_locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/runatlantis/atlantis/server/events/command"
)

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_apply_lock_checker.go ApplyLockChecker
//go:generate pegomock generate -m --package mocks -o mocks/mock_apply_lock_checker.go ApplyLockChecker

// ApplyLockChecker is an implementation of the global apply lock retrieval.
// It returns an object that contains information about apply locks status.
type ApplyLockChecker interface {
CheckApplyLock() (ApplyCommandLock, error)
}

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_apply_locker.go ApplyLocker
//go:generate pegomock generate -m --package mocks -o mocks/mock_apply_locker.go ApplyLocker

// ApplyLocker interface that manages locks for apply command runner
type ApplyLocker interface {
Expand Down
4 changes: 2 additions & 2 deletions server/core/locking/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/runatlantis/atlantis/server/events/models"
)

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_backend.go Backend
//go:generate pegomock generate -m --package mocks -o mocks/mock_backend.go Backend

// Backend is an implementation of the locking API we require.
type Backend interface {
Expand Down Expand Up @@ -60,7 +60,7 @@ type Client struct {
backend Backend
}

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_locker.go Locker
//go:generate pegomock generate -m --package mocks -o mocks/mock_locker.go Locker

type Locker interface {
TryLock(p models.Project, workspace string, pull models.PullRequest, user models.User) (TryLockResponse, error)
Expand Down
Loading

0 comments on commit 27b9897

Please sign in to comment.