fix(test): match xrayErrorCause by reflected type, not type name - #128
fix(test): match xrayErrorCause by reflected type, not type name#128carole-lavillonniere wants to merge 1 commit into
Conversation
Go 1.27 makes encoding/json's RawMessage an alias for jsontext.Value, so
the runtime type name is now "jsontext.Value". testify's AnythingOfType
matches on that name string, so the three SendInvokeFinishedEvent
expectations stopped matching and the mock panicked on an unexpected call:
Diff: 1: FAIL: type json.RawMessage != type Value - (jsontext.Value=null)
Switch to mock.IsType, which resolves the type through reflection and so
matches whether or not the alias is in play. This has broken
TestRuntimeErrorFailure_ErrorWhileError and left the localstack branch red
since the go directive bump to 1.27.0 in #122.
|
Closing — wrong fix, and the framing in the description was wrong. Go did not break backward compatibility here.
So #122 ( It also edits upstream code: The unmodified upstream test passes with the directive back at |
Problem
localstackhas been red since #122 (godirective →1.27.0, merged Aug 22). Every build on the branch since then has failed, and six Renovate PRs automerged on top of the breakage.Go 1.27 makes
encoding/json'sRawMessagean alias forjsontext.Value, so the runtime type name is nowjsontext.Value. testify'sAnythingOfTypematches on that name string, so the threeSendInvokeFinishedEventexpectations stopped matching and the mock panicked on an unexpected call:TestRuntimeErrorFailure_ErrorWhileErrorpanics, which fails the package and thetestjob.Fix
Switch the three expectations to
mock.IsType(json.RawMessage(nil)).IsTyperesolves the type throughreflect.TypeOfrather than comparing a hardcoded name, so it matches whether or not the alias is in play — no re-break if the alias changes again.Hardcoding
"jsontext.Value"would also go green today, but re-breaks on any future rename and reads as if the test cares about the JSON encoder's internals; it doesn't.Scope
Only
AnythingOfType("json.RawMessage")was affected. I checked everyAnythingOfTypein the repo — the rest areint,bool,int64,time.Time,time.Duration,*interop.TracingCtx,interop.TelemetrySubscriptionMetrics, none of which are aliased.Production code is untouched; this is a test-only change.
Verification
go test ./...passes locally on go1.27.0. Before the change,internal/lambda-managed-instances/invokepanicked.Note
This fixes the breakage but not the reason it reached the branch. The ruleset requires the
buildcheck, butbuildhasneeds: test— so a failingtestmakesbuildreportskipped, which GitHub counts as passing.testitself isn't required, so Renovate automerges onto red. Follow-up PR addresses that.