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

Function TestTruncatedJSON

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

Source from the content-addressed store, hash-verified

111}
112
113func TestTruncatedJSON(t *testing.T) {
114 err := godotenv.Load("../.env")
115 require.NoError(t, err)
116
117 path := "../test_data/truncated/conn_json.log"
118 entries := make(chan zeektypes.Conn)
119 errc := make(chan error)
120 metaDBChan := make(chan MetaDBFile)
121
122 // get the current time in microseconds
123 start := time.Now().UTC().UnixMicro()
124
125 // create a unique import id using the start time
126 importID, err := util.NewFixedStringHash(strconv.FormatInt(start, 10))
127 require.NoError(t, err)
128
129 go func() {
130 parseFile(afero.NewOsFs(), path, entries, errc, metaDBChan, "test", importID)
131 close(errc)
132 close(entries)
133 close(metaDBChan)
134 }()
135
136 receivedTruncatedErr := false
137 openChannels := 3
138 for openChannels > 0 {
139 select {
140 case _, ok := <-entries:
141 if !ok {
142 openChannels--
143 }
144 case _, ok := <-metaDBChan:
145 if !ok {
146 openChannels--
147 }
148 case err, ok := <-errc:
149 if !ok {
150 openChannels--
151 } else if errors.Is(err, errTruncated) {
152 receivedTruncatedErr = true
153 }
154
155 }
156 }
157
158 require.True(t, receivedTruncatedErr)
159
160}
161
162func TestHasUnknownFieldTSV(t *testing.T) {
163 err := godotenv.Load("../.env")

Callers

nothing calls this directly

Calls 2

NewFixedStringHashFunction · 0.92
parseFileFunction · 0.85

Tested by

no test coverage detected