@@ -12,58 +12,59 @@ func TestParserConfigs(t *testing.T) {
1212 t .Fatalf ("unable to load patterns : %s" , err )
1313 }
1414
15- /* the actual tests*/
15+ // the actual tests
1616 var CfgTests = []struct {
17- NodeCfg * Node
18- Compiles bool
19- Valid bool
17+ cfg NodeConfig
18+ compiles bool
19+ valid bool
2020 }{
21- //valid node with grok pattern
22- {& Node {Debug : true , Stage : "s00" , Grok : GrokPattern {RegexpValue : "^x%{DATA:extr}$" , TargetField : "t" }}, true , true },
23- //bad filter
24- {& Node {Debug : true , Stage : "s00" , Filter : "ratata" }, false , false },
25- //empty node
26- {& Node {Debug : true , Stage : "s00" , Filter : "true" }, false , false },
27- //bad subgrok
28- {& Node {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {{Key : string ("FOOBAR" ), Value : string ("[a-$" )}}}, false , true },
29- //valid node with grok pattern
30- {& Node {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {{Key : string ("FOOBAR" ), Value : string ("[a-z]" )}}, Grok : GrokPattern {RegexpValue : "^x%{FOOBAR:extr}$" , TargetField : "t" }}, true , true },
31- //bad node success
32- {& Node {Debug : true , Stage : "s00" , OnSuccess : "ratat" , Grok : GrokPattern {RegexpValue : "^x%{DATA:extr}$" , TargetField : "t" }}, false , false },
33- //ok node success
34- {& Node {Debug : true , Stage : "s00" , OnSuccess : "continue" , Grok : GrokPattern {RegexpValue : "^x%{DATA:extr}$" , TargetField : "t" }}, true , true },
35- //valid node with grok sub-pattern used by name
36- {& Node {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {{Key : string ("FOOBARx" ), Value : string ("[a-z] %{DATA:lol}$" )}}, Grok : GrokPattern {RegexpName : "FOOBARx" , TargetField : "t" }}, true , true },
37- //node with unexisting grok pattern
38- {& Node {Debug : true , Stage : "s00" , Grok : GrokPattern {RegexpName : "RATATA" , TargetField : "t" }}, false , true },
39- //node with grok pattern dependencies
40- {& Node {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {
21+ // valid node with grok pattern
22+ {NodeConfig {Debug : true , Stage : "s00" , Grok : GrokPattern {RegexpValue : "^x%{DATA:extr}$" , TargetField : "t" }}, true , true },
23+ // bad filter
24+ {NodeConfig {Debug : true , Stage : "s00" , Filter : "ratata" }, false , false },
25+ // empty node
26+ {NodeConfig {Debug : true , Stage : "s00" , Filter : "true" }, false , false },
27+ // bad subgrok
28+ {NodeConfig {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {{Key : string ("FOOBAR" ), Value : string ("[a-$" )}}}, false , true },
29+ // valid node with grok pattern
30+ {NodeConfig {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {{Key : string ("FOOBAR" ), Value : string ("[a-z]" )}}, Grok : GrokPattern {RegexpValue : "^x%{FOOBAR:extr}$" , TargetField : "t" }}, true , true },
31+ // bad node success
32+ {NodeConfig {Debug : true , Stage : "s00" , OnSuccess : "ratat" , Grok : GrokPattern {RegexpValue : "^x%{DATA:extr}$" , TargetField : "t" }}, false , false },
33+ // ok node success
34+ {NodeConfig {Debug : true , Stage : "s00" , OnSuccess : "continue" , Grok : GrokPattern {RegexpValue : "^x%{DATA:extr}$" , TargetField : "t" }}, true , true },
35+ // valid node with grok sub-pattern used by name
36+ {NodeConfig {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {{Key : string ("FOOBARx" ), Value : string ("[a-z] %{DATA:lol}$" )}}, Grok : GrokPattern {RegexpName : "FOOBARx" , TargetField : "t" }}, true , true },
37+ // node with unexisting grok pattern
38+ {NodeConfig {Debug : true , Stage : "s00" , Grok : GrokPattern {RegexpName : "RATATA" , TargetField : "t" }}, false , true },
39+ // node with grok pattern dependencies
40+ {NodeConfig {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {
4141 {Key : string ("SUBGROK" ), Value : string ("[a-z]" )},
4242 {Key : string ("MYGROK" ), Value : string ("[a-z]%{SUBGROK}" )},
4343 }, Grok : GrokPattern {RegexpValue : "^x%{MYGROK:extr}$" , TargetField : "t" }}, true , true },
44- //node with broken grok pattern dependencies
45- {& Node {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {
44+ // node with broken grok pattern dependencies
45+ {NodeConfig {Debug : true , Stage : "s00" , SubGroks : yaml.MapSlice {
4646 {Key : string ("SUBGROKBIS" ), Value : string ("[a-z]%{MYGROKBIS}" )},
4747 {Key : string ("MYGROKBIS" ), Value : string ("[a-z]" )},
4848 }, Grok : GrokPattern {RegexpValue : "^x%{MYGROKBIS:extr}$" , TargetField : "t" }}, false , true },
4949 }
5050
51- for idx := range CfgTests {
52- err := CfgTests [idx ].NodeCfg .compile (pctx , EnricherCtx {})
53- if CfgTests [idx ].Compiles && err != nil {
51+ for idx , tc := range CfgTests {
52+ node := & Node {NodeConfig : tc .cfg }
53+ err := node .compile (pctx , EnricherCtx {})
54+ if tc .compiles && err != nil {
5455 t .Fatalf ("Compile: (%d/%d) expected valid, got : %s" , idx + 1 , len (CfgTests ), err )
5556 }
5657
57- if ! CfgTests [ idx ]. Compiles && err == nil {
58+ if ! tc . compiles && err == nil {
5859 t .Fatalf ("Compile: (%d/%d) expected error" , idx + 1 , len (CfgTests ))
5960 }
6061
61- err = CfgTests [ idx ]. NodeCfg .validate (EnricherCtx {})
62- if CfgTests [ idx ]. Valid && err != nil {
62+ err = node .validate (EnricherCtx {})
63+ if tc . valid && err != nil {
6364 t .Fatalf ("Valid: (%d/%d) expected valid, got : %s" , idx + 1 , len (CfgTests ), err )
6465 }
6566
66- if ! CfgTests [ idx ]. Valid && err == nil {
67+ if ! tc . valid && err == nil {
6768 t .Fatalf ("Valid: (%d/%d) expected error" , idx + 1 , len (CfgTests ))
6869 }
6970 }
0 commit comments