@@ -259,6 +259,60 @@ func TestPublishInternal(t *testing.T) {
259
259
require .NoError (t , err )
260
260
})
261
261
262
+ t .Run ("valid operation, correct overridden parameters" , func (t * testing.T ) {
263
+ o := newTestOutbox ().(* outboxImpl )
264
+ o .publishFn = func (ctx context.Context , pr * contribPubsub.PublishRequest ) error {
265
+ var cloudEvent map [string ]interface {}
266
+ err := json .Unmarshal (pr .Data , & cloudEvent )
267
+ require .NoError (t , err )
268
+
269
+ assert .Equal (t , "test" , cloudEvent ["data" ])
270
+ assert .Equal (t , "a" , pr .PubsubName )
271
+ assert .Equal (t , "testapp1outbox" , pr .Topic )
272
+ assert .Equal (t , "testsource" , cloudEvent ["source" ])
273
+ assert .Equal (t , "text/plain" , cloudEvent ["datacontenttype" ])
274
+ assert .Equal (t , "a" , cloudEvent ["pubsubname" ])
275
+
276
+ return nil
277
+ }
278
+
279
+ o .AddOrUpdateOutbox (v1alpha1.Component {
280
+ ObjectMeta : metav1.ObjectMeta {
281
+ Name : "test" ,
282
+ },
283
+ Spec : v1alpha1.ComponentSpec {
284
+ Metadata : []common.NameValuePair {
285
+ {
286
+ Name : outboxPublishPubsubKey ,
287
+ Value : common.DynamicValue {
288
+ JSON : v1.JSON {
289
+ Raw : []byte ("a" ),
290
+ },
291
+ },
292
+ },
293
+ {
294
+ Name : outboxPublishTopicKey ,
295
+ Value : common.DynamicValue {
296
+ JSON : v1.JSON {
297
+ Raw : []byte ("1" ),
298
+ },
299
+ },
300
+ },
301
+ },
302
+ },
303
+ })
304
+
305
+ _ , err := o .PublishInternal (context .Background (), "test" , []state.TransactionalStateOperation {
306
+ state.SetRequest {
307
+ Key : "key" ,
308
+ Value : "test" ,
309
+ Metadata : map [string ]string {"source" : "testsource" },
310
+ },
311
+ }, "testapp" , "" , "" )
312
+
313
+ require .NoError (t , err )
314
+ })
315
+
262
316
t .Run ("valid operation, no datacontenttype" , func (t * testing.T ) {
263
317
o := newTestOutbox ().(* outboxImpl )
264
318
o .publishFn = func (ctx context.Context , pr * contribPubsub.PublishRequest ) error {
@@ -479,7 +533,7 @@ func TestPublishInternal(t *testing.T) {
479
533
}
480
534
481
535
func TestSubscribeToInternalTopics (t * testing.T ) {
482
- t .Run ("correct configuration with trace" , func (t * testing.T ) {
536
+ t .Run ("correct configuration with trace, custom field and nonoverridable fields " , func (t * testing.T ) {
483
537
o := newTestOutbox ().(* outboxImpl )
484
538
o .cloudEventExtractorFn = extractCloudEventProperty
485
539
@@ -496,20 +550,31 @@ func TestSubscribeToInternalTopics(t *testing.T) {
496
550
internalCalledCh := make (chan struct {})
497
551
externalCalledCh := make (chan struct {})
498
552
553
+ var closed bool
554
+
499
555
o .publishFn = func (ctx context.Context , pr * contribPubsub.PublishRequest ) error {
500
556
if pr .Topic == outboxTopic {
501
557
close (internalCalledCh )
502
558
} else if pr .Topic == "1" {
503
- close (externalCalledCh )
559
+ if ! closed {
560
+ close (externalCalledCh )
561
+ closed = true
562
+ }
504
563
}
505
564
506
565
ce := map [string ]string {}
507
566
json .Unmarshal (pr .Data , & ce )
508
567
509
568
traceID := ce [contribPubsub .TraceIDField ]
510
569
traceState := ce [contribPubsub .TraceStateField ]
570
+ customField := ce ["outbox.cloudevent.customfield" ]
571
+ data := ce [contribPubsub .DataField ]
572
+ id := ce [contribPubsub .IDField ]
511
573
assert .Equal (t , "00-ecdf5aaa79bff09b62b201442c0f3061-d2597ed7bfd029e4-01" , traceID )
512
574
assert .Equal (t , "00-ecdf5aaa79bff09b62b201442c0f3061-d2597ed7bfd029e4-01" , traceState )
575
+ assert .Equal (t , "a" , customField )
576
+ assert .Equal (t , "hello" , data )
577
+ assert .Contains (t , id , "outbox-" )
513
578
514
579
return psMock .Publish (ctx , pr )
515
580
}
@@ -556,8 +621,9 @@ func TestSubscribeToInternalTopics(t *testing.T) {
556
621
go func () {
557
622
trs , pErr := o .PublishInternal (context .Background (), "test" , []state.TransactionalStateOperation {
558
623
state.SetRequest {
559
- Key : "1" ,
560
- Value : "hello" ,
624
+ Key : "1" ,
625
+ Value : "hello" ,
626
+ Metadata : map [string ]string {"outbox.cloudevent.customfield" : "a" , "data" : "a" , "id" : "b" },
561
627
},
562
628
}, appID , "00-ecdf5aaa79bff09b62b201442c0f3061-d2597ed7bfd029e4-01" , "00-ecdf5aaa79bff09b62b201442c0f3061-d2597ed7bfd029e4-01" )
563
629
0 commit comments