-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
timestamps_test.go
57 lines (53 loc) · 1.15 KB
/
timestamps_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package telemetry
import (
"reflect"
"testing"
"time"
"github.com/gogo/protobuf/proto"
pr "github.com/influxdata/influxdb/v2/prometheus"
dto "github.com/prometheus/client_model/go"
)
func goodMetricWithTime() *dto.MetricFamily {
return &dto.MetricFamily{
Name: proto.String("good"),
Type: dto.MetricType_COUNTER.Enum(),
Metric: []*dto.Metric{
&dto.Metric{
Label: []*dto.LabelPair{pr.L("n1", "v1")},
Counter: &dto.Counter{
Value: proto.Float64(1.0),
},
TimestampMs: proto.Int64(1),
},
},
}
}
func TestAddTimestamps(t *testing.T) {
type args struct {
mfs []*dto.MetricFamily
now func() time.Time
}
tests := []struct {
name string
args args
}{
{
args: args{
mfs: []*dto.MetricFamily{goodMetric()},
now: func() time.Time { return time.Unix(0, int64(time.Millisecond)) },
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ts := AddTimestamps{
now: tt.args.now,
}
got := ts.Transform(tt.args.mfs)
want := []*dto.MetricFamily{goodMetricWithTime()}
if !reflect.DeepEqual(got, want) {
t.Errorf("AddTimestamps.Transform() = %v, want %v", got, want)
}
})
}
}