Skip to content

Commit

Permalink
chore: Update server/events/working_dir Logging Configuration (runatl…
Browse files Browse the repository at this point in the history
…antis#3636)

* Update server/events/working_dir logging

* Add e2e FileWorkspace logger

* Fix github app working dir test logger

* Update working_dir_test

---------

Co-authored-by: Dylan Page <[email protected]>
  • Loading branch information
2 people authored and ijames-gc committed Feb 13, 2024
1 parent 67ea261 commit 3468a9d
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 172 deletions.
1 change: 1 addition & 0 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
workingDir := &events.FileWorkspace{
DataDir: dataDir,
TestingOverrideHeadCloneURL: "override-me",
Logger: logger,
}

defaultTFVersion := terraformClient.DefaultVersion()
Expand Down
6 changes: 3 additions & 3 deletions server/events/command_requirement_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (a *DefaultCommandRequirementHandler) ValidatePlanProject(repoDir string, c
return "Pull request must be mergeable before running plan.", nil
}
case raw.UnDivergedRequirement:
if a.WorkingDir.HasDiverged(ctx.Log, repoDir) {
if a.WorkingDir.HasDiverged(repoDir) {
return "Default branch must be rebased onto pull request before running plan.", nil
}
}
Expand All @@ -56,7 +56,7 @@ func (a *DefaultCommandRequirementHandler) ValidateApplyProject(repoDir string,
return "Pull request must be mergeable before running apply.", nil
}
case raw.UnDivergedRequirement:
if a.WorkingDir.HasDiverged(ctx.Log, repoDir) {
if a.WorkingDir.HasDiverged(repoDir) {
return "Default branch must be rebased onto pull request before running apply.", nil
}
}
Expand All @@ -77,7 +77,7 @@ func (a *DefaultCommandRequirementHandler) ValidateImportProject(repoDir string,
return "Pull request must be mergeable before running import.", nil
}
case raw.UnDivergedRequirement:
if a.WorkingDir.HasDiverged(ctx.Log, repoDir) {
if a.WorkingDir.HasDiverged(repoDir) {
return "Default branch must be rebased onto pull request before running import.", nil
}
}
Expand Down
13 changes: 6 additions & 7 deletions server/events/command_requirement_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/runatlantis/atlantis/server/core/config/valid"
"github.com/runatlantis/atlantis/server/events"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"

"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/mocks"
Expand Down Expand Up @@ -47,7 +46,7 @@ func TestAggregateApplyRequirements_ValidatePlanProject(t *testing.T) {
ProjectPlanStatus: models.PassedPolicyCheckStatus,
},
setup: func(workingDir *mocks.MockWorkingDir) {
When(workingDir.HasDiverged(Any[logging.SimpleLogging](), Any[string]())).ThenReturn(false)
When(workingDir.HasDiverged(Any[string]())).ThenReturn(false)
},
wantErr: assert.NoError,
},
Expand Down Expand Up @@ -77,7 +76,7 @@ func TestAggregateApplyRequirements_ValidatePlanProject(t *testing.T) {
PlanRequirements: []string{raw.UnDivergedRequirement},
},
setup: func(workingDir *mocks.MockWorkingDir) {
When(workingDir.HasDiverged(Any[logging.SimpleLogging](), Any[string]())).ThenReturn(true)
When(workingDir.HasDiverged(Any[string]())).ThenReturn(true)
},
wantFailure: "Default branch must be rebased onto pull request before running plan.",
wantErr: assert.NoError,
Expand Down Expand Up @@ -131,7 +130,7 @@ func TestAggregateApplyRequirements_ValidateApplyProject(t *testing.T) {
ProjectPlanStatus: models.PassedPolicyCheckStatus,
},
setup: func(workingDir *mocks.MockWorkingDir) {
When(workingDir.HasDiverged(Any[logging.SimpleLogging](), Any[string]())).ThenReturn(false)
When(workingDir.HasDiverged(Any[string]())).ThenReturn(false)
},
wantErr: assert.NoError,
},
Expand Down Expand Up @@ -185,7 +184,7 @@ func TestAggregateApplyRequirements_ValidateApplyProject(t *testing.T) {
ApplyRequirements: []string{raw.UnDivergedRequirement},
},
setup: func(workingDir *mocks.MockWorkingDir) {
When(workingDir.HasDiverged(Any[logging.SimpleLogging](), Any[string]())).ThenReturn(true)
When(workingDir.HasDiverged(Any[string]())).ThenReturn(true)
},
wantFailure: "Default branch must be rebased onto pull request before running apply.",
wantErr: assert.NoError,
Expand Down Expand Up @@ -238,7 +237,7 @@ func TestAggregateApplyRequirements_ValidateImportProject(t *testing.T) {
ProjectPlanStatus: models.PassedPolicyCheckStatus,
},
setup: func(workingDir *mocks.MockWorkingDir) {
When(workingDir.HasDiverged(Any[logging.SimpleLogging](), Any[string]())).ThenReturn(false)
When(workingDir.HasDiverged(Any[string]())).ThenReturn(false)
},
wantErr: assert.NoError,
},
Expand Down Expand Up @@ -268,7 +267,7 @@ func TestAggregateApplyRequirements_ValidateImportProject(t *testing.T) {
ImportRequirements: []string{raw.UnDivergedRequirement},
},
setup: func(workingDir *mocks.MockWorkingDir) {
When(workingDir.HasDiverged(Any[logging.SimpleLogging](), Any[string]())).ThenReturn(true)
When(workingDir.HasDiverged(Any[string]())).ThenReturn(true)
},
wantFailure: "Default branch must be rebased onto pull request before running import.",
wantErr: assert.NoError,
Expand Down
5 changes: 2 additions & 3 deletions server/events/github_app_working_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/vcs"
"github.com/runatlantis/atlantis/server/logging"
)

const redactedReplacement = "://:<redacted>@"
Expand All @@ -20,7 +19,7 @@ type GithubAppWorkingDir struct {
}

// Clone writes a fresh token for Github App authentication
func (g *GithubAppWorkingDir) Clone(log logging.SimpleLogging, headRepo models.Repo, p models.PullRequest, workspace string) (string, bool, error) {
func (g *GithubAppWorkingDir) Clone(headRepo models.Repo, p models.PullRequest, workspace string) (string, bool, error) {
baseRepo := &p.BaseRepo

// Realistically, this is a super brittle way of supporting clones using gh app installation tokens
Expand All @@ -36,5 +35,5 @@ func (g *GithubAppWorkingDir) Clone(log logging.SimpleLogging, headRepo models.R
headRepo.CloneURL = strings.Replace(headRepo.CloneURL, "://:@", replacement, 1)
headRepo.SanitizedCloneURL = strings.Replace(baseRepo.SanitizedCloneURL, redactedReplacement, replacement, 1)

return g.WorkingDir.Clone(log, headRepo, p, workspace, additionalBranches)
return g.WorkingDir.Clone(headRepo, p, workspace)
}
15 changes: 7 additions & 8 deletions server/events/github_app_working_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ func TestClone_GithubAppNoneExisting(t *testing.T) {

dataDir := t.TempDir()

logger := logging.NewNoopLogger(t)

wd := &events.FileWorkspace{
DataDir: dataDir,
CheckoutMerge: false,
TestingOverrideHeadCloneURL: fmt.Sprintf("file://%s", repoDir),
Logger: logger,
}

defer disableSSLVerification()()
Expand All @@ -44,9 +47,7 @@ func TestClone_GithubAppNoneExisting(t *testing.T) {
GithubHostname: testServer,
}

logger := logging.NewNoopLogger(t)

cloneDir, _, err := gwd.Clone(logger, models.Repo{}, models.PullRequest{
cloneDir, _, err := gwd.Clone(models.Repo{}, models.PullRequest{
BaseRepo: models.Repo{},
HeadBranch: "branch",
}, "default", []string{})
Expand Down Expand Up @@ -80,8 +81,6 @@ func TestClone_GithubAppSetsCorrectUrl(t *testing.T) {
"",
)

logger := logging.NewNoopLogger(t)

headRepo := baseRepo

modifiedBaseRepo := baseRepo
Expand All @@ -90,13 +89,13 @@ func TestClone_GithubAppSetsCorrectUrl(t *testing.T) {
modifiedBaseRepo.SanitizedCloneURL = "https://github.com/runatlantis/atlantis.git"

When(credentials.GetToken()).ThenReturn("token", nil)
When(workingDir.Clone(logger, modifiedBaseRepo, models.PullRequest{BaseRepo: modifiedBaseRepo}, "default", []string{})).ThenReturn(
When(workingDir.Clone(modifiedBaseRepo, models.PullRequest{BaseRepo: modifiedBaseRepo}, "default")).ThenReturn(
"", true, nil,
)

_, success, _ := ghAppWorkingDir.Clone(logger, headRepo, models.PullRequest{BaseRepo: baseRepo}, "default", []string{})
_, success, _ := ghAppWorkingDir.Clone(headRepo, models.PullRequest{BaseRepo: baseRepo}, "default")

workingDir.VerifyWasCalledOnce().Clone(logger, modifiedBaseRepo, models.PullRequest{BaseRepo: modifiedBaseRepo}, "default")
workingDir.VerifyWasCalledOnce().Clone(modifiedBaseRepo, models.PullRequest{BaseRepo: modifiedBaseRepo}, "default")

Assert(t, success == true, "clone url mutation error")
}
57 changes: 24 additions & 33 deletions server/events/mock_workingdir_test.go

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

Loading

0 comments on commit 3468a9d

Please sign in to comment.