Skip to content

Conversation

califlower
Copy link
Contributor

  • Add SetSeed() method to SchemaRenderer to allow setting custom random seed
  • Add SetSeed() method to MockGenerator that delegates to underlying renderer
  • Replace global rand usage with instance-based *rand.Rand in SchemaRenderer
  • Update all rand.* calls to use instance-specific random source

This enables deterministic mock generation for testing purposes while keeping existing random behavior by default.

Some background, the random behavior was convenient but made certain generation scenarios a bit hard to test. If this isn't something you think is needed lmk it's not a big deal either way

…tic output

- Add SetSeed() method to SchemaRenderer to allow setting custom random seed
- Add SetSeed() method to MockGenerator that delegates to underlying renderer
- Replace global rand usage with instance-based *rand.Rand in SchemaRenderer
- Update all rand.* calls to use instance-specific random source
- Add comprehensive tests for deterministic behavior with same/different seeds
- Maintains full backward compatibility with existing API

This enables deterministic mock generation for testing purposes while
keeping existing random behavior by default.
@califlower califlower closed this Aug 11, 2025
@califlower califlower reopened this Aug 11, 2025
- Initialize rand field in createSchemaRenderer() test helper
- Add missing math/rand import to schema_renderer_test.go

This fixes the panic that occurred when tests created empty SchemaRenderer
instances without initializing the new rand field.
Copy link

codecov bot commented Aug 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.67%. Comparing base (c3b03f1) to head (1b67723).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #450      +/-   ##
==========================================
- Coverage   99.67%   99.67%   -0.01%     
==========================================
  Files         169      169              
  Lines       24546    24551       +5     
==========================================
+ Hits        24467    24470       +3     
- Misses         74       76       +2     
  Partials        5        5              
Flag Coverage Δ
unittests 99.67% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@califlower califlower marked this pull request as ready for review August 11, 2025 19:32
@califlower califlower force-pushed the add-seed-support-mock-generator branch from 1b67723 to 079f82a Compare August 11, 2025 19:53
@califlower
Copy link
Contributor Author

califlower commented Aug 19, 2025

fixes #454

Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks! this is a nice upgrade.

@daveshanley daveshanley merged commit 7c53faa into pb33f:main Aug 25, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants