MCPcopy Create free account
hub / github.com/activecm/rita / TestPlainTextFile

Function TestPlainTextFile

importer/parser_test.go:216–265  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

214}
215
216func TestPlainTextFile(t *testing.T) {
217 err := godotenv.Load("../.env")
218 require.NoError(t, err)
219
220 path := "../test_data/text_file/conn.log"
221
222 entries := make(chan zeektypes.Conn)
223 errc := make(chan error)
224 metaDBChan := make(chan MetaDBFile)
225
226 // get the current time in microseconds
227 start := time.Now().UTC().UnixMicro()
228
229 // create a unique import id using the start time
230 importID, err := util.NewFixedStringHash(strconv.FormatInt(start, 10))
231 require.NoError(t, err)
232
233 go func() {
234 parseFile(afero.NewOsFs(), path, entries, errc, metaDBChan, "test", importID)
235 close(errc)
236 close(entries)
237 close(metaDBChan)
238 }()
239
240 receivedErr := false
241 openChannels := 3
242 recordCount := 0
243 for openChannels > 0 {
244 select {
245 case _, ok := <-entries:
246 if !ok {
247 openChannels--
248 } else {
249 recordCount++
250 }
251 case _, ok := <-metaDBChan:
252 if !ok {
253 openChannels--
254 }
255 case err, ok := <-errc:
256 if !ok {
257 openChannels--
258 } else if errors.Is(err, errUnknownFileType) {
259 receivedErr = true
260 }
261
262 }
263 }
264 require.True(t, receivedErr, "should receive unknown file type error")
265}

Callers

nothing calls this directly

Calls 2

NewFixedStringHashFunction · 0.92
parseFileFunction · 0.85

Tested by

no test coverage detected