mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
cedbbdec30
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
31 lines
609 B
Go
31 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)
|
|
}
|