mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 16:36:27 +01:00
04a304fd39
This simplifies debugging tests and makes the test code more clear and concise.
See https://itnext.io/f-tests-as-a-replacement-for-table-driven-tests-in-go-8814a8b19e9e
While at is, consistently use t.Fatal* instead of t.Error* across tests, since t.Error*
requires more boilerplate code, which can result in additional bugs inside tests.
While t.Error* allows writing logging errors for the same, this doesn't simplify fixing
broken tests most of the time.
This is a follow-up for a9525da8a4
32 lines
609 B
Go
32 lines
609 B
Go
package prometheus
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestInRange(t *testing.T) {
|
|
f := func(filterMin, filterMax, blockMin, blockMax int64, resultExpected bool) {
|
|
t.Helper()
|
|
|
|
f := filter{
|
|
min: filterMin,
|
|
max: filterMax,
|
|
}
|
|
result := f.inRange(blockMin, blockMax)
|
|
if result != resultExpected {
|
|
t.Fatalf("unexpected result; got %v; want %v", result, resultExpected)
|
|
}
|
|
}
|
|
|
|
f(0, 0, 1, 2, true)
|
|
f(0, 3, 1, 2, true)
|
|
f(0, 3, 4, 5, false)
|
|
f(3, 0, 1, 2, false)
|
|
f(3, 0, 2, 4, true)
|
|
f(3, 10, 1, 2, false)
|
|
f(3, 10, 1, 4, true)
|
|
f(3, 10, 5, 9, true)
|
|
f(3, 10, 9, 12, true)
|
|
f(3, 10, 12, 15, false)
|
|
}
|