Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor log handler #175

Merged
merged 4 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
lyft_vcs "github.com/runatlantis/atlantis/server/events/vcs/lyft"
vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks"
"github.com/runatlantis/atlantis/server/events/webhooks"
handlermocks "github.com/runatlantis/atlantis/server/handlers/mocks"
jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/lyft/feature"
"github.com/runatlantis/atlantis/server/metrics"
Expand Down Expand Up @@ -828,7 +828,7 @@ func setupE2E(t *testing.T, repoDir string) (events_controllers.VCSEventsControl
e2eStatusUpdater := &events.DefaultCommitStatusUpdater{Client: e2eVCSClient, TitleBuilder: vcs.StatusTitleBuilder{TitlePrefix: "atlantis"}}
e2eGithubGetter := mocks.NewMockGithubPullGetter()
e2eGitlabGetter := mocks.NewMockGitlabMergeRequestGetter()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()

// Real dependencies.
logger := logging.NewNoopLogger(t)
Expand Down
4 changes: 2 additions & 2 deletions server/core/terraform/async_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/hashicorp/go-version"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/handlers"
"github.com/runatlantis/atlantis/server/jobs"
)

// Setting the buffer size to 10mb
const BufioScannerBufferSize = 10 * 1024 * 1024

type AsyncClient struct {
projectCmdOutputHandler handlers.ProjectCommandOutputHandler
projectCmdOutputHandler jobs.ProjectCommandOutputHandler
commandBuilder commandBuilder
}

Expand Down
17 changes: 9 additions & 8 deletions server/core/terraform/async_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
. "github.com/petergtz/pegomock"
"github.com/runatlantis/atlantis/server/core/terraform/mocks"
"github.com/runatlantis/atlantis/server/events/models"
handlermocks "github.com/runatlantis/atlantis/server/handlers/mocks"
jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks"

"github.com/runatlantis/atlantis/server/logging"
. "github.com/runatlantis/atlantis/testing"
)
Expand All @@ -30,7 +31,7 @@ func TestDefaultClient_RunCommandAsync_Success(t *testing.T) {
}

mockBuilder := mocks.NewMockcommandBuilder()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
client := &AsyncClient{
projectCmdOutputHandler: projectCmdOutputHandler,
commandBuilder: mockBuilder,
Expand All @@ -57,7 +58,7 @@ func TestDefaultClient_RunCommandAsync_BigOutput(t *testing.T) {
Log: logger,
}
mockBuilder := mocks.NewMockcommandBuilder()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
client := &AsyncClient{
projectCmdOutputHandler: projectCmdOutputHandler,
commandBuilder: mockBuilder,
Expand Down Expand Up @@ -104,7 +105,7 @@ func TestDefaultClient_RunCommandAsync_StderrOutput(t *testing.T) {
Log: logger,
}
mockBuilder := mocks.NewMockcommandBuilder()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
client := &AsyncClient{
projectCmdOutputHandler: projectCmdOutputHandler,
commandBuilder: mockBuilder,
Expand All @@ -127,10 +128,10 @@ func TestDefaultClient_RunCommandAsync_ExitOne(t *testing.T) {
logger := logging.NewNoopLogger(t)

ctx := models.ProjectCommandContext{
Log: logger,
Log: logger,
}
mockBuilder := mocks.NewMockcommandBuilder()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
client := &AsyncClient{
projectCmdOutputHandler: projectCmdOutputHandler,
commandBuilder: mockBuilder,
Expand All @@ -154,10 +155,10 @@ func TestDefaultClient_RunCommandAsync_Input(t *testing.T) {
logger := logging.NewNoopLogger(t)

ctx := models.ProjectCommandContext{
Log: logger,
Log: logger,
}
mockBuilder := mocks.NewMockcommandBuilder()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
client := &AsyncClient{
projectCmdOutputHandler: projectCmdOutputHandler,
commandBuilder: mockBuilder,
Expand Down
10 changes: 4 additions & 6 deletions server/core/terraform/terraform_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/runatlantis/atlantis/server/core/terraform/cloud"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/terraform/ansi"
"github.com/runatlantis/atlantis/server/handlers"
"github.com/runatlantis/atlantis/server/jobs"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/lyft/feature"
)
Expand Down Expand Up @@ -95,7 +95,7 @@ func NewClientWithVersionCache(
tfDownloadURL string,
tfDownloader Downloader,
usePluginCache bool,
projectCmdOutputHandler handlers.ProjectCommandOutputHandler,
projectCmdOutputHandler jobs.ProjectCommandOutputHandler,
featureAllocator feature.Allocator,
versionCache cache.ExecutionVersionCache,
) (*DefaultClient, error) {
Expand Down Expand Up @@ -160,7 +160,7 @@ func NewE2ETestClient(
tfDownloadURL string,
tfDownloader Downloader,
usePluginCache bool,
projectCmdOutputHandler handlers.ProjectCommandOutputHandler,
projectCmdOutputHandler jobs.ProjectCommandOutputHandler,
featureAllocator feature.Allocator,
) (*DefaultClient, error) {
versionCache := cache.NewLocalBinaryCache("terraform")
Expand All @@ -181,8 +181,6 @@ func NewE2ETestClient(
)
}



func NewClient(
log logging.SimpleLogging,
binDir string,
Expand All @@ -194,7 +192,7 @@ func NewClient(
tfDownloadURL string,
tfDownloader Downloader,
usePluginCache bool,
projectCmdOutputHandler handlers.ProjectCommandOutputHandler,
projectCmdOutputHandler jobs.ProjectCommandOutputHandler,
featureAllocator feature.Allocator,
) (*DefaultClient, error) {
loader := VersionLoader{
Expand Down
8 changes: 4 additions & 4 deletions server/core/terraform/terraform_client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
. "github.com/petergtz/pegomock"
"github.com/runatlantis/atlantis/server/core/terraform/mocks"
"github.com/runatlantis/atlantis/server/events/models"
handlermocks "github.com/runatlantis/atlantis/server/handlers/mocks"
jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/lyft/feature"
fmocks "github.com/runatlantis/atlantis/server/lyft/feature/mocks"
Expand All @@ -37,7 +37,7 @@ func TestDefaultClient_Synchronous_RunCommandWithVersion(t *testing.T) {
},
}
mockBuilder := mocks.NewMockcommandBuilder()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
asyncClient := &AsyncClient{
projectCmdOutputHandler: projectCmdOutputHandler,
commandBuilder: mockBuilder,
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestVersionLoader_buildsURL(t *testing.T) {
mockDownloader := mocks.NewMockDownloader()

subject := VersionLoader{
downloader: mockDownloader,
downloader: mockDownloader,
downloadURL: "https://releases.hashicorp.com",
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func TestDefaultClient_Synchronous_RunCommandWithVersion_Error(t *testing.T) {
},
}
mockBuilder := mocks.NewMockcommandBuilder()
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
asyncClient := &AsyncClient{
projectCmdOutputHandler: projectCmdOutputHandler,
commandBuilder: mockBuilder,
Expand Down
10 changes: 5 additions & 5 deletions server/core/terraform/terraform_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/runatlantis/atlantis/cmd"
"github.com/runatlantis/atlantis/server/core/terraform"
"github.com/runatlantis/atlantis/server/events/models"
handlermocks "github.com/runatlantis/atlantis/server/handlers/mocks"
jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/lyft/feature"
fmocks "github.com/runatlantis/atlantis/server/lyft/feature/mocks"
Expand All @@ -36,7 +36,7 @@ import (
func TestNewClient_NoTF(t *testing.T) {
logger := logging.NewNoopLogger(t)
tmp, binDir, cacheDir, cleanup := mkSubDirs(t)
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
defer cleanup()

// Set PATH to only include our empty directory.
Expand All @@ -55,7 +55,7 @@ func TestNewClient_DefaultTFFlagInPath(t *testing.T) {
fakeBinOut := "Terraform v0.11.10\n"
logger := logging.NewNoopLogger(t)
tmp, binDir, cacheDir, cleanup := mkSubDirs(t)
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
ctx := models.ProjectCommandContext{
Log: logging.NewNoopLogger(t),
Workspace: "default",
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestNewClient_DefaultTFFlagInPath(t *testing.T) {
func TestNewClient_DefaultTFFlagInBinDir(t *testing.T) {
fakeBinOut := "Terraform v0.11.10\n"
tmp, binDir, cacheDir, cleanup := mkSubDirs(t)
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
ctx := models.ProjectCommandContext{
Log: logging.NewNoopLogger(t),
Workspace: "default",
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestNewClient_DefaultTFFlagInBinDir(t *testing.T) {
func TestNewClient_BadVersion(t *testing.T) {
logger := logging.NewNoopLogger(t)
_, binDir, cacheDir, cleanup := mkSubDirs(t)
projectCmdOutputHandler := handlermocks.NewMockProjectCommandOutputHandler()
projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler()
defer cleanup()
allocator := fmocks.NewMockAllocator()

Expand Down
33 changes: 33 additions & 0 deletions server/events/mocks/matchers/jobs_pullinfo.go

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

106 changes: 106 additions & 0 deletions server/events/mocks/mock_job_message_sender.go

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

Loading