Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/util/conv_test.go

59 lines
1.2 KiB

package util
import (
"reflect"
"testing"
"time"
"github.com/prometheus/common/model"
)
func TestRoundToMilliseconds(t *testing.T) {
tests := []struct {
name string
from time.Time
through time.Time
wantFrom model.Time
wantThrough model.Time
}{
{
"0",
time.Unix(0, 0),
time.Unix(0, 1),
model.Time(0),
model.Time(1),
},
{
"equal",
time.Unix(0, time.Millisecond.Nanoseconds()),
time.Unix(0, time.Millisecond.Nanoseconds()),
model.Time(1),
model.Time(1),
},
{
"exact",
time.Unix(0, time.Millisecond.Nanoseconds()),
time.Unix(0, 2*time.Millisecond.Nanoseconds()),
model.Time(1),
model.Time(2),
},
{
"rounding",
time.Unix(0, time.Millisecond.Nanoseconds()+10),
time.Unix(0, 2*time.Millisecond.Nanoseconds()+10),
model.Time(1),
model.Time(3),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
from, through := RoundToMilliseconds(tt.from, tt.through)
if !reflect.DeepEqual(from, tt.wantFrom) {
t.Errorf("RoundToMilliseconds() from = %v, want %v", from, tt.wantFrom)
}
if !reflect.DeepEqual(through, tt.wantThrough) {
t.Errorf("RoundToMilliseconds() through = %v, want %v", through, tt.wantThrough)
}
})
}
}