55 "fmt"
66 "io/ioutil"
77 "os"
8+ "strings"
89 "testing"
10+ "time"
911
1012 "github.com/influxdata/telegraf"
1113 "github.com/influxdata/telegraf/config"
@@ -47,7 +49,18 @@ func TestMultipleConfigs(t *testing.T) {
4749 // Process expected metrics and compare with resulting metrics
4850 expectedOutputs , err := readMetricFile (fmt .Sprintf ("testdata/%s/expected.out" , f .Name ()))
4951 require .NoError (t , err )
50- testutil .RequireMetricsEqual (t , expectedOutputs , acc .GetTelegrafMetrics (), testutil .IgnoreTime ())
52+ resultingMetrics := acc .GetTelegrafMetrics ()
53+ testutil .RequireMetricsEqual (t , expectedOutputs , resultingMetrics , testutil .IgnoreTime ())
54+
55+ // Folder with timestamp prefixed will also check for matching timestamps to make sure they are parsed correctly
56+ // The milliseconds weren't matching, seemed like a rounding difference between the influx parser
57+ // Compares each metrics times separately and ignores milliseconds
58+ if strings .HasPrefix (f .Name (), "timestamp" ) {
59+ require .Equal (t , len (expectedOutputs ), len (resultingMetrics ))
60+ for i , m := range resultingMetrics {
61+ require .Equal (t , expectedOutputs [i ].Time ().Truncate (time .Second ), m .Time ().Truncate (time .Second ))
62+ }
63+ }
5164 })
5265 }
5366}
@@ -66,6 +79,8 @@ func readMetricFile(path string) ([]telegraf.Metric, error) {
6679 line := scanner .Text ()
6780 if line != "" {
6881 m , err := parser .ParseLine (line )
82+ // The timezone needs to be UTC to match the timestamp test results
83+ m .SetTime (m .Time ().UTC ())
6984 if err != nil {
7085 return nil , fmt .Errorf ("unable to parse metric in %q failed: %v" , line , err )
7186 }
0 commit comments