Skip to content

feat(internal/surfer): add integration tests#4730

Merged
quirogas merged 64 commits intogoogleapis:mainfrom
quirogas:integration-tests
Mar 25, 2026
Merged

feat(internal/surfer): add integration tests#4730
quirogas merged 64 commits intogoogleapis:mainfrom
quirogas:integration-tests

Conversation

@quirogas
Copy link
Copy Markdown
Contributor

@quirogas quirogas commented Mar 23, 2026

Add a golden file testing framework for surfer. This framework provides a consistent way to validate the final YAML output generated by `surfer. It ensures that changes to parsing and generation logic are tested against expected YAML outputs before being merged.

How the Integration Tests Work

The core testing logic is implemented in golden_file_test.go. The test suite iterates over predefined scenarios (located in internal/surfer/sufer/testdata/). For each scenario it:

  1. Copies the scenario proto files and standard googleapis imports into a temporary structure.
  2. Invokes the surfer generate command via the CLI using the defined test config and context.
  3. Compares the resulting generated output directory against a set of expected "golden" files.

The expected YAMLs are divided into two distinct expectations, verified in subtests:

  • surfer: The current snapshot of what surfer outputs. (for CI)
  • autogen: The intended, ideal state of output. This directory represents the target output we are aiming for in the future, mimicking the exact output of autogen (for development).

Test Cases Covered

The test suite spans multiple edge scenarios and common API design patterns. Test cases tested in this framework include:

Running and Updating Tests

  • To update the surfer golden files: If you make an intentional parser/generator change and need to record the newly generated surfer output as the expected golden state, run the tests with the -update flag:
go test ./internal/surfer/surfer -update
  • To run the autogen comparison: By default, the tests only compare against the surfer golden directory. To enable the comparison against autogen golden files, use the -run-with-autogen-comparison flag:
go test ./internal/surfer/surfer -run-with-autogen-comparison

Fixes # 4642

quirogas added 30 commits March 18, 2026 04:18
@quirogas
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive golden file testing framework for the surfer generator, which is a great addition for ensuring stability and correctness. The changes also include removing internal Google links from comments, making the code more suitable for open source. My review focuses on the new testing framework in internal/surfer/surfer/golden_file_test.go. I've identified a few areas for improvement regarding error handling, the completeness of directory comparisons, and code clarity. Overall, this is a solid contribution that significantly improves the project's test coverage.

@quirogas
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive integration test suite for the surfer tool using golden files, which is a great addition for ensuring the stability and correctness of the code generator. The test framework is well-structured, with good use of parallel tests, timeouts, and clear separation of test cases. I've identified a couple of areas for improvement in the test implementation to enhance its completeness and code quality. Specifically, the test verification should include all generated files, and a minor cleanup in a helper function signature would improve code clarity.

@quirogas quirogas marked this pull request as ready for review March 24, 2026 05:43
@quirogas quirogas requested a review from a team as a code owner March 24, 2026 05:43
Copy link
Copy Markdown
Contributor

@sarahheacock sarahheacock left a comment

Choose a reason for hiding this comment

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

I went a little crazy with the nits but love the test set up and how they work! This is better than what I had in mind

@quirogas quirogas changed the title surfer: add integration tests feat(internal/surfer): add integration tests Mar 24, 2026
@quirogas quirogas enabled auto-merge (squash) March 25, 2026 17:46
@quirogas quirogas merged commit 8fe449a into googleapis:main Mar 25, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

surfer Issues related to the surfer project (https://github.com/googleapis/librarian/issues/2375)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants