@@ -281,7 +281,7 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
281
281
282
282
t .Run ("from struct.struct.field" , func (t * testing.T ) {
283
283
wf := NewWorkflow [* structB , string ]()
284
- wf .AddEnd (START , FromField ( "F1. F1" ))
284
+ wf .AddEnd (START , FromFieldPath ([] string { "F1" , " F1"} ))
285
285
r , err := wf .Compile (ctx )
286
286
assert .NoError (t , err )
287
287
out , err := r .Invoke (ctx , & structB {
@@ -293,14 +293,14 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
293
293
assert .Equal (t , "hello" , out )
294
294
295
295
wf = NewWorkflow [* structB , string ]()
296
- wf .AddEnd (START , FromField ( "F1. F2" ))
296
+ wf .AddEnd (START , FromFieldPath ([] string { "F1" , " F2"} ))
297
297
_ , err = wf .Compile (ctx )
298
298
assert .ErrorContains (t , err , "type[compose.structA] has no field[F2]" )
299
299
})
300
300
301
301
t .Run ("from map.map.field" , func (t * testing.T ) {
302
302
wf := NewWorkflow [map [string ]map [string ]string , string ]()
303
- wf .AddEnd (START , FromField ( "F1. F1" ))
303
+ wf .AddEnd (START , FromFieldPath ([] string { "F1" , " F1"} ))
304
304
r , err := wf .Compile (ctx )
305
305
assert .NoError (t , err )
306
306
out , err := r .Invoke (ctx , map [string ]map [string ]string {
@@ -322,7 +322,7 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
322
322
323
323
t .Run ("from struct.map.field" , func (t * testing.T ) {
324
324
wf := NewWorkflow [* structB , string ]()
325
- wf .AddEnd (START , FromField ( "F2. F1" ))
325
+ wf .AddEnd (START , FromFieldPath ([] string { "F2" , " F1"} ))
326
326
r , err := wf .Compile (ctx )
327
327
assert .NoError (t , err )
328
328
out , err := r .Invoke (ctx , & structB {
@@ -344,7 +344,7 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
344
344
345
345
t .Run ("from map.struct.field" , func (t * testing.T ) {
346
346
wf := NewWorkflow [map [string ]* structA , string ]()
347
- wf .AddEnd (START , FromField ( "F1. F1" ))
347
+ wf .AddEnd (START , FromFieldPath ([] string { "F1" , " F1"} ))
348
348
r , err := wf .Compile (ctx )
349
349
assert .NoError (t , err )
350
350
out , err := r .Invoke (ctx , map [string ]* structA {
@@ -356,14 +356,14 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
356
356
assert .Equal (t , "hello" , out )
357
357
358
358
wf = NewWorkflow [map [string ]* structA , string ]()
359
- wf .AddEnd (START , FromField ( "F1. F2" ))
359
+ wf .AddEnd (START , FromFieldPath ([] string { "F1" , " F2"} ))
360
360
_ , err = wf .Compile (ctx )
361
361
assert .ErrorContains (t , err , "type[compose.structA] has no field[F2]" )
362
362
})
363
363
364
364
t .Run ("from map[string]any.field" , func (t * testing.T ) {
365
365
wf := NewWorkflow [map [string ]any , string ]()
366
- wf .AddEnd (START , FromField ( "F1. F1" ))
366
+ wf .AddEnd (START , FromFieldPath ([] string { "F1" , " F1"} ))
367
367
r , err := wf .Compile (ctx )
368
368
assert .NoError (t , err )
369
369
out , err := r .Invoke (ctx , map [string ]any {
@@ -391,7 +391,7 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
391
391
392
392
t .Run ("to struct.struct.field" , func (t * testing.T ) {
393
393
wf := NewWorkflow [string , * structB ]()
394
- wf .AddEnd (START , ToField ( "F1. F1" ))
394
+ wf .AddEnd (START , ToFieldPath ([] string { "F1" , " F1"} ))
395
395
r , err := wf .Compile (ctx )
396
396
assert .NoError (t , err )
397
397
out , err := r .Invoke (ctx , "hello" )
@@ -403,14 +403,14 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
403
403
}, out )
404
404
405
405
wf = NewWorkflow [string , * structB ]()
406
- wf .AddEnd (START , ToField ( "F1. F2" ))
406
+ wf .AddEnd (START , ToFieldPath ([] string { "F1" , " F2"} ))
407
407
_ , err = wf .Compile (ctx )
408
408
assert .ErrorContains (t , err , "type[compose.structA] has no field[F2]" )
409
409
})
410
410
411
411
t .Run ("to map.map.field" , func (t * testing.T ) {
412
412
wf := NewWorkflow [string , map [string ]map [string ]string ]()
413
- wf .AddEnd (START , ToField ( "F1. F1" ))
413
+ wf .AddEnd (START , ToFieldPath ([] string { "F1" , " F1"} ))
414
414
r , err := wf .Compile (ctx )
415
415
assert .NoError (t , err )
416
416
out , err := r .Invoke (ctx , "hello" )
@@ -422,14 +422,14 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
422
422
}, out )
423
423
424
424
wf1 := NewWorkflow [string , map [string ]map [string ]int ]()
425
- wf1 .AddEnd (START , ToField ( "F1. F1" ))
425
+ wf1 .AddEnd (START , ToFieldPath ([] string { "F1" , " F1"} ))
426
426
_ , err = wf1 .Compile (ctx )
427
427
assert .ErrorContains (t , err , "field[string]-[int] must not be assignable" )
428
428
})
429
429
430
430
t .Run ("to struct.map.field" , func (t * testing.T ) {
431
431
wf := NewWorkflow [string , * structB ]()
432
- wf .AddEnd (START , ToField ( "F2. F1" ))
432
+ wf .AddEnd (START , ToFieldPath ([] string { "F2" , " F1"} ))
433
433
r , err := wf .Compile (ctx )
434
434
assert .NoError (t , err )
435
435
out , err := r .Invoke (ctx , "hello" )
@@ -443,7 +443,7 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
443
443
444
444
t .Run ("to map.struct.struct.field" , func (t * testing.T ) {
445
445
wf := NewWorkflow [string , map [string ]* structB ]()
446
- wf .AddEnd (START , ToField ( "F1.F1. F1" ))
446
+ wf .AddEnd (START , ToFieldPath ([] string { "F1" , "F1" , " F1"} ))
447
447
r , err := wf .Compile (ctx )
448
448
assert .NoError (t , err )
449
449
out , err := r .Invoke (ctx , "hello" )
@@ -459,17 +459,35 @@ func TestWorkflowWithNestedFieldMappings(t *testing.T) {
459
459
460
460
t .Run ("to struct.int.field" , func (t * testing.T ) {
461
461
wf := NewWorkflow [string , * structB ]()
462
- wf .AddEnd (START , ToField ( "F3.F1. F1" ))
462
+ wf .AddEnd (START , ToFieldPath ([] string { "F3" , "F1" , " F1"} ))
463
463
_ , err := wf .Compile (ctx )
464
464
assert .ErrorContains (t , err , "type[int] is not valid" )
465
465
})
466
466
467
467
t .Run ("to struct.any.field" , func (t * testing.T ) {
468
468
wf := NewWorkflow [string , * structB ]()
469
- wf .AddEnd (START , ToField ( "F4.F1. F1" ))
469
+ wf .AddEnd (START , ToFieldPath ([] string { "F4" , "F1" , " F1"} ))
470
470
_ , err := wf .Compile (ctx )
471
471
assert .ErrorContains (t , err , "the successor has intermediate interface type interface {}" )
472
472
})
473
+
474
+ t .Run ("from nested to nested" , func (t * testing.T ) {
475
+ wf := NewWorkflow [map [string ]any , * structB ]()
476
+ wf .AddEnd (START , MapFieldPaths ([]string {"key1" , "key2" }, []string {"F1" , "F1" }))
477
+ r , err := wf .Compile (ctx )
478
+ assert .NoError (t , err )
479
+ out , err := r .Invoke (ctx , map [string ]any {
480
+ "key1" : map [string ]any {
481
+ "key2" : "hello" ,
482
+ },
483
+ })
484
+ assert .NoError (t , err )
485
+ assert .Equal (t , & structB {
486
+ F1 : & structA {
487
+ F1 : "hello" ,
488
+ },
489
+ }, out )
490
+ })
473
491
}
474
492
475
493
func TestWorkflowCompile (t * testing.T ) {
0 commit comments