test: Add property-based tests for Agones resources#31
test: Add property-based tests for Agones resources#31NAME-ASHWANIYADAV wants to merge 6 commits into
Conversation
6fdb983 to
9420c51
Compare
| 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 }), |
There was a problem hiding this comment.
We can also have "None" as a port value.
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>
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
a981fcf to
dd3b4d8
Compare
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
|
Thanks for the thorough review, Mark! You and the AI were both spot on 😄 a) List Mutations: I have added the missing property test for lists to ensure empty addValues are always excluded, mirroring the counter test. |
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().