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/logproto/timeseries_test.go

67 lines
1.7 KiB

package logproto
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLabelAdapter_Marshal(t *testing.T) {
tests := []struct {
bs *LabelAdapter
}{
{&LabelAdapter{Name: "foo", Value: "bar"}},
{&LabelAdapter{Name: "very long label name", Value: "very long label value"}},
{&LabelAdapter{Name: "", Value: "foo"}},
{&LabelAdapter{}},
}
for _, tt := range tests {
t.Run(tt.bs.Name, func(t *testing.T) {
bytes, err := tt.bs.Marshal()
require.NoError(t, err)
lbs := &LabelAdapter{}
require.NoError(t, lbs.Unmarshal(bytes))
require.EqualValues(t, tt.bs, lbs)
})
}
}
func TestPreallocTimeseriesSliceFromPool(t *testing.T) {
t.Run("new instance is provided when not available to reuse", func(t *testing.T) {
first := PreallocTimeseriesSliceFromPool()
second := PreallocTimeseriesSliceFromPool()
assert.NotSame(t, &first, &second)
})
t.Run("instance is cleaned before reusing", func(t *testing.T) {
slice := PreallocTimeseriesSliceFromPool()
slice = append(slice, PreallocTimeseries{TimeSeries: &TimeSeries{}})
ReuseSlice(slice)
reused := PreallocTimeseriesSliceFromPool()
assert.Len(t, reused, 0)
})
}
func TestTimeseriesFromPool(t *testing.T) {
t.Run("new instance is provided when not available to reuse", func(t *testing.T) {
first := TimeseriesFromPool()
second := TimeseriesFromPool()
assert.NotSame(t, &first, &second)
})
t.Run("instance is cleaned before reusing", func(t *testing.T) {
ts := TimeseriesFromPool()
ts.Labels = []LabelAdapter{{Name: "foo", Value: "bar"}}
ts.Samples = []LegacySample{{Value: 1, TimestampMs: 2}}
ReuseTimeseries(ts)
reused := TimeseriesFromPool()
assert.Len(t, reused.Labels, 0)
assert.Len(t, reused.Samples, 0)
})
}