mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? <!-- Describe what has changed in this PR --> Use [gowrap](https://github.com/hexdigest/gowrap) for generating fault injection code. Similar to https://github.com/temporalio/temporal/pull/7050. ## Why? <!-- Tell your future self why have you made these changes --> Less code to maintain. Before: 238 LOC. After: 34 line Go Template. ## How did you test it? <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> Existing tests + eyeballing the output. ## Potential risks <!-- Assuming the worst case, what can be broken when deploying this change to production? --> ## Documentation <!-- Have you made sure this change doesn't falsify anything currently stated in `docs/`? If significant new behavior is added, have you described that in `docs/`? --> ## Is hotfix candidate? <!-- Is this PR a hotfix candidate or does it require a notification to be sent to the broader community? (Yes/No) -->
35 lines
1.1 KiB
Plaintext
35 lines
1.1 KiB
Plaintext
{{ $decorator := (or .Vars.DecoratorName (printf "faultInjection%s" .Interface.Name)) }}
|
|
|
|
type (
|
|
// {{$decorator}} implements {{.Interface.Name}} interface with fault injection.
|
|
{{$decorator}} struct {
|
|
{{.Interface.Type}}
|
|
generator faultGenerator
|
|
}
|
|
)
|
|
|
|
// new{{upFirst $decorator}} returns {{$decorator}}.
|
|
func new{{upFirst $decorator}} (
|
|
baseStore {{.Interface.Type}},
|
|
generator faultGenerator,
|
|
) *{{$decorator}} {
|
|
return &{{$decorator}} {
|
|
{{.Interface.Name}}: baseStore,
|
|
generator: generator,
|
|
}
|
|
}
|
|
|
|
{{range $method := .Interface.Methods}}
|
|
{{if (and $method.AcceptsContext (gt (len $method.Params) 1)) }}
|
|
{{ $methodIdent := (printf "%s.%s" $.Interface.Name $method.Name) }}
|
|
// {{$method.Name}} wraps {{ (printf "%s.%s" $.Interface.Name $method.Name) }}.
|
|
func (d {{$decorator}}) {{$method.Declaration}} {
|
|
err = d.generator.generate("{{ $method.Name }}").inject(func() error {
|
|
{{$method.ResultsNames}} = d.{{$.Interface.Name}}.{{$method.Call}}
|
|
return err
|
|
})
|
|
return
|
|
}
|
|
{{end}}
|
|
{{end}}
|