mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 08:36:55 +03:00
lib: consistently use f-tests instead of table-driven tests
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*.
This commit is contained in:
@@ -135,9 +135,13 @@ func TestAuthKeyMetrics(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHandlerWrapper(t *testing.T) {
|
||||
*headerHSTS = "foo"
|
||||
*headerFrameOptions = "bar"
|
||||
*headerCSP = "baz"
|
||||
const hstsHeader = "foo"
|
||||
const frameOptionsHeader = "bar"
|
||||
const cspHeader = "baz"
|
||||
|
||||
*headerHSTS = hstsHeader
|
||||
*headerFrameOptions = frameOptionsHeader
|
||||
*headerCSP = cspHeader
|
||||
defer func() {
|
||||
*headerHSTS = ""
|
||||
*headerFrameOptions = ""
|
||||
@@ -152,13 +156,14 @@ func TestHandlerWrapper(t *testing.T) {
|
||||
return true
|
||||
})
|
||||
|
||||
if w.Header().Get("Strict-Transport-Security") != "foo" {
|
||||
t.Errorf("HSTS header not set")
|
||||
h := w.Header()
|
||||
if got := h.Get("Strict-Transport-Security"); got != hstsHeader {
|
||||
t.Fatalf("unexpected HSTS header; got %q; want %q", got, hstsHeader)
|
||||
}
|
||||
if w.Header().Get("X-Frame-Options") != "bar" {
|
||||
t.Errorf("X-Frame-Options header not set")
|
||||
if got := h.Get("X-Frame-Options"); got != frameOptionsHeader {
|
||||
t.Fatalf("unexpected X-Frame-Options header; got %q; want %q", got, frameOptionsHeader)
|
||||
}
|
||||
if w.Header().Get("Content-Security-Policy") != "baz" {
|
||||
t.Errorf("CSP header not set")
|
||||
if got := h.Get("Content-Security-Policy"); got != cspHeader {
|
||||
t.Fatalf("unexpected CSP header; got %q; want %q", got, cspHeader)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user