Skip to content

Conversation

@braydonk
Copy link
Contributor

@braydonk braydonk commented Aug 24, 2022

Description

The gotesttools package for golden tests lines up perfectly with the
golden tests that we currently do, and using it can greatly simplify our
unit test code. This PR reimagines the confgenerator_test.go tests using
this package. A few other minor changes were made:

  • The invalid type for sqlserver test did not have an input.yaml (this
    new way of doing tests actually caught that; it's been that way
    forever)
  • It never made much sense for golden_otel to have an extension of
    conf, this PR switches that to yaml
  • Since we install gotesttools in this PR for golden, just opted to use the assert package as well

Related issue

None yet, since I wanted to post this as RFC first. 🙂
EDIT: Created a bug for this. b/243791505

How has this been tested?

Verbose test run: https://pastebin.com/SahVB1Kg
The -update flag worked as expected, as evidenced by the updated files in the PR.

Checklist:

  • Unit tests
    • Unit tests do not apply.
    • Unit tests have been added/modified and passed for this PR.
  • Integration tests
    • Integration tests do not apply.
    • Integration tests have been added/modified and passed for this PR.
  • Documentation
    • This PR introduces no user visible changes.
    • This PR introduces user visible changes and the corresponding documentation change has been made.
  • Minor version bump
    • This PR introduces no new features.
    • This PR introduces new features, and there is a separate PR to bump the minor version since the last release already.
    • This PR bumps the version.

@sophieyfang sophieyfang self-requested a review August 25, 2022 13:45
@qingling128
Copy link
Contributor

qingling128 commented Aug 25, 2022

Can we add some details (e.g. command output, transcripts, could be a file) for the How has this been tested? section for the records? BTW, have we gotten a chance to test the -update_golden flag with this change? (no need to wait for me for merging)

@braydonk braydonk force-pushed the braydonk-golden-experiment branch from 31189b2 to e0fbaed Compare September 6, 2022 15:41
The gotesttools package for golden tests lines up perfectly with the
golden tests that we currently do, and using it can greatly simplify our
unit test code. This PR reimagines the confgenerator_test.go tests using
this package. 2 other minor changes were made:

* The invalid type for sqlserver test did not have an input.yaml (this
  new way of doing tests actually caught that; it's been that way
  forever)
* It never made much sense for `golden_otel` to have an extension of
  `conf`, this PR switches that to `yaml`
This reverts commit 13b99e9f40387531f6cde67163f7ccaffbceebc3. It did not
work.
The local function checkGoldenError was unnecessarily complex compared
to simply splitting it up and calling assert in every spot. Thanks
@avilevy18 for the suggestion.
Unifies the tests for valid and invalid to reduce repetition. Also
supports generating and comparing lua files, as well as cleaning up old
ones when the lua files change.
I had a bug in the lua gen testing that botched tons of input.yaml
files. I reverted that commit, restored the new confgenerator_test
changes, and regenerated the configs. I should be smarter about when I
commit!
By using a functional option to runTestsInDir, we can reduce the
duplication of gathering all the platform's test cases and asserting
differently for valid vs invalid tests.
@braydonk braydonk force-pushed the braydonk-golden-experiment branch from 329db6f to e3d7607 Compare September 6, 2022 19:04
@braydonk braydonk requested a review from sophieyfang September 8, 2022 11:29
@braydonk braydonk merged commit d12b900 into master Sep 8, 2022
@quentinmit
Copy link
Member

I'm trying to handle a merge conflict on this PR - I'm wondering why this refactoring added so much duplicate code? The golden package is nice but it seems like it was coupled with unrolling a bunch of loops?

@braydonk
Copy link
Contributor Author

@quentinmit The unrolling of loops was to add some robustness to the tests.
In the previous version, valid and invalid tests weren't technically treated any differently. If an invalid config was placed in the valid folder or vice versa the previous tests didn't care. There were some actual test cases before this PR that were afflicted by this. Now they are properly treated differently, i.e. if an invalid config is put in a valid test case folder or vice versa the test will fail.
When Lua files changed in the previous version there was no cleanup. Now, the case where they are changed includes cleanup of the old Lua files.
The previous version of the tests checked for a test name that contained "builtin" which I thought would make more sense to split into its own test run rather than needing to check and do something different on that case. A lot of folks also use that builtin test case a lot to check what the default config generation is, so separating it into its own folder makes it more convenient to find (pretty minor thing compared to everything else).

@igorpeshansky igorpeshansky deleted the braydonk-golden-experiment branch July 10, 2023 21:49
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