Skip to content
Merged
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
15 changes: 8 additions & 7 deletions server/events/instrumented_project_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ func NewInstrumentedProjectCommandRunner(scope tally.Scope, projectCommandRunner
}

func (p *InstrumentedProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult {
return RunAndEmitStats("plan", ctx, p.projectCommandRunner.Plan, p.scope)
return RunAndEmitStats(ctx, p.projectCommandRunner.Plan, p.scope)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance of adding a unit or e2e test here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see this comment, let me check

Copy link
Copy Markdown
Contributor Author

@albertorm95 albertorm95 May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to develop the test 🥺, is there a boilerplate or something I can use as guide, should I just look at other tests?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now @albertorm95 , please look to other tests for examples.

https://github.com/runatlantis/atlantis/blob/23443a9262c3817d01f397636d4387ba4e392b41/server/events/import_command_runner_test.go

Then we can create server/events/instrumented_project_command_runner_test.go and then write a test that will test the output of the RunAndEmitStats function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitrocode I try to develop the code, but it looks like there is a lot of work to do in order to make that NewInstrumentedProjectCommandRunner or RunAndEmitStats testable, looks like I need to develop a mock? and then add it to the events.NewPlanCommandRunner() and same for apply, etc.., I don't feel confident enough to do this

The latest release is already failing because of this. What do you suggest to do in this case?

Copy link
Copy Markdown
Member

@nitrocode nitrocode May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to merge based on the above comments regarding testing and how you tested end to end.

cc: @GenPage @jamengual thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

}

func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult {
return RunAndEmitStats("policy check", ctx, p.projectCommandRunner.PolicyCheck, p.scope)
return RunAndEmitStats(ctx, p.projectCommandRunner.PolicyCheck, p.scope)
Comment thread
nitrocode marked this conversation as resolved.
}

func (p *InstrumentedProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult {
return RunAndEmitStats("apply", ctx, p.projectCommandRunner.Apply, p.scope)
return RunAndEmitStats(ctx, p.projectCommandRunner.Apply, p.scope)
}

func (p *InstrumentedProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectResult {
return RunAndEmitStats("approve policies", ctx, p.projectCommandRunner.ApprovePolicies, p.scope)
return RunAndEmitStats(ctx, p.projectCommandRunner.ApprovePolicies, p.scope)
}

func (p *InstrumentedProjectCommandRunner) Import(ctx command.ProjectContext) command.ProjectResult {
return RunAndEmitStats("import", ctx, p.projectCommandRunner.Import, p.scope)
return RunAndEmitStats(ctx, p.projectCommandRunner.Import, p.scope)
}

func (p *InstrumentedProjectCommandRunner) StateRm(ctx command.ProjectContext) command.ProjectResult {
return RunAndEmitStats("state rm", ctx, p.projectCommandRunner.StateRm, p.scope)
return RunAndEmitStats(ctx, p.projectCommandRunner.StateRm, p.scope)
}

func RunAndEmitStats(commandName string, ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectResult, scope tally.Scope) command.ProjectResult {
func RunAndEmitStats(ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectResult, scope tally.Scope) command.ProjectResult {
commandName := ctx.CommandName.String()
// ensures we are differentiating between project level command and overall command
scope = ctx.SetProjectScopeTags(scope).SubScope(commandName)
logger := ctx.Log
Expand Down