test: Add property-based tests for Agones resources#31
Draft
NAME-ASHWANIYADAV wants to merge 3 commits into
Draft
test: Add property-based tests for Agones resources#31NAME-ASHWANIYADAV wants to merge 3 commits into
NAME-ASHWANIYADAV wants to merge 3 commits into
Conversation
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
6fdb983 to
9420c51
Compare
markmandel
reviewed
Jul 8, 2026
| function fcGameServerJson(): fc.Arbitrary<any> { | ||
| const fcSpecPort = fc.record({ | ||
| name: fc.option(fc.string({ minLength: 1, maxLength: 15 }), { nil: undefined }), | ||
| portPolicy: fc.option(fc.constantFrom('Dynamic', 'Static', 'Passthrough'), { nil: undefined }), |
Member
There was a problem hiding this comment.
We can also have "None" as a port value.
Contributor
Author
There was a problem hiding this comment.
I've updated the fcGameServerJson generator and the assertion to include "None" as a valid portPolicy value. Tests are passing!
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
What this PR does
This PR adds property-based testing to the Agones plugin using the
fast-checkframework. It verifies invariants across Agones resource models and utilities using randomly generated inputs.Added 6 new test files (
*.property.test.ts):buildAllocationBody: 11 invariants (structural guarantees, namespace propagation, label trimming, mutation filtering)StateChip: 3 invariants (no crash on any string, valid MUI colors, known state mapping fallback)GameServer: 9 invariants (getter return types, port formatting, protocol/policy defaults)Fleet: 3 invariants (numeric types, scheduling/strategy defaults)FleetAutoscaler: 3 invariants (numeric/boolean return types)GameServerAllocation: 2 invariants (string types, port "name:port" format)Total: 31 property checks generating ~3,100 random test cases per run.
Note: Depends on the testing infrastructure introduced in the previous PR.
Test plan
Automated checks
npm cinpm run buildnpm run tscnpm run lintnpm run format -- --checknpm run testAll 70 tests (39 existing + 31 new property tests) pass successfully.
Notes for reviewers
One interesting finding during implementation:
fast-checkgenerated"__proto__"as a counterexample for theStateChipcolor lookup test, which broke theSTATE_COLORS[state] ?? 'default'logic due to JS prototype pollution behavior. This was fixed in the test by usingObject.prototype.hasOwnProperty.call().