@@ -36,6 +36,10 @@ func TestBasicPolicy(t *testing.T) {
3636 testPolicyWithFullCache (t )
3737 testPolicyWithPartialCache (t )
3838 testGenerateUniqueTimestamps (t )
39+
40+ testFailureLexer (t )
41+ testFailureParser (t )
42+ testFailureResolver (t )
3943 })
4044}
4145
@@ -439,6 +443,79 @@ func testGenerateUniqueTimestamps(t *testing.T) {
439443 })
440444}
441445
446+ func testFailureLexer (t * testing.T ) {
447+ t .Run ("with lexer error" , func (t * testing.T ) {
448+ stateData := []byte (`routes:
449+ running:
450+ - destination: 0.0.0.0/0
451+ next-hop-address: 192.168.100.1
452+ next-hop-interface: eth1
453+ table-id: 254
454+ ` )
455+
456+ policySpec := types.PolicySpec {
457+ Capture : map [string ]string {
458+ "cap1" : `routes.running.destination==-"0.0.0.0/0"` ,
459+ },
460+ DesiredState : stateData ,
461+ }
462+ _ , err := nmpolicy .GenerateState (policySpec , stateData , types.CachedState {})
463+ assert .EqualError (t , err , `failed to generate state, err: failed to resolve capture expression, err: illegal rune -
464+ | routes.running.destination==-"0.0.0.0/0"
465+ | ............................^` )
466+ })
467+ }
468+
469+ func testFailureParser (t * testing.T ) {
470+ t .Run ("with parser error" , func (t * testing.T ) {
471+ stateData := []byte (`routes:
472+ running:
473+ - destination: 0.0.0.0/0
474+ next-hop-address: 192.168.100.1
475+ next-hop-interface: eth1
476+ table-id: 254
477+ ` )
478+
479+ policySpec := types.PolicySpec {
480+ Capture : map [string ]string {
481+ "cap1" : `routes.running.destination=="0.0.0.0/0" |` ,
482+ },
483+ DesiredState : stateData ,
484+ }
485+ _ , err := nmpolicy .GenerateState (policySpec , stateData , types.CachedState {})
486+ assert .EqualError (t , err ,
487+ "failed to generate state, err: failed to resolve capture expression, " +
488+ "err: invalid pipe: only paths can be piped in" + `
489+ | routes.running.destination=="0.0.0.0/0" |
490+ | ........................................^` )
491+ })
492+ }
493+
494+ func testFailureResolver (t * testing.T ) {
495+ t .Run ("with resolver error" , func (t * testing.T ) {
496+ stateData := []byte (`routes:
497+ running:
498+ - destination: 0.0.0.0/0
499+ next-hop-address: 192.168.100.1
500+ next-hop-interface: eth1
501+ table-id: 254
502+ ` )
503+
504+ policySpec := types.PolicySpec {
505+ Capture : map [string ]string {
506+ "cap1" : `interfaces | routes.running.destination=="0.0.0.0/0"` ,
507+ },
508+ DesiredState : stateData ,
509+ }
510+ _ , err := nmpolicy .GenerateState (policySpec , stateData , types.CachedState {})
511+ assert .EqualError (t , err ,
512+ "failed to generate state, err: failed to resolve capture expression, " +
513+ "err: resolve error: eqfilter error: invalid path input source, only capture reference is supported" + `
514+ | interfaces | routes.running.destination=="0.0.0.0/0"
515+ | .......................................^` )
516+ })
517+ }
518+
442519func resetTimeStamp (generatedState types.GeneratedState ) types.GeneratedState {
443520 generatedState .MetaInfo .TimeStamp = time.Time {}
444521 for captureID , captureState := range generatedState .Cache .Capture {
0 commit comments