Skip to content

Commit

Permalink
[DEVCON-7138] remove old workflow mode that is not platform (pr) (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero authored Jul 23, 2024
1 parent 3aaf0d7 commit 31f1f02
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 138 deletions.
2 changes: 1 addition & 1 deletion server/config/raw/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (p Project) ToValid(defaultWorkflowModeType valid.WorkflowModeType) valid.P
v.DeploymentWorkflowName = p.DeploymentWorkflowName
v.WorkflowModeType = defaultWorkflowModeType
if p.WorkflowModeType != nil {
v.WorkflowModeType = toWorkflowModeType(*p.WorkflowModeType)
v.WorkflowModeType = valid.PlatformWorkflowMode
}
if p.TerraformVersion != nil {
v.TerraformVersion, _ = version.NewVersion(*p.TerraformVersion)
Expand Down
22 changes: 11 additions & 11 deletions server/config/raw/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestProject_ToValid(t *testing.T) {
},
ApplyRequirements: nil,
Name: nil,
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
{
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
// Directories.
Expand All @@ -330,7 +330,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
{
Expand All @@ -345,7 +345,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
{
Expand All @@ -360,7 +360,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
{
Expand All @@ -376,7 +376,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
{
Expand All @@ -391,7 +391,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
{
Expand All @@ -406,7 +406,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
{
Expand All @@ -421,7 +421,7 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},

Expand All @@ -438,13 +438,13 @@ func TestProject_ToValid(t *testing.T) {
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
WorkflowModeType: valid.DefaultWorkflowMode,
WorkflowModeType: valid.PlatformWorkflowMode,
},
},
}
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
Equals(t, c.exp, c.input.ToValid(valid.DefaultWorkflowMode))
Equals(t, c.exp, c.input.ToValid(valid.PlatformWorkflowMode))
})
}
}
13 changes: 2 additions & 11 deletions server/config/raw/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (r RepoCfg) Validate() error {
return validation.ValidateStruct(&r,
validation.Field(&r.Version, validation.By(equals2)),
validation.Field(&r.Projects),
validation.Field(&r.WorkflowModeType, validation.In("pr", "platform")),
validation.Field(&r.WorkflowModeType, validation.In("platform")),
)
}

func (r RepoCfg) ToValid() valid.RepoCfg {
workflowModeType := toWorkflowModeType(r.WorkflowModeType)
workflowModeType := valid.PlatformWorkflowMode

var validProjects []valid.Project
for _, p := range r.Projects {
Expand All @@ -71,12 +71,3 @@ func (r RepoCfg) ToValid() valid.RepoCfg {
ParallelPolicyCheck: parallelPlan,
}
}

func toWorkflowModeType(workflowModeType string) valid.WorkflowModeType {
result := valid.PlatformWorkflowMode
switch workflowModeType {
case "pr":
result = valid.DefaultWorkflowMode
}
return result
}
1 change: 0 additions & 1 deletion server/config/valid/global_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type WorkflowModeType int

const (
PlatformWorkflowMode WorkflowModeType = iota
DefaultWorkflowMode
)

type BackendType string
Expand Down
10 changes: 0 additions & 10 deletions server/legacy/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,6 @@ legacy-deprecation:
{"exp-output-auto-policy-check.txt"},
},
},
{
Description: "failing policy without policies passing",
RepoDir: "policy-checks",
ModifiedFiles: []string{"main.tf"},
ExpReplies: [][]string{
{"exp-output-autoplan.txt"},
{"exp-output-auto-policy-check.txt"},
{"exp-output-auto-policy-check.txt"},
},
},
{
Description: "failing policy additional apply requirements specified",
RepoDir: "policy-checks-apply-reqs",
Expand Down
82 changes: 0 additions & 82 deletions server/legacy/events/project_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,36 +427,6 @@ func TestDefaultProjectCommandRunner_ApplyNotCloned(t *testing.T) {
ErrEquals(t, "project has not been cloned–did you run plan?", firstRes.Error)
}

// Test that if approval is required and the PR isn't approved we give an error.
func TestDefaultProjectCommandRunner_ApplyNotApproved(t *testing.T) {
RegisterMockTestingT(t)
mockWorkingDir := mocks.NewMockWorkingDir()
mockSender := mocks.NewMockWebhooksSender()
runner := &events.DefaultProjectCommandRunner{
WorkingDir: mockWorkingDir,
WorkingDirLocker: events.NewDefaultWorkingDirLocker(),
AggregateApplyRequirements: &events.AggregateApplyRequirements{
WorkingDir: mockWorkingDir,
},
Webhooks: mockSender,
}
prjCtx := command.ProjectContext{
ApplyRequirements: []string{"approved"},
PullReqStatus: models.PullReqStatus{
ApprovalStatus: models.ApprovalStatus{
IsApproved: false,
},
},
WorkflowModeType: valid.DefaultWorkflowMode,
}
tmp, cleanup := TempDir(t)
defer cleanup()
When(mockWorkingDir.GetWorkingDir(prjCtx.BaseRepo, prjCtx.Pull, prjCtx.Workspace)).ThenReturn(tmp, nil)

firstRes := runner.Apply(prjCtx)
Equals(t, "Pull request must be approved by at least one person other than the author before running apply.", firstRes.Failure)
}

func TestDefaultProjectCommandRunner_ForceOverridesApplyReqs_IfPlatformMode(t *testing.T) {
RegisterMockTestingT(t)
mockWorkingDir := mocks.NewMockWorkingDir()
Expand Down Expand Up @@ -517,58 +487,6 @@ func TestDefaultProjectCommandRunner_ForceOverridesApplyReqs(t *testing.T) {
Equals(t, "", firstRes.Failure)
}

// Test that if mergeable is required and the PR isn't mergeable we give an error.
func TestDefaultProjectCommandRunner_ApplyNotMergeable(t *testing.T) {
RegisterMockTestingT(t)
mockWorkingDir := mocks.NewMockWorkingDir()
runner := &events.DefaultProjectCommandRunner{
WorkingDir: mockWorkingDir,
WorkingDirLocker: events.NewDefaultWorkingDirLocker(),
StepsRunner: smocks.NewMockStepsRunner(),
AggregateApplyRequirements: &events.AggregateApplyRequirements{
WorkingDir: mockWorkingDir,
},
}
prjCtx := command.ProjectContext{
PullReqStatus: models.PullReqStatus{
Mergeable: false,
},
ApplyRequirements: []string{"mergeable"},
WorkflowModeType: valid.DefaultWorkflowMode,
}
tmp, cleanup := TempDir(t)
defer cleanup()
When(mockWorkingDir.GetWorkingDir(prjCtx.BaseRepo, prjCtx.Pull, prjCtx.Workspace)).ThenReturn(tmp, nil)

firstRes := runner.Apply(prjCtx)
Equals(t, "Pull request must be mergeable before running apply.", firstRes.Failure)
}

// Test that if undiverged is required and the PR is diverged we give an error.
func TestDefaultProjectCommandRunner_ApplyDiverged(t *testing.T) {
RegisterMockTestingT(t)
mockWorkingDir := mocks.NewMockWorkingDir()
runner := &events.DefaultProjectCommandRunner{
WorkingDir: mockWorkingDir,
WorkingDirLocker: events.NewDefaultWorkingDirLocker(),
StepsRunner: smocks.NewMockStepsRunner(),
AggregateApplyRequirements: &events.AggregateApplyRequirements{
WorkingDir: mockWorkingDir,
},
}
prjCtx := command.ProjectContext{
ApplyRequirements: []string{"undiverged"},
WorkflowModeType: valid.DefaultWorkflowMode,
}
tmp, cleanup := TempDir(t)
defer cleanup()
When(mockWorkingDir.GetWorkingDir(prjCtx.BaseRepo, prjCtx.Pull, prjCtx.Workspace)).ThenReturn(tmp, nil)
When(mockWorkingDir.HasDiverged(matchers.AnyLoggingLogger(), AnyString(), matchers.AnyModelsRepo())).ThenReturn(true)

firstRes := runner.Apply(prjCtx)
Equals(t, "Default branch must be rebased onto pull request before running apply.", firstRes.Failure)
}

// Test that it runs the expected apply steps.
func TestDefaultProjectCommandRunner_Apply(t *testing.T) {
cases := []struct {
Expand Down
23 changes: 1 addition & 22 deletions server/legacy/lyft/command/feature_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ func (b *TestMultiBuilder) BuildApplyCommands(ctx *command.Context, comment *com
{
WorkflowModeType: valid.PlatformWorkflowMode,
},
{
WorkflowModeType: valid.DefaultWorkflowMode,
},
}, nil
}

Expand Down Expand Up @@ -148,7 +145,7 @@ func TestPlatformModeRunner_allocatesButNotPlatformMode(t *testing.T) {
}

builder := &TestBuilder{
Type: valid.DefaultWorkflowMode,
Type: valid.PlatformWorkflowMode,
}
runner := &testCMDRunner{
t: t,
Expand Down Expand Up @@ -303,15 +300,6 @@ func TestPlatformModeProjectRunner_plan(t *testing.T) {
},
prModeRunner: &testRunner{},
},
{
description: "allocated and platform mode not enabled",
shouldAllocate: true,
workflowModeType: valid.DefaultWorkflowMode,
platformRunner: &testRunner{},
prModeRunner: &testRunner{
expectedPlanResult: expectedResult,
},
},
}

for _, c := range cases {
Expand Down Expand Up @@ -365,15 +353,6 @@ func TestPlatformModeProjectRunner_policyCheck(t *testing.T) {
},
prModeRunner: &testRunner{},
},
{
description: "allocated and platform mode not enabled",
shouldAllocate: true,
workflowModeType: valid.DefaultWorkflowMode,
platformRunner: &testRunner{},
prModeRunner: &testRunner{
expectedPolicyCheckResult: expectedResult,
},
},
}

for _, c := range cases {
Expand Down

0 comments on commit 31f1f02

Please sign in to comment.