Skip to content

Commit

Permalink
Avoid nolint:errcheck in header tests (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Jul 6, 2023
1 parent 0d0bbfe commit 064124e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 <nil>")
}
}

func TestResponseHeaderEmptyValueFromHeader(t *testing.T) {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 064124e

Please sign in to comment.