You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "hackintoshrao (via GitHub)" <gi...@apache.org> on 2025/08/07 13:29:14 UTC
[PR] test(table): Add validation tests for Requirement interface [iceberg-go]
hackintoshrao opened a new pull request, #527:
URL: https://github.com/apache/iceberg-go/pull/527
Hi team,
This PR adds a comprehensive, table-driven unit test suite for the `Validate()` and `GetType()` methods of all types that implement the `table.Requirement` interface.
#### Motivation
The `Requirement` validation logic is a critical part of the commit protocol, ensuring transactional safety for table updates. However, this logic was not explicitly covered by unit tests, leaving it potentially vulnerable to future regressions.
This test suite is intended to serve as a **gatekeeper** for this important feature. It ensures that the contract of each requirement's `Validate` method is well-defined and that any future, unintended changes to this core logic will be caught by the CI.
#### Implementation Details
- A new test suite, `TestRequirementValidation`, has been added to `table/requirement_test.go`.
- It uses a lightweight, mock `table.Metadata` object to precisely control the conditions for each test case without needing to construct a full metadata object.
- The tests cover all key scenarios for each requirement type, including:
- Success on a valid state.
- Failure on an invalid state (e.g., mismatched UUIDs, conflicting snapshot IDs).
- Correct behavior when validating against a non-existent (`nil`) table, which is crucial for the `assert-create` requirement.
Happy to make any adjustments or answer any questions. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] test(table): Add validation tests for Requirement interface [iceberg-go]
Posted by "laskoviymishka (via GitHub)" <gi...@apache.org>.
laskoviymishka commented on code in PR #527:
URL: https://github.com/apache/iceberg-go/pull/527#discussion_r2280966446
##########
table/requirement_test.go:
##########
@@ -145,3 +147,214 @@ func TestParseRequirementList(t *testing.T) {
assert.Error(t, err)
})
}
+
+// mockMetadata is a correct and complete mock implementation of the
+// table.Metadata interface, used for testing requirement validation.
+type mockMetadata struct {
Review Comment:
this is not a mock, this is fake, take a look [here](https://martinfowler.com/bliki/TestDouble.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] test(table): Add validation tests for Requirement interface [iceberg-go]
Posted by "hackintoshrao (via GitHub)" <gi...@apache.org>.
hackintoshrao commented on PR #527:
URL: https://github.com/apache/iceberg-go/pull/527#issuecomment-3198803979
@laskoviymishka Thanks for the feedback, you're right, it's a fake, not a mock.
My goal was to validate the contract of the Requirement interface, but using a fake defeats that purpose since it doesn't test real behavior. It just tests against my own simplified implementation. Apologies for the naivety here; this is a rare mistake on my part.
I see that to test the contract correctly, I need to use a real TableMetadataBuilder and test against actual metadata lifecycle scenarios rather than artificial ones.
I'll rework this to:
- Build metadata using the real builder/update mechanisms
- Test requirements against actual metadata state transitions
- Use errors.Is instead of string matching
- Make the tests more straightforward and more explicit
My primary concern is to ensure that no unintended changes are introduced into the implementation that might affect upstream users of the library.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] test(table): Add validation tests for Requirement interface [iceberg-go]
Posted by "laskoviymishka (via GitHub)" <gi...@apache.org>.
laskoviymishka commented on PR #527:
URL: https://github.com/apache/iceberg-go/pull/527#issuecomment-3194555815
Besides the obvious problem with linting, such tests are harmful—you’re hiding a contract instead of exposing it.
If you plan to bring value by explicitly checking a contract, it’s better to rework the test framework into more assert-style code.
Right now the tests don’t really lock down the contract -- they mainly check `GetType()` against a custom `mockMetadata`. To make them meaningful:
– build `Metadata` via the real builder/updates instead of a fake (which you named as mock)
– cover each `Requirement` with clear positive/negative `Validate` cases (no table, plain procedural code)
– use golden tests for serialization (fixed test-data) instead of ad-hoc checks
– verify errors via `errors.Is` rather than string matching.
This way the tests capture the contract rather than implementation details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] test(table): Add validation tests for Requirement interface [iceberg-go]
Posted by "hackintoshrao (via GitHub)" <gi...@apache.org>.
hackintoshrao closed pull request #527: test(table): Add validation tests for Requirement interface
URL: https://github.com/apache/iceberg-go/pull/527
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org