Skip to content

test: add edge case coverage for hasHTTPResponseWriterMethods and matchesWriteSignature #162

Description

@yvonnedevlinrh

Description

Summary

hasHTTPResponseWriterMethods requires all three methods (Header, Write, WriteHeader) with correct signatures to classify a type as http.ResponseWriter. This contract is correct but only tested implicitly — there are no edge case tests that verify partial matches are rejected or that near-miss signatures don't pass.

Missing Test Coverage

1. Partial method set (2 of 3 methods)

A type with Write([]byte) (int, error) and Header() but no WriteHeader should produce WriterOutput (it's an io.Writer) but not HTTPResponseWrite. No test fixture exercises this boundary.

2. Near-miss Write signatures

matchesWriteSignature verifies Write([]byte) (int, error) exactly. The following near-misses should all be rejected, but none are tested:

  • Write([]byte) int — missing error return
  • Write(string) (int, error) — wrong param type
  • Write([]byte) (int64, error) — wrong int type
  • Write([]byte, int) (int, error) — extra param

Suggested Fixtures

// PartialResponseWriter has Write + Header but no WriteHeader.
// Should produce WriterOutput, NOT HTTPResponseWrite.
type PartialResponseWriter struct{}
func (p *PartialResponseWriter) Header() http.Header { return nil }
func (p *PartialResponseWriter) Write(b []byte) (int, error) { return len(b), nil }

func HandlePartialRW(w *PartialResponseWriter) {
    w.Write([]byte("ok"))
}

An internal test file (p1effects_internal_test.go) could also construct synthetic types.Signature values to unit test matchesWriteSignature directly against the near-miss cases without needing full package loading.

Rationale

These are defense-in-depth tests that lock down the contracts established in #109 and #132. The current implementation is correct, but without explicit edge case coverage a future refactor could silently break the boundary conditions.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions