From c78a4d3b2f6dd6574106e225f272a2e5082f2042 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Wed, 5 Jul 2023 12:44:31 +0300 Subject: [PATCH] Avoid nolint:errcheck in header tests --- header_test.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/header_test.go b/header_test.go index c2b8b18e74..7ae61383b8 100644 --- a/header_test.go +++ b/header_test.go @@ -26,7 +26,9 @@ func TestResponseHeaderAddContentType(t *testing.T) { } var buf bytes.Buffer - h.WriteTo(&buf) //nolint:errcheck + if _, err := h.WriteTo(&buf); err != nil { + t.Fatalf("unexpected error when writing header: %v", err) + } if n := strings.Count(buf.String(), "Content-Type: "); n != 1 { t.Errorf("Content-Type occurred %d times", n) @@ -46,7 +48,9 @@ func TestResponseHeaderAddContentEncoding(t *testing.T) { } var buf bytes.Buffer - h.WriteTo(&buf) //nolint:errcheck + if _, err := h.WriteTo(&buf); err != nil { + t.Fatalf("unexpected error when writing header: %v", err) + } if n := strings.Count(buf.String(), "Content-Encoding: "); n != 1 { t.Errorf("Content-Encoding occurred %d times", n) @@ -138,13 +142,15 @@ func TestResponseHeaderMultiLineName(t *testing.T) { } } -func TestResponseHeaderMultiLinePaniced(t *testing.T) { +func TestResponseHeaderMultiLinePanicked(t *testing.T) { t.Parallel() // Input generated by fuzz testing that caused the parser to panic. s, _ := base64.StdEncoding.DecodeString("aAEAIDoKKDoKICA6CgkKCiA6CiA6CgkpCiA6CiA6CiA6Cig6CiAgOgoJCgogOgogOgoJKQogOgogOgogOgogOgogOgoJOg86CiA6CiA6Cig6CiAyCg==") header := new(RequestHeader) - header.parse(s) //nolint:errcheck + if _, err := header.parse(s); err == nil { + t.Error("expected error, got ") + } } func TestResponseHeaderEmptyValueFromHeader(t *testing.T) { @@ -3021,7 +3027,9 @@ func TestAddVaryHeader(t *testing.T) { } var buf bytes.Buffer - h.WriteTo(&buf) //nolint:errcheck + if _, err := h.WriteTo(&buf); err != nil { + t.Fatalf("unexpected error when writing header: %v", err) + } if n := strings.Count(buf.String(), "Vary: "); n != 1 { t.Errorf("Vary occurred %d times", n) @@ -3042,7 +3050,9 @@ func TestAddVaryHeaderExisting(t *testing.T) { } var buf bytes.Buffer - h.WriteTo(&buf) //nolint:errcheck + if _, err := h.WriteTo(&buf); err != nil { + t.Fatalf("unexpected error when writing header: %v", err) + } if n := strings.Count(buf.String(), "Vary: "); n != 1 { t.Errorf("Vary occurred %d times", n) @@ -3063,7 +3073,9 @@ func TestAddVaryHeaderExistingAcceptEncoding(t *testing.T) { } var buf bytes.Buffer - h.WriteTo(&buf) //nolint:errcheck + if _, err := h.WriteTo(&buf); err != nil { + t.Fatalf("unexpected error when writing header: %v", err) + } if n := strings.Count(buf.String(), "Vary: "); n != 1 { t.Errorf("Vary occurred %d times", n)