mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
a9525da8a4
This makes easier to read and debug these tests. This also reduces test lines count by 15% from 3K to 2.5K See https://itnext.io/f-tests-as-a-replacement-for-table-driven-tests-in-go-8814a8b19e9e While at it, consistently use t.Fatal* instead of t.Error*, since t.Error* usually leads to more complicated and fragile tests, while it doesn't bring any practical benefits over t.Fatal*.
48 lines
893 B
Go
48 lines
893 B
Go
package snapshotutil
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestValidate_Failure(t *testing.T) {
|
|
f := func(snapshotName string) {
|
|
t.Helper()
|
|
|
|
err := Validate(snapshotName)
|
|
if err == nil {
|
|
t.Fatalf("expecting non-nil error")
|
|
}
|
|
}
|
|
|
|
// empty snapshot name
|
|
f("")
|
|
|
|
// short snapshot name
|
|
f("foo")
|
|
|
|
// short first part of the snapshot name
|
|
f("2022050312163-16EB56ADB4110CF2")
|
|
|
|
// invalid time part snapshot name
|
|
f("00000000000000-16EB56ADB4110CF2")
|
|
|
|
// not enough parts of the snapshot name
|
|
f("2022050312163816EB56ADB4110CF2")
|
|
}
|
|
|
|
func TestValidate_Success(t *testing.T) {
|
|
f := func(snapshotName string) {
|
|
t.Helper()
|
|
|
|
err := Validate(snapshotName)
|
|
if err != nil {
|
|
t.Fatalf("checkSnapshotName() error: %s", err)
|
|
}
|
|
}
|
|
|
|
// short second part of the snapshot name - this is OK
|
|
f("20220503121638-16EB56ADB4110CF")
|
|
|
|
//correct snapshot name
|
|
f("20220503121638-16EB56ADB4110CF2")
|
|
}
|