github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/tsdb/bounds_test.go (about) 1 package tsdb 2 3 import ( 4 "fmt" 5 "math" 6 "testing" 7 8 "github.com/prometheus/common/model" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestOverlap(t *testing.T) { 13 for i, tc := range []struct { 14 a, b Bounded 15 overlap bool 16 }{ 17 { 18 a: newBounds(1, 5), 19 b: newBounds(2, 6), 20 overlap: true, 21 }, 22 { 23 a: newBounds(1, 5), 24 b: newBounds(6, 7), 25 overlap: false, 26 }, 27 { 28 // ensure [start,end) inclusivity works as expected 29 a: newBounds(1, 5), 30 b: newBounds(5, 6), 31 overlap: false, 32 }, 33 } { 34 t.Run(fmt.Sprint(i), func(t *testing.T) { 35 require.Equal(t, tc.overlap, Overlap(tc.a, tc.b)) 36 }) 37 } 38 } 39 40 func TestInclusiveBounds(t *testing.T) { 41 for i, tc := range []struct { 42 input Bounded 43 lower, upper int64 44 }{ 45 { 46 input: newBounds(0, 4), 47 lower: 0, 48 upper: 5, // increment upper by 1 49 }, 50 { 51 input: newBounds(0, math.MaxInt64), 52 lower: 0, 53 upper: math.MaxInt64, // do nothing since we're already at the maximum value. 54 }, 55 } { 56 t.Run(fmt.Sprint(i), func(t *testing.T) { 57 a, b := inclusiveBounds(tc.input) 58 require.Equal(t, model.Time(tc.lower), a) 59 require.Equal(t, model.Time(tc.upper), b) 60 }) 61 } 62 }