(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestParserConfigs(t *testing.T) { |
| 10 | pctx, err := NewUnixParserCtx("../../config/patterns/", "./testdata/") |
| 11 | if err != nil { |
| 12 | t.Fatalf("unable to load patterns : %s", err) |
| 13 | } |
| 14 | |
| 15 | // the actual tests |
| 16 | var CfgTests = []struct { |
| 17 | cfg NodeConfig |
| 18 | compiles bool |
| 19 | valid bool |
| 20 | }{ |
| 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{ |
| 41 | {Key: string("SUBGROK"), Value: string("[a-z]")}, |
| 42 | {Key: string("MYGROK"), Value: string("[a-z]%{SUBGROK}")}, |
| 43 | }, Grok: GrokPattern{RegexpValue: "^x%{MYGROK:extr}$", TargetField: "t"}}, true, true}, |
| 44 | // node with broken grok pattern dependencies |
| 45 | {NodeConfig{Debug: true, Stage: "s00", SubGroks: yaml.MapSlice{ |
| 46 | {Key: string("SUBGROKBIS"), Value: string("[a-z]%{MYGROKBIS}")}, |
| 47 | {Key: string("MYGROKBIS"), Value: string("[a-z]")}, |
| 48 | }, Grok: GrokPattern{RegexpValue: "^x%{MYGROKBIS:extr}$", TargetField: "t"}}, false, true}, |
| 49 | } |
| 50 | |
| 51 | for idx, tc := range CfgTests { |
| 52 | node := &Node{NodeConfig: tc.cfg} |
| 53 | err := node.compile(pctx, EnricherCtx{}) |
| 54 | if tc.compiles && err != nil { |
| 55 | t.Fatalf("Compile: (%d/%d) expected valid, got : %s", idx+1, len(CfgTests), err) |
| 56 | } |
| 57 | |
| 58 | if !tc.compiles && err == nil { |
| 59 | t.Fatalf("Compile: (%d/%d) expected error", idx+1, len(CfgTests)) |
| 60 | } |
| 61 | |
| 62 | err = node.validate(EnricherCtx{}) |
| 63 | if tc.valid && err != nil { |
| 64 | t.Fatalf("Valid: (%d/%d) expected valid, got : %s", idx+1, len(CfgTests), err) |
| 65 | } |
| 66 |
nothing calls this directly
no test coverage detected
searching dependent graphs…