@@ -19,12 +19,14 @@ import (
19
19
"testing"
20
20
"time"
21
21
22
+ "github.com/stretchr/testify/mock"
23
+ "github.com/stretchr/testify/require"
24
+ "gopkg.in/yaml.v2"
25
+
22
26
"github.com/open-telemetry/opentelemetry-log-collection/entry"
23
27
"github.com/open-telemetry/opentelemetry-log-collection/operator"
24
28
"github.com/open-telemetry/opentelemetry-log-collection/operator/helper"
25
29
"github.com/open-telemetry/opentelemetry-log-collection/testutil"
26
- "github.com/stretchr/testify/mock"
27
- "github.com/stretchr/testify/require"
28
30
)
29
31
30
32
func TestIsZero (t * testing.T ) {
@@ -442,3 +444,39 @@ func parseTimeTestConfig(layoutType, layout string, parseFrom entry.Field) *Time
442
444
}
443
445
return cfg
444
446
}
447
+
448
+ func TestTimeParserConfig (t * testing.T ) {
449
+ expect := parseTimeTestConfig (helper .GotimeKey , "Mon Jan 2 15:04:05 MST 2006" , entry .NewRecordField ("from" ))
450
+ t .Run ("mapstructure" , func (t * testing.T ) {
451
+ input := map [string ]interface {}{
452
+ "id" : "test_operator_id" ,
453
+ "type" : "time_parser" ,
454
+ "output" : []string {"output1" },
455
+ "on_error" : "send" ,
456
+ "layout" : "Mon Jan 2 15:04:05 MST 2006" ,
457
+ "layout_type" : "gotime" ,
458
+ "parse_from" : "$.from" ,
459
+ }
460
+ var actual TimeParserConfig
461
+ err := helper .UnmarshalMapstructure (input , & actual )
462
+ require .NoError (t , err )
463
+ require .Equal (t , expect , & actual )
464
+ })
465
+
466
+ t .Run ("yaml" , func (t * testing.T ) {
467
+ input := `
468
+ type: time_parser
469
+ id: test_operator_id
470
+ on_error: "send"
471
+ parse_from: $.from
472
+ layout_type: gotime
473
+ layout: "Mon Jan 2 15:04:05 MST 2006"
474
+ output:
475
+ - output1
476
+ `
477
+ var actual TimeParserConfig
478
+ err := yaml .Unmarshal ([]byte (input ), & actual )
479
+ require .NoError (t , err )
480
+ require .Equal (t , expect , & actual )
481
+ })
482
+ }
0 commit comments