From 3e7b463908c7ce490def575027258d15f8a3b4e7 Mon Sep 17 00:00:00 2001 From: johncming Date: Tue, 25 Aug 2020 23:16:43 +0800 Subject: [PATCH] add testcase for rangeForTimestamp. (#6454) Signed-off-by: johncming --- tsdb/db_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tsdb/db_test.go b/tsdb/db_test.go index 64fb80e75..8617828e2 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -2579,6 +2579,28 @@ func TestChunkWriter_ReadAfterWrite(t *testing.T) { } } +func TestRangeForTimestamp(t *testing.T) { + type args struct { + t int64 + width int64 + } + tests := []struct { + args args + expected int64 + }{ + {args{0, 5}, 5}, + {args{1, 5}, 5}, + {args{5, 5}, 10}, + {args{6, 5}, 10}, + {args{13, 5}, 15}, + {args{95, 5}, 100}, + } + for _, tt := range tests { + got := rangeForTimestamp(tt.args.t, tt.args.width) + testutil.Equals(t, tt.expected, got) + } +} + // TestChunkReader_ConcurrentReads checks that the chunk result can be read concurrently. // Regression test for https://github.com/prometheus/prometheus/pull/6514. func TestChunkReader_ConcurrentReads(t *testing.T) {