@@ -189,12 +189,12 @@ func TestSanitizeExtensionName(t *testing.T) {
189189 }
190190}
191191
192- func TestNewEvent_WithResourceAttributeExtensions (t * testing.T ) {
192+ func TestNewEventWithOpts_WithResourceAttributeExtensions (t * testing.T ) {
193193 payload := []byte ("body" )
194194
195195 t .Run ("sanitized keys/values land on the event" , func (t * testing.T ) {
196196 attrs := map [string ]string {"chain_id" : "1" , "k8s.pod.name" : "pod-abc" }
197- event , err := NewEvent ("domain" , "entity" , payload , nil , WithResourceAttributeExtensions (attrs ))
197+ event , err := NewEventWithOpts ("domain" , "entity" , payload , nil , WithResourceAttributeExtensions (attrs ))
198198 require .NoError (t , err )
199199 ext := event .Extensions ()
200200 assert .Equal (t , "1" , ext ["chainid" ])
@@ -203,14 +203,14 @@ func TestNewEvent_WithResourceAttributeExtensions(t *testing.T) {
203203
204204 t .Run ("empty sanitized name is dropped" , func (t * testing.T ) {
205205 attrs := map [string ]string {"---" : "value" }
206- event , err := NewEvent ("domain" , "entity" , payload , nil , WithResourceAttributeExtensions (attrs ))
206+ event , err := NewEventWithOpts ("domain" , "entity" , payload , nil , WithResourceAttributeExtensions (attrs ))
207207 require .NoError (t , err )
208208 assert .Len (t , event .Extensions (), 1 ) // only the always-set recordedtime extension
209209 })
210210
211211 t .Run ("reserved name is skipped" , func (t * testing.T ) {
212212 attrs := map [string ]string {IdempotencyKeyAttr : "should-not-override" , "subject" : "should-not-override" }
213- event , err := NewEvent ("domain" , "entity" , payload , map [string ]any {IdempotencyKeyAttr : "real-key" }, WithResourceAttributeExtensions (attrs ))
213+ event , err := NewEventWithOpts ("domain" , "entity" , payload , map [string ]any {IdempotencyKeyAttr : "real-key" }, WithResourceAttributeExtensions (attrs ))
214214 require .NoError (t , err )
215215 ext := event .Extensions ()
216216 assert .Equal (t , "real-key" , ext [IdempotencyKeyAttr ])
@@ -219,19 +219,38 @@ func TestNewEvent_WithResourceAttributeExtensions(t *testing.T) {
219219
220220 t .Run ("duplicate sanitized names resolve deterministically to sorted-first key" , func (t * testing.T ) {
221221 attrs := map [string ]string {"service.name" : "from-dotted" , "service_name" : "from-snake" }
222- event , err := NewEvent ("domain" , "entity" , payload , nil , WithResourceAttributeExtensions (attrs ))
222+ event , err := NewEventWithOpts ("domain" , "entity" , payload , nil , WithResourceAttributeExtensions (attrs ))
223223 require .NoError (t , err )
224224 // sorted order: "service.name" < "service_name" ('.' < '_' in ASCII), so the dotted key wins.
225225 assert .Equal (t , "from-dotted" , event .Extensions ()["servicename" ])
226226 })
227227
228- t .Run ("omitting the opt is a no-op" , func (t * testing.T ) {
229- event , err := NewEvent ("domain" , "entity" , payload , nil )
228+ t .Run ("omitting all opts is a no-op" , func (t * testing.T ) {
229+ event , err := NewEventWithOpts ("domain" , "entity" , payload , nil )
230230 require .NoError (t , err )
231231 assert .Len (t , event .Extensions (), 1 ) // only the always-set recordedtime extension
232232 })
233233}
234234
235+ // TestNewEvent_UnchangedSignature is a backward-compatibility guard: NewEvent's exported
236+ // signature must stay exactly as it was before EventOpt/NewEventWithOpts were introduced, and
237+ // must remain equivalent to calling NewEventWithOpts with no opts.
238+ func TestNewEvent_UnchangedSignature (t * testing.T ) {
239+ payload := []byte ("body" )
240+ attributes := map [string ]any {"subject" : "example-subject" }
241+
242+ viaNewEvent , err := NewEvent ("domain" , "entity" , payload , attributes )
243+ require .NoError (t , err )
244+
245+ viaNewEventWithOpts , err := NewEventWithOpts ("domain" , "entity" , payload , attributes )
246+ require .NoError (t , err )
247+
248+ assert .Equal (t , viaNewEventWithOpts .Subject (), viaNewEvent .Subject ())
249+ assert .Equal (t , viaNewEventWithOpts .Extensions ()["recordedtime" ].(ce.Timestamp ).Time .Truncate (time .Second ),
250+ viaNewEvent .Extensions ()["recordedtime" ].(ce.Timestamp ).Time .Truncate (time .Second ))
251+ assert .Equal (t , viaNewEventWithOpts .Data (), viaNewEvent .Data ())
252+ }
253+
235254func TestEventToProto (t * testing.T ) {
236255 // Create a test protobuf message
237256 testProto := pb.PingResponse {Message : "test message" }
0 commit comments