@@ -2402,52 +2402,34 @@ func Test_newPath(t *testing.T) {
2402
2402
2403
2403
func Test_newPath_WithPathContextNames (t * testing.T ) {
2404
2404
tests := []struct {
2405
- name string
2406
- pathContext string
2407
- pathContextNames []string
2408
- validationEnabled bool
2409
- contextParsedAsField bool
2410
- expectedError bool
2405
+ name string
2406
+ pathContext string
2407
+ pathContextNames []string
2408
+ expectedError string
2411
2409
}{
2412
2410
{
2413
- name : "with no context" ,
2411
+ name : "with no path context" ,
2414
2412
pathContextNames : []string {"log" },
2413
+ expectedError : `missing context name for path "body.string[key]", valid options are: "log.body.string[key]"` ,
2415
2414
},
2416
2415
{
2417
- name : "with context" ,
2416
+ name : "with no path context and configuration" ,
2417
+ },
2418
+ {
2419
+ name : "with valid path context" ,
2418
2420
pathContext : "log" ,
2419
2421
pathContextNames : []string {"log" },
2420
2422
},
2421
2423
{
2422
- name : "with multiple contexts " ,
2424
+ name : "with invalid path context " ,
2423
2425
pathContext : "span" ,
2424
- pathContextNames : []string {"log" , "span" },
2425
- },
2426
- {
2427
- name : "with invalid context and validation disabled" ,
2428
- pathContext : "span" ,
2429
- pathContextNames : []string {"log" },
2430
- validationEnabled : false ,
2431
- contextParsedAsField : true ,
2432
- },
2433
- {
2434
- name : "with invalid context and validation enabled" ,
2435
- pathContext : "span" ,
2436
- pathContextNames : []string {"log" },
2437
- validationEnabled : true ,
2438
- expectedError : true ,
2439
- },
2440
- {
2441
- name : "with valid context and validation enabled" ,
2442
- pathContext : "spanevent" ,
2443
- pathContextNames : []string {"spanevent" },
2444
- validationEnabled : true ,
2426
+ pathContextNames : []string {"log" },
2427
+ expectedError : `context "span" from path "span.body.string[key]" is not valid, it must be replaced by one of: "log"` ,
2445
2428
},
2446
2429
{
2447
- name : "with no context and validation enabled" ,
2448
- pathContextNames : []string {"spanevent" },
2449
- validationEnabled : true ,
2450
- expectedError : true ,
2430
+ name : "with multiple configured contexts" ,
2431
+ pathContext : "span" ,
2432
+ pathContextNames : []string {"log" , "span" },
2451
2433
},
2452
2434
}
2453
2435
@@ -2459,7 +2441,6 @@ func Test_newPath_WithPathContextNames(t *testing.T) {
2459
2441
componenttest .NewNopTelemetrySettings (),
2460
2442
WithEnumParser [any ](testParseEnum ),
2461
2443
WithPathContextNames [any ](tt .pathContextNames ),
2462
- WithPathContextNameValidation [any ](tt .validationEnabled ),
2463
2444
)
2464
2445
2465
2446
gp := & path {
@@ -2479,13 +2460,14 @@ func Test_newPath_WithPathContextNames(t *testing.T) {
2479
2460
}}
2480
2461
2481
2462
np , err := ps .newPath (gp )
2482
- if tt .expectedError {
2483
- assert .Error (t , err )
2463
+ if tt .expectedError != "" {
2464
+ assert .Error (t , err , tt . expectedError )
2484
2465
return
2485
2466
}
2486
2467
assert .NoError (t , err )
2487
2468
p := Path [any ](np )
2488
- if tt .contextParsedAsField {
2469
+ contextParsedAsField := len (tt .pathContextNames ) == 0 && tt .pathContext != ""
2470
+ if contextParsedAsField {
2489
2471
assert .Equal (t , tt .pathContext , p .Name ())
2490
2472
assert .Equal (t , "" , p .Context ())
2491
2473
assert .Nil (t , p .Keys ())
@@ -2500,13 +2482,13 @@ func Test_newPath_WithPathContextNames(t *testing.T) {
2500
2482
assert .Equal (t , "body" , p .Name ())
2501
2483
assert .Nil (t , p .Keys ())
2502
2484
assert .Equal (t , bodyStringFuncValue , p .String ())
2503
- if ! tt . contextParsedAsField {
2485
+ if ! contextParsedAsField {
2504
2486
assert .Equal (t , tt .pathContext , p .Context ())
2505
2487
}
2506
2488
p = p .Next ()
2507
2489
assert .Equal (t , "string" , p .Name ())
2508
2490
assert .Equal (t , bodyStringFuncValue , p .String ())
2509
- if ! tt . contextParsedAsField {
2491
+ if ! contextParsedAsField {
2510
2492
assert .Equal (t , tt .pathContext , p .Context ())
2511
2493
}
2512
2494
assert .Nil (t , p .Next ())
0 commit comments