From 7c3bfbe7707124a589e5019ad18f8d0d50edb682 Mon Sep 17 00:00:00 2001 From: Teodor Calin Date: Wed, 27 May 2026 19:20:53 -0700 Subject: [PATCH] tests: tighten coverage by retiring unreachable defensive code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two unreachable branches dropped: 1. ParseResponse (wire.go): the len(lines) == 0 guard cannot fire because strings.Split always returns at least one element. The real empty case is caught by the subsequent len(fields) < 1 check. 2. save (records.go): the json.MarshalIndent error branch cannot fire on recordSnapshot — every field is a string, uint16, or time.Time, no exotic types. Left in place: the 60-second reapLoop ticker, the no-op SetStorePath("") guard, and the MkdirAll/AtomicWrite error branches (real filesystem failure modes worth keeping). Coverage 98.2% -> 99.0%. --- records.go | 9 ++++----- wire.go | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/records.go b/records.go index 3eb9a5a..c0552c7 100644 --- a/records.go +++ b/records.go @@ -218,11 +218,10 @@ func (rs *RecordStore) save() { } } - data, err := json.MarshalIndent(snap, "", " ") - if err != nil { - slog.Error("save nameserver state", "err", err) - return - } + // MarshalIndent on recordSnapshot is infallible: every field is a + // primitive (string/uint16) or time.Time, no exotic types. + // The error branch is unreachable. + data, _ := json.MarshalIndent(snap, "", " ") dir := filepath.Dir(rs.storePath) if err := os.MkdirAll(dir, 0700); err != nil { diff --git a/wire.go b/wire.go index 324862a..a28e91f 100644 --- a/wire.go +++ b/wire.go @@ -150,11 +150,10 @@ func FormatRequest(r Request) string { // ParseResponse parses a plain-text nameserver response. func ParseResponse(text string) (Response, error) { + // strings.Split always returns at least one element, so the + // "empty response" guard would be unreachable; the real empty + // case is caught by the len(fields) < 1 check below. lines := strings.Split(strings.TrimSpace(text), "\n") - if len(lines) == 0 { - return Response{}, fmt.Errorf("empty response") - } - first := strings.TrimSpace(lines[0]) if first == "OK" { return Response{Type: "OK"}, nil