@@ -42,6 +42,12 @@ func TestConfig(t *testing.T) {
42
42
false ,
43
43
defaultCfg (),
44
44
},
45
+ {
46
+
47
+ "extra_field" ,
48
+ false ,
49
+ defaultCfg (),
50
+ },
45
51
{
46
52
"id_custom" ,
47
53
false ,
@@ -83,6 +89,11 @@ func TestConfig(t *testing.T) {
83
89
return cfg
84
90
}(),
85
91
},
92
+ {
93
+ "include_invalid" ,
94
+ true ,
95
+ nil ,
96
+ },
86
97
{
87
98
"exclude_one" ,
88
99
false ,
@@ -123,6 +134,11 @@ func TestConfig(t *testing.T) {
123
134
return cfg
124
135
}(),
125
136
},
137
+ {
138
+ "exclude_invalid" ,
139
+ true ,
140
+ nil ,
141
+ },
126
142
{
127
143
"poll_interval_no_units" ,
128
144
false ,
@@ -204,28 +220,277 @@ func TestConfig(t *testing.T) {
204
220
return cfg
205
221
}(),
206
222
},
223
+ {
224
+ "fingerprint_size_float" ,
225
+ false ,
226
+ func () * InputConfig {
227
+ cfg := defaultCfg ()
228
+ cfg .FingerprintSize = helper .ByteSize (1100 )
229
+ return cfg
230
+ }(),
231
+ },
232
+ {
233
+ "include_file_name_lower" ,
234
+ false ,
235
+ func () * InputConfig {
236
+ cfg := defaultCfg ()
237
+ cfg .Include = append (cfg .Include , "one.log" )
238
+ cfg .IncludeFileName = true
239
+ return cfg
240
+ }(),
241
+ },
242
+ {
243
+ "include_file_name_upper" ,
244
+ false ,
245
+ func () * InputConfig {
246
+ cfg := defaultCfg ()
247
+ cfg .Include = append (cfg .Include , "one.log" )
248
+ cfg .IncludeFileName = true
249
+ return cfg
250
+ }(),
251
+ },
252
+ {
253
+ "include_file_name_on" ,
254
+ false ,
255
+ func () * InputConfig {
256
+ cfg := defaultCfg ()
257
+ cfg .Include = append (cfg .Include , "one.log" )
258
+ cfg .IncludeFileName = true
259
+ return cfg
260
+ }(),
261
+ },
262
+ {
263
+ "include_file_name_yes" ,
264
+ false ,
265
+ func () * InputConfig {
266
+ cfg := defaultCfg ()
267
+ cfg .Include = append (cfg .Include , "one.log" )
268
+ cfg .IncludeFileName = true
269
+ return cfg
270
+ }(),
271
+ },
272
+ {
273
+ "include_file_path_lower" ,
274
+ false ,
275
+ func () * InputConfig {
276
+ cfg := defaultCfg ()
277
+ cfg .Include = append (cfg .Include , "one.log" )
278
+ cfg .IncludeFilePath = true
279
+ return cfg
280
+ }(),
281
+ },
282
+ {
283
+ "include_file_path_upper" ,
284
+ false ,
285
+ func () * InputConfig {
286
+ cfg := defaultCfg ()
287
+ cfg .Include = append (cfg .Include , "one.log" )
288
+ cfg .IncludeFilePath = true
289
+ return cfg
290
+ }(),
291
+ },
292
+ {
293
+ "include_file_path_on" ,
294
+ false ,
295
+ func () * InputConfig {
296
+ cfg := defaultCfg ()
297
+ cfg .Include = append (cfg .Include , "one.log" )
298
+ cfg .IncludeFilePath = true
299
+ return cfg
300
+ }(),
301
+ },
302
+ {
303
+ "include_file_path_yes" ,
304
+ false ,
305
+ func () * InputConfig {
306
+ cfg := defaultCfg ()
307
+ cfg .Include = append (cfg .Include , "one.log" )
308
+ cfg .IncludeFilePath = true
309
+ return cfg
310
+ }(),
311
+ },
312
+ {
313
+ "include_file_path_off" ,
314
+ false ,
315
+ func () * InputConfig {
316
+ cfg := defaultCfg ()
317
+ cfg .Include = append (cfg .Include , "one.log" )
318
+ cfg .IncludeFilePath = false
319
+ return cfg
320
+ }(),
321
+ },
322
+ {
323
+ "include_file_path_no" ,
324
+ false ,
325
+ func () * InputConfig {
326
+ cfg := defaultCfg ()
327
+ cfg .Include = append (cfg .Include , "one.log" )
328
+ cfg .IncludeFilePath = false
329
+ return cfg
330
+ }(),
331
+ },
332
+ {
333
+ "include_file_path_nonbool" ,
334
+ true ,
335
+ nil ,
336
+ },
337
+ {
338
+ "multiline_line_start_string" ,
339
+ false ,
340
+ func () * InputConfig {
341
+ cfg := defaultCfg ()
342
+ var newMulti * MultilineConfig
343
+ newMulti = new (MultilineConfig )
344
+ newMulti .LineStartPattern = "Start"
345
+ cfg .Multiline = newMulti
346
+ return cfg
347
+ }(),
348
+ },
349
+ {
350
+ "multiline_line_start_special" ,
351
+ false ,
352
+ func () * InputConfig {
353
+ cfg := defaultCfg ()
354
+ var newMulti * MultilineConfig
355
+ newMulti = new (MultilineConfig )
356
+ newMulti .LineStartPattern = "%"
357
+ cfg .Multiline = newMulti
358
+ return cfg
359
+ }(),
360
+ },
361
+ {
362
+ "multiline_line_end_string" ,
363
+ false ,
364
+ func () * InputConfig {
365
+ cfg := defaultCfg ()
366
+ var newMulti * MultilineConfig
367
+ newMulti = new (MultilineConfig )
368
+ newMulti .LineEndPattern = "Start"
369
+ cfg .Multiline = newMulti
370
+ return cfg
371
+ }(),
372
+ },
373
+ {
374
+ "multiline_line_end_special" ,
375
+ false ,
376
+ func () * InputConfig {
377
+ cfg := defaultCfg ()
378
+ var newMulti * MultilineConfig
379
+ newMulti = new (MultilineConfig )
380
+ newMulti .LineEndPattern = "%"
381
+ cfg .Multiline = newMulti
382
+ return cfg
383
+ }(),
384
+ },
385
+ {
386
+ "multiline_random" ,
387
+ true ,
388
+ nil ,
389
+ },
390
+ {
391
+ "start_at_string" ,
392
+ false ,
393
+ func () * InputConfig {
394
+ cfg := defaultCfg ()
395
+ cfg .StartAt = "beginning"
396
+ return cfg
397
+ }(),
398
+ },
399
+ {
400
+ "max_concurrent_large" ,
401
+ false ,
402
+ func () * InputConfig {
403
+ cfg := defaultCfg ()
404
+ cfg .MaxConcurrentFiles = 9223372036854775807
405
+ return cfg
406
+ }(),
407
+ },
408
+ {
409
+ "max_log_size_mib_lower" ,
410
+ false ,
411
+ func () * InputConfig {
412
+ cfg := defaultCfg ()
413
+ cfg .MaxLogSize = helper .ByteSize (1048576 )
414
+ return cfg
415
+ }(),
416
+ },
417
+ {
418
+ "max_log_size_mib_upper" ,
419
+ false ,
420
+ func () * InputConfig {
421
+ cfg := defaultCfg ()
422
+ cfg .MaxLogSize = helper .ByteSize (1048576 )
423
+ return cfg
424
+ }(),
425
+ },
426
+ {
427
+ "max_log_size_mb_upper" ,
428
+ false ,
429
+ func () * InputConfig {
430
+ cfg := defaultCfg ()
431
+ cfg .MaxLogSize = helper .ByteSize (1048576 )
432
+ return cfg
433
+ }(),
434
+ },
435
+ {
436
+ "max_log_size_mb_lower" ,
437
+ false ,
438
+ func () * InputConfig {
439
+ cfg := defaultCfg ()
440
+ cfg .MaxLogSize = helper .ByteSize (1048576 )
441
+ return cfg
442
+ }(),
443
+ },
444
+ {
445
+ "max_log_size_invalid_unit" ,
446
+ true ,
447
+ nil ,
448
+ },
449
+ {
450
+ "encoding_lower" ,
451
+ false ,
452
+ func () * InputConfig {
453
+ cfg := defaultCfg ()
454
+ cfg .Encoding = "utf-16le"
455
+ return cfg
456
+ }(),
457
+ },
458
+ {
459
+ "encoding_upper" ,
460
+ false ,
461
+ func () * InputConfig {
462
+ cfg := defaultCfg ()
463
+ cfg .Encoding = "UTF-16lE"
464
+ return cfg
465
+ }(),
466
+ },
207
467
}
208
468
209
469
for _ , tc := range cases {
210
470
t .Run (tc .name , func (t * testing.T ) {
211
- cfgFromYaml , err := configFromFileViaYaml (path .Join ("." , "testdata" , fmt .Sprintf ("%s.yaml" , tc .name )))
212
- require .NoError (t , err )
213
- require .Equal (t , tc .expect , cfgFromYaml )
214
- cfgFromMapstructure , err := configFromFileViaMapstructure (path .Join ("." , "testdata" , fmt .Sprintf ("%s.yaml" , tc .name )))
215
- require .NoError (t , err )
216
- require .Equal (t , tc .expect , cfgFromMapstructure )
471
+ cfgFromYaml , yamlErr := configFromFileViaYaml (t , path .Join ("." , "testdata" , fmt .Sprintf ("%s.yaml" , tc .name )))
472
+ cfgFromMapstructure , mapErr := configFromFileViaMapstructure (path .Join ("." , "testdata" , fmt .Sprintf ("%s.yaml" , tc .name )))
473
+ if tc .expectErr {
474
+ require .Error (t , yamlErr )
475
+ require .Error (t , mapErr )
476
+ } else {
477
+ require .NoError (t , yamlErr )
478
+ require .Equal (t , tc .expect , cfgFromYaml )
479
+ require .NoError (t , mapErr )
480
+ require .Equal (t , tc .expect , cfgFromMapstructure )
481
+ }
217
482
})
218
483
}
219
484
}
220
485
221
- func configFromFileViaYaml (file string ) (* InputConfig , error ) {
486
+ func configFromFileViaYaml (t * testing. T , file string ) (* InputConfig , error ) {
222
487
bytes , err := ioutil .ReadFile (file )
223
488
if err != nil {
224
489
return nil , fmt .Errorf ("could not find config file: %s" , err )
225
490
}
226
491
227
- config := NewInputConfig ( "file_input" )
228
- if err := yaml .UnmarshalStrict (bytes , config ); err != nil {
492
+ config := defaultCfg ( )
493
+ if err := yaml .Unmarshal (bytes , config ); err != nil {
229
494
return nil , fmt .Errorf ("failed to read config file as yaml: %s" , err )
230
495
}
231
496
@@ -280,10 +545,8 @@ func TestMapStructureDecodeConfigWithHook(t *testing.T) {
280
545
"id" : "config_test" ,
281
546
"type" : "file_input" ,
282
547
"write_to" : "$" ,
283
- "labels" : map [string ]interface {}{
284
- },
285
- "resource" : map [string ]interface {}{
286
- },
548
+ "labels" : map [string ]interface {}{},
549
+ "resource" : map [string ]interface {}{},
287
550
288
551
"include" : expect .Include ,
289
552
"exclude" : expect .Exclude ,
@@ -317,12 +580,10 @@ func TestMapStructureDecodeConfig(t *testing.T) {
317
580
"id" : "config_test" ,
318
581
"type" : "file_input" ,
319
582
"write_to" : entry .NewRecordField ([]string {}... ),
320
- "labels" : map [string ]interface {}{
321
- },
322
- "resource" : map [string ]interface {}{
323
- },
324
- "include" : expect .Include ,
325
- "exclude" : expect .Exclude ,
583
+ "labels" : map [string ]interface {}{},
584
+ "resource" : map [string ]interface {}{},
585
+ "include" : expect .Include ,
586
+ "exclude" : expect .Exclude ,
326
587
"poll_interval" : map [string ]interface {}{
327
588
"Duration" : 200 * 1000 * 1000 ,
328
589
},
0 commit comments