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

fix: allow validate input to handle multiple source groups #1815

Closed
wants to merge 1 commit into from

Conversation

mbestavros
Copy link
Contributor

@mbestavros mbestavros commented Jul 31, 2024

Resolves #1688.

Turns out that the NewInput function only returned the final source group in the policy. This patch makes the function return ALL source groups and changes the caller to evaluate each one, then append all to the output.

@mbestavros mbestavros requested review from simonbaird and lcarva July 31, 2024 20:48
Signed-off-by: Mark Bestavros <mbestavr@redhat.com>
Copy link

codecov bot commented Jul 31, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.73%. Comparing base (3459e02) to head (d731a01).
Report is 67 commits behind head on main.

Files Patch % Lines
internal/input/validate.go 85.71% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1815      +/-   ##
==========================================
- Coverage   80.74%   80.73%   -0.01%     
==========================================
  Files          68       68              
  Lines        4954     4963       +9     
==========================================
+ Hits         4000     4007       +7     
- Misses        954      956       +2     
Flag Coverage Δ
generative 80.73% <85.71%> (-0.01%) ⬇️
integration 80.73% <85.71%> (-0.01%) ⬇️
unit 80.73% <85.71%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
internal/input/validate.go 83.33% <85.71%> (-0.88%) ⬇️

Copy link
Member

@zregvart zregvart left a comment

Choose a reason for hiding this comment

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

Could add unit/acceptance tests to add regression tests for this

for _, e := range p.Evaluators {
results, _, err := e.Evaluate(ctx, evaluator.EvaluationTarget{Inputs: inputFiles})
if err != nil {
log.Debug("Problem running conftest policy check!")
Copy link
Member

Choose a reason for hiding this comment

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

Could we also log the error?

Copy link
Member

Choose a reason for hiding this comment

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

+1

log.Debug("\n\nRunning conftest policy check\n\n")

if err != nil {
log.Debug("Problem running conftest policy check!")
Copy link
Member

Choose a reason for hiding this comment

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

Let's log the error as well

Copy link
Member

@lcarva lcarva left a comment

Choose a reason for hiding this comment

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

Fix looks reasonable. Let's make sure we add some tests (unit or acceptance) to prevent the behavior from breaking in the future.

log.Debug("Problem running conftest policy check!")
return nil, err
}
log.Debug("\n\nRunning conftest policy check\n\n")
Copy link
Member

Choose a reason for hiding this comment

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

A big unusual to include \n in the log message.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's remove the extra blanks lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but just for the sake of completeness, I pulled some of this code from ec validate image and that logging was there too.

defFunc: mockNewPipelineDefinitionFile,
},
{
name: "validation succeeds with yaml input",
fpath: "kind: task",
err: nil,
output: &output.Output{PolicyCheck: []evaluator.Outcome{}},
output: &output.Output{PolicyCheck: []evaluator.Outcome(nil)},
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious about this diff, is it just a style change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was necessary to allow tests to pass. AFAICT it's just a different type of "nothing" since before it was just an empty list.

Copy link
Member

@simonbaird simonbaird left a comment

Choose a reason for hiding this comment

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

Nice patch. Some logging nitpicks to address, otherwise lgtm.

@lcarva
Copy link
Member

lcarva commented Aug 13, 2024

I created #1858 which includes the changes from the PR and addresses the comments.

@mbestavros
Copy link
Contributor Author

@lcarva's patch (#1858) is the way to go here, but I added some follow-up comments to clarify a few things just for the sake of completeness.

@lcarva
Copy link
Member

lcarva commented Aug 16, 2024

#1858 was merged. Let's close this.

@lcarva lcarva closed this Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] "validate input" does not handle multiple source groups
4 participants