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

test(Spring CodeGen): Set up golden file tests for spring class composers #1052

Merged
merged 15 commits into from
Oct 11, 2022

Conversation

emmileaf
Copy link
Contributor

@emmileaf emmileaf commented Oct 3, 2022

In this PR:

  • Separates SpringPropertiesClassComposerTest from SpringAutoConfigClassComposerTest
  • Replaces string comparisons with golden file testing

To update golden files:

mvn test -DupdateUnitGoldens -Dtest=SpringAutoConfigClassComposerTest
mvn test -DupdateUnitGoldens -Dtest=SpringPropertiesClassComposerTest
mvn test -DupdateUnitGoldens -Dtest=SpringComposerTest

Potential conflicts:

@emmileaf emmileaf added the spring pr that's related to spring code gen, intend to merge into autoconfig-gen-draft2 branch. label Oct 3, 2022
@emmileaf
Copy link
Contributor Author

emmileaf commented Oct 4, 2022

@zhumin8 Two open questions for this PR:

  1. Right now the golden files for SpringComposerTest vs. the individual class composer tests only differ in the apache license. Would we want to keep these as separate files (vs. combine and reuse), given the additional testing for SpringComposer steps that we anticipate adding in the future?

  2. I’ve split out SpringPropertiesClassComposerTest from SpringAutoConfigClassComposerTest, but noticed that the same chunk of setup code is shared and repeated. This setup seems to be replaceable by calling TestProtoLoader:

    this.context = TestProtoLoader.instance().parseShowcaseEcho();
    this.echoProtoService = this.context.services().get(0);

Was there a consideration for keeping the explicit setup steps here (perhaps for things that’d need customizing or flexibility in the future?) If not, I'll make the switch over in this PR.

@emmileaf emmileaf marked this pull request as ready for review October 4, 2022 20:06
@emmileaf emmileaf requested review from a team as code owners October 4, 2022 20:06
Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

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

Great work! this will make our work a lot easier when making changes to the Composer classes.

I only got one comment:
The setups for the three existing tests are exactly the same. Perhaps it makes sense to have an Abstract test class with the setups and each extend from it. This way if we ever want to test on more edge-cases in future, we are able to add the scenario to all test in sync.

On your questions above:

  1. Changes to SpringComposer I have in mind now: 1) add package-info composer 2)extracting the @Generated("by gapic-generator-java") here instead of individual class composers. 3)perhaps add a new class composer for a shared property class.
    Either way, I would say combine and reuse is fine. Unless it causes trouble setting updates to golden files. Also, I don't have to strong a preference here, now that with golden files, they can be updated.
  2. Great find! No particular reason. Your replacement is better. (I probably started out there testing around and lost track of the origin entirely)

BUILD.bazel Outdated
@@ -208,6 +208,9 @@ GOLDEN_UPDATING_UNIT_TESTS = [
"com.google.api.generator.gapic.composer.rest.ServiceClientTestClassComposerTest",
"com.google.api.generator.gapic.composer.rest.ServiceSettingsClassComposerTest",
"com.google.api.generator.gapic.composer.rest.ServiceStubSettingsClassComposerTest",
"com.google.api.generator.spring.SpringAutoConfigClassComposerTest",
Copy link
Contributor

@zhumin8 zhumin8 Oct 5, 2022

Choose a reason for hiding this comment

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

just a note for future: we will need to carry this update logic over if we separate from gapic-generator-java.

@emmileaf
Copy link
Contributor Author

emmileaf commented Oct 6, 2022

@zhumin8 Thank you for the review! A quick summary of follow-up changes to the PR:

  • Replaced the tests’ setup code (as discussed above)
  • Moved tests and goldens into a composer subdirectory to align with package structure of the source code
  • Tried changing the SpringComposer tests to reuse golden files from the individual class composer tests, but the extra setup felt more complicated than expected. Upon second thought, having a test use but not update the golden files (or having two different tests update the same ones) could get confusing, so I reverted back to separate files and just gave them better names. We can revisit this if needed later.

@emmileaf emmileaf requested a review from zhumin8 October 6, 2022 14:41
Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

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

Changes looks good. Agreed on your reasoning on keeping separate golden files.

BUILD.bazel Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@emmileaf emmileaf merged commit 2b11de7 into autoconfig-gen-draft2 Oct 11, 2022
@emmileaf emmileaf deleted the autoconfig-emmwang-test branch October 11, 2022 13:22
suztomo pushed a commit that referenced this pull request Mar 21, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [org.threeten:threetenbp](https://www.threeten.org/threetenbp) ([source](https://togithub.com/ThreeTen/threetenbp)) | `1.6.4` -> `1.6.5` | [![age](https://badges.renovateapi.com/packages/maven/org.threeten:threetenbp/1.6.5/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/org.threeten:threetenbp/1.6.5/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/org.threeten:threetenbp/1.6.5/compatibility-slim/1.6.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/org.threeten:threetenbp/1.6.5/confidence-slim/1.6.4)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ThreeTen/threetenbp</summary>

### [`v1.6.5`](https://togithub.com/ThreeTen/threetenbp/releases/tag/v1.6.5)

[Compare Source](https://togithub.com/ThreeTen/threetenbp/compare/v1.6.4...v1.6.5)

See the [change notes](https://www.threeten.org/threetenbp/changes-report.html) for more information.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-core).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spring pr that's related to spring code gen, intend to merge into autoconfig-gen-draft2 branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants