test: Add property-based tests for Agones resources - #31
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. |
|
Realised I never came back around to this - looks like CI failed on these tests. |
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
…SHWANIYADAV/headlamp-plugin into test/property-based-tests
|
@markmandel may you please re-run ci/cd |
|
Looks like it failed again |
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
|
@markmandel may you please take another look ?? |
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().