(t require.TestingT, pctx *UnixParserCtx, ectx EnricherCtx, dir string, b *testing.B)
| 97 | } |
| 98 | |
| 99 | func testOneParser(t require.TestingT, pctx *UnixParserCtx, ectx EnricherCtx, dir string, b *testing.B) error { |
| 100 | var ( |
| 101 | pnodes []Node |
| 102 | parserConfigs []Stagefile |
| 103 | ) |
| 104 | |
| 105 | log.Warningf("testing %s", dir) |
| 106 | |
| 107 | parserCfgFile := filepath.Join(dir, "parsers.yaml") |
| 108 | |
| 109 | cfg, err := os.ReadFile(parserCfgFile) |
| 110 | if err != nil { |
| 111 | return fmt.Errorf("failed opening %s: %w", parserCfgFile, err) |
| 112 | } |
| 113 | |
| 114 | tmpl, err := template.New("test").Parse(string(cfg)) |
| 115 | if err != nil { |
| 116 | return fmt.Errorf("failed to parse template %s: %w", cfg, err) |
| 117 | } |
| 118 | |
| 119 | var out bytes.Buffer |
| 120 | |
| 121 | err = tmpl.Execute(&out, map[string]string{"TestDirectory": dir}) |
| 122 | if err != nil { |
| 123 | panic(err) |
| 124 | } |
| 125 | |
| 126 | if err = yaml.UnmarshalStrict(out.Bytes(), &parserConfigs); err != nil { |
| 127 | return fmt.Errorf("failed to parse %s: %w", parserCfgFile, err) |
| 128 | } |
| 129 | |
| 130 | pnodes, err = LoadStages(parserConfigs, pctx, ectx) |
| 131 | if err != nil { |
| 132 | return fmt.Errorf("unable to load parser config: %w", err) |
| 133 | } |
| 134 | |
| 135 | // TBD: Load post overflows |
| 136 | // func testFile(t *testing.T, file string, pctx UnixParserCtx, nodes []Node) bool { |
| 137 | parserTestFile := filepath.Join(dir, "test.yaml") |
| 138 | tests := loadTestFile(t, parserTestFile) |
| 139 | count := 1 |
| 140 | |
| 141 | if b != nil { |
| 142 | count = b.N |
| 143 | b.ResetTimer() |
| 144 | } |
| 145 | |
| 146 | for range count { |
| 147 | if !testFile(t, tests, *pctx, pnodes) { |
| 148 | return errors.New("test failed") |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | // prepTests is going to do the initialisation of parser : it's going to load enrichment plugins and load the patterns. This is done here so that we don't redo it for each test |
| 156 | func prepTests(t require.TestingT) (*UnixParserCtx, EnricherCtx) { |
no test coverage detected
searching dependent graphs…