Skip to content

test: use custom filter to make tests less brittle#2544

Merged
sozercan merged 5 commits into
open-policy-agent:masterfrom
acpana:acpana/refactor-tests
Mar 29, 2023
Merged

test: use custom filter to make tests less brittle#2544
sozercan merged 5 commits into
open-policy-agent:masterfrom
acpana:acpana/refactor-tests

Conversation

@acpana
Copy link
Copy Markdown
Contributor

@acpana acpana commented Jan 28, 2023

Re working some of these to be less brittle. It's going to help any time we make changes to the Result type in CF.

Signed-off-by: Alex Pana 8968914+acpana@users.noreply.github.com

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 28, 2023

Codecov Report

Base: 53.62% // Head: 53.51% // Decreases project coverage by -0.12% ⚠️

Coverage data is based on head (20f93a7) compared to base (8170c5f).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2544      +/-   ##
==========================================
- Coverage   53.62%   53.51%   -0.12%     
==========================================
  Files         120      120              
  Lines       10634    10634              
==========================================
- Hits         5703     5691      -12     
- Misses       4500     4509       +9     
- Partials      431      434       +3     
Flag Coverage Δ
unittests 53.51% <ø> (-0.12%) ⬇️

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

Impacted Files Coverage Δ
...onstrainttemplate/constrainttemplate_controller.go 54.06% <0.00%> (-2.88%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@acpana acpana marked this pull request as ready for review January 28, 2023 06:42
@acpana acpana force-pushed the acpana/refactor-tests branch from edb9fc3 to 084571c Compare January 28, 2023 06:46
@JaydipGabani
Copy link
Copy Markdown
Contributor

@acpana can you explain why this was brittle? What was causing it to break? Just curious

@acpana
Copy link
Copy Markdown
Contributor Author

acpana commented Jan 30, 2023

can you explain why this was brittle? What was causing it to break?

the tl;dr issue imo is that we are comparing structs absolutely (i.e. all the fields). you'll see that we have a few cmpopts.IgnoreFields() calls in our testing to ignore struct fields that we don't necessarily care about or can compare absolutely.

When working on the structs themselves, like Result, the current approach causes test failures. You won't see those failures here, but you will see them in the constraint framework repo. eg job runs:

does this help offer more context?

Comment thread cmd/gator/test/gatortest_test.go Outdated
Comment thread cmd/gator/test/gatortest_test.go Outdated
Comment thread pkg/gator/test/test_test.go Outdated
@JaydipGabani
Copy link
Copy Markdown
Contributor

can you explain why this was brittle? What was causing it to break?

the tl;dr issue imo is that we are comparing structs absolutely (i.e. all the fields). you'll see that we have a few cmpopts.IgnoreFields() calls in our testing to ignore struct fields that we don't necessarily care about or can compare absolutely.

When working on the structs themselves, like Result, the current approach causes test failures. You won't see those failures here, but you will see them in the constraint framework repo. eg job runs:

does this help offer more context?

Thanks for clearing it up

@acpana acpana force-pushed the acpana/refactor-tests branch from 084571c to d285243 Compare February 1, 2023 22:22
}
}

func ignoreGatorResultFields() cmp.Option {
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.

the main difference here between our custom option and the IgnoreFields option is that the latter relies the existence of a field; ref: https://github.com/google/go-cmp/blob/a97318bf6562f2ed2632c5f985db51b1bc5bdcd0/cmp/cmpopts/struct_filter.go#L177-L179

@acpana acpana requested a review from maxsmythe February 1, 2023 22:29
@acpana acpana changed the title test: make tests less brittle test: use custom filter to make tests less brittle Feb 15, 2023
@acpana
Copy link
Copy Markdown
Contributor Author

acpana commented Feb 15, 2023

@maxsmythe @sozercan @ritazh PTAL 🙏🏼

Copy link
Copy Markdown
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@sozercan sozercan left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

Comment thread pkg/gator/test/test_test.go Outdated
acpana added 5 commits March 28, 2023 19:05
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
@acpana acpana force-pushed the acpana/refactor-tests branch from 9ddb3a6 to f086ea6 Compare March 28, 2023 19:46
@sozercan sozercan merged commit e33c551 into open-policy-agent:master Mar 29, 2023
davis-haba pushed a commit to davis-haba/gatekeeper that referenced this pull request Mar 31, 2023
salaxander pushed a commit to salaxander/gatekeeper that referenced this pull request Apr 5, 2023
…#2544)

Signed-off-by: Xander Grzywinski <xandergr@microsoft.com>
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.

6 participants