fix(templates): apply delay from go_template_json dynamic responses#333
Merged
Conversation
…305) Delay.UnmarshalJSON only accepted numeric nanoseconds, so a delay written as a duration string ("10ms") — the form used in the docs and accepted by the Lua and go_template_yaml engines — failed to parse. go_template_json swallows that error, so the delay was silently dropped and the response returned immediately. Parse each bound as either a duration string (time.ParseDuration) or a number of nanoseconds, like the other engines. Marshalling is unchanged (still numeric nanoseconds), so the on-disk mock format is unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Fixes #305.
Problem
A
delaywritten as duration strings in ago_template_jsondynamic response was silently ignored — the response returned immediately — while the same mock worked underlua:Root cause
Delay.UnmarshalJSONonly accepted numeric nanoseconds, not duration strings like"10ms". The Lua engine pre-parses durations (time.ParseDuration) andgo_template_yamlhappens to accept the string form, butgo_template_jsonfeeds the raw JSON straight toDelay.UnmarshalJSON, which errored on the string.goTemplateJsonEngine.Executelogs that error but doesn't return it, so the delay was dropped as{0, 0}and the mock answered with no delay.Fix
Parse each delay bound as either a duration string (
time.ParseDuration) or a number of nanoseconds, matching the Lua/yaml engines. Marshalling is unchanged (still numeric nanoseconds), so the on-disk mock format is unaffected.Verified
{min,max}and scalar shorthand"5ms"parse correctly.go_template_jsonmock withdelay {min:300ms, max:300ms}now responds in ~0.30s (was ~0s).🤖 Generated with Claude Code