Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Jul 10, 2024
1 parent c890c9c commit ba001b6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 287 deletions.
55 changes: 0 additions & 55 deletions server/legacy/events/policy_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,6 @@ func TestFilter_Approved(t *testing.T) {
assert.Empty(t, filteredPolicies)
}

func TestFilter_NotApproved(t *testing.T) {
reviewFetcher := &mockReviewFetcher{
reviews: []*github.PullRequestReview{
{
User: &github.User{Login: github.String(ownerA)},
},
{
User: &github.User{Login: github.String(ownerB)},
},
},
}
teamFetcher := &mockTeamMemberFetcher{
members: []string{ownerC},
}
reviewDismisser := &mockReviewDismisser{}
failedPolicies := []valid.PolicySet{
{Name: policyName, Owner: policyOwner},
}

policyFilter := NewApprovedPolicyFilter(reviewFetcher, reviewDismisser, teamFetcher, &testFeatureAllocator{}, failedPolicies, logging.NewNoopCtxLogger(t))
filteredPolicies, err := policyFilter.Filter(context.Background(), 0, models.Repo{}, 0, command.AutoTrigger, failedPolicies)
assert.NoError(t, err)
assert.False(t, reviewFetcher.listUsernamesIsCalled)
assert.True(t, reviewFetcher.listApprovalsIsCalled)
assert.True(t, teamFetcher.isCalled)
assert.False(t, reviewDismisser.isCalled)
assert.Equal(t, failedPolicies, filteredPolicies)
}

func TestFilter_DismissalBlockedByFeatureAllocator(t *testing.T) {
reviewFetcher := &mockReviewFetcher{
reviews: []*github.PullRequestReview{
Expand All @@ -100,32 +71,6 @@ func TestFilter_DismissalBlockedByFeatureAllocator(t *testing.T) {
assert.Equal(t, failedPolicies, filteredPolicies)
}

func TestFilter_NotApproved_Dismissal(t *testing.T) {
reviewFetcher := &mockReviewFetcher{
reviews: []*github.PullRequestReview{
{
User: &github.User{Login: github.String(ownerA)},
},
},
}
teamFetcher := &mockTeamMemberFetcher{
members: []string{ownerA},
}
reviewDismisser := &mockReviewDismisser{}
failedPolicies := []valid.PolicySet{
{Name: policyName, Owner: policyOwner},
}

policyFilter := NewApprovedPolicyFilter(reviewFetcher, reviewDismisser, teamFetcher, &testFeatureAllocator{}, failedPolicies, logging.NewNoopCtxLogger(t))
filteredPolicies, err := policyFilter.Filter(context.Background(), 0, models.Repo{}, 0, command.AutoTrigger, failedPolicies)
assert.NoError(t, err)
assert.False(t, reviewFetcher.listUsernamesIsCalled)
assert.True(t, reviewFetcher.listApprovalsIsCalled)
assert.True(t, teamFetcher.isCalled)
assert.True(t, reviewDismisser.isCalled)
assert.Equal(t, failedPolicies, filteredPolicies)
}

func TestFilter_NoFailedPolicies(t *testing.T) {
reviewFetcher := &mockReviewFetcher{
approvers: []string{ownerB},
Expand Down
232 changes: 0 additions & 232 deletions server/legacy/lyft/command/feature_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,61 +231,6 @@ func TestPlatformModeRunner_allocatesButPartialPlatformMode(t *testing.T) {
assert.False(t, commenter.called)
}

func TestPlatformModeRunner_doesntAllocate(t *testing.T) {
ctx := &command.Context{
RequestCtx: context.Background(),
HeadRepo: models.Repo{
FullName: "owner/repo",
},
Pull: models.PullRequest{
Num: 1,
BaseRepo: models.Repo{
FullName: "owner/base",
},
},
}
cmd := &command.Comment{
Workspace: "hi",
}

commenter := &TestCommenter{
expectedT: t,
expectedComment: "Platform mode does not support legacy apply commands. Please merge your PR to apply the changes. ",
expectedPullNum: 1,
expectedRepo: ctx.Pull.BaseRepo,
}

builder := &TestBuilder{
Type: valid.PlatformWorkflowMode,
}
runner := &testCMDRunner{
t: t,
expectedCmd: cmd,
}

subject := &lyftCommand.PlatformModeRunner{
Allocator: &testAllocator{
expectedFeatureName: feature.PlatformMode,
expectedT: t,
expectedCtx: feature.FeatureContext{RepoName: "owner/repo"},
expectedResult: false,
},
Logger: logging.NewNoopCtxLogger(t),
Builder: builder,
TemplateLoader: template.Loader[lyftCommand.LegacyApplyCommentInput]{
GlobalCfg: valid.GlobalCfg{},
},
VCSClient: commenter,
Runner: runner,
}

subject.Run(ctx, cmd)

assert.True(t, runner.called)
assert.False(t, builder.called)
assert.False(t, commenter.called)
}

func TestPlatformModeRunner_success(t *testing.T) {
ctx := &command.Context{
RequestCtx: context.Background(),
Expand Down Expand Up @@ -367,15 +312,6 @@ func TestPlatformModeProjectRunner_plan(t *testing.T) {
expectedPlanResult: expectedResult,
},
},
{
description: "not allocated and platform mode enabled",
shouldAllocate: false,
workflowModeType: valid.PlatformWorkflowMode,
platformRunner: &testRunner{},
prModeRunner: &testRunner{
expectedPlanResult: expectedResult,
},
},
}

for _, c := range cases {
Expand Down Expand Up @@ -477,171 +413,3 @@ func TestPlatformModeProjectRunner_policyCheck(t *testing.T) {
})
}
}

func TestPlatformModeProjectRunner_apply(t *testing.T) {
cases := []struct {
description string
shouldAllocate bool
workflowModeType valid.WorkflowModeType
platformRunner events.ProjectCommandRunner
prModeRunner events.ProjectCommandRunner
subject lyftCommand.PlatformModeProjectRunner
expectedResult command.ProjectResult
}{
{
description: "allocated and platform mode enabled",
shouldAllocate: true,
workflowModeType: valid.PlatformWorkflowMode,
platformRunner: &testRunner{
expectedApplyResult: command.ProjectResult{
RepoRelDir: "reldir",
Workspace: "default",
ProjectName: "project",
StatusID: "id",
Command: command.Apply,
ApplySuccess: "atlantis apply is disabled for this project. Please track the deployment when the PR is merged. ",
},
},
expectedResult: command.ProjectResult{
RepoRelDir: "reldir",
Workspace: "default",
ProjectName: "project",
StatusID: "id",
Command: command.Apply,
ApplySuccess: "atlantis apply is disabled for this project. Please track the deployment when the PR is merged. ",
},
prModeRunner: &testRunner{},
},
{
description: "allocated and platform mode not enabled",
shouldAllocate: true,
workflowModeType: valid.DefaultWorkflowMode,
platformRunner: &testRunner{},
prModeRunner: &testRunner{
expectedApplyResult: command.ProjectResult{
JobID: "1234y",
},
},
expectedResult: command.ProjectResult{
JobID: "1234y",
},
},
{
description: "not allocated and platform mode enabled",
shouldAllocate: false,
workflowModeType: valid.PlatformWorkflowMode,
platformRunner: &testRunner{},
prModeRunner: &testRunner{
expectedApplyResult: command.ProjectResult{
JobID: "1234y",
},
},
expectedResult: command.ProjectResult{
JobID: "1234y",
},
},
}

for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
subject := lyftCommand.PlatformModeProjectRunner{
PlatformModeRunner: c.platformRunner,
PrModeRunner: c.prModeRunner,
Allocator: &testAllocator{
expectedResult: c.shouldAllocate,
expectedFeatureName: feature.PlatformMode,
expectedCtx: feature.FeatureContext{
RepoName: "nish/repo",
},
expectedT: t,
},
Logger: logging.NewNoopCtxLogger(t),
}

result := subject.Apply(command.ProjectContext{
RequestCtx: context.Background(),
HeadRepo: models.Repo{
FullName: "nish/repo",
},
RepoRelDir: "reldir",
Workspace: "default",
ProjectName: "project",
StatusID: "id",
WorkflowModeType: c.workflowModeType,
})

assert.Equal(t, c.expectedResult, result)
})
}
}

func TestPlatformModeProjectRunner_version(t *testing.T) {
expectedResult := command.ProjectResult{
JobID: "1234y",
}

cases := []struct {
description string
shouldAllocate bool
workflowModeType valid.WorkflowModeType
platformRunner events.ProjectCommandRunner
prModeRunner events.ProjectCommandRunner
subject lyftCommand.PlatformModeProjectRunner
}{
{
description: "allocated and platform mode enabled",
shouldAllocate: true,
workflowModeType: valid.PlatformWorkflowMode,
platformRunner: &testRunner{
expectedVersionResult: expectedResult,
},
prModeRunner: &testRunner{},
},
{
description: "allocated and platform mode not enabled",
shouldAllocate: true,
workflowModeType: valid.DefaultWorkflowMode,
platformRunner: &testRunner{},
prModeRunner: &testRunner{
expectedVersionResult: expectedResult,
},
},
{
description: "not allocated and platform mode enabled",
shouldAllocate: false,
workflowModeType: valid.PlatformWorkflowMode,
platformRunner: &testRunner{},
prModeRunner: &testRunner{
expectedVersionResult: expectedResult,
},
},
}

for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
subject := lyftCommand.PlatformModeProjectRunner{
PlatformModeRunner: c.platformRunner,
PrModeRunner: c.prModeRunner,
Allocator: &testAllocator{
expectedResult: c.shouldAllocate,
expectedFeatureName: feature.PlatformMode,
expectedCtx: feature.FeatureContext{
RepoName: "nish/repo",
},
expectedT: t,
},
Logger: logging.NewNoopCtxLogger(t),
}

result := subject.Version(command.ProjectContext{
RequestCtx: context.Background(),
HeadRepo: models.Repo{
FullName: "nish/repo",
},
WorkflowModeType: c.workflowModeType,
})

assert.Equal(t, expectedResult, result)
})
}
}

0 comments on commit ba001b6

Please sign in to comment.