Clean up code reuse, consistency, and efficiency issues

Merge readExistingSerial and readExistingContent into a single
readExisting function to eliminate duplicate file I/O. Extract dateBase
helper to deduplicate serial formula between defaultSerial and
bumpSerial. Cache hash results during collision check to avoid
recomputing per member. Normalize error prefixes (remove "error:" from
fmt.Errorf, add uniformly at print sites). Use filepath.Join instead of
manual "/" concatenation. Replace trivial containsStr wrapper with
strings.Contains. Simplify tokenize to a single return. Use writeTestFile
and fixedTime helpers consistently in tests.
This commit is contained in:
2026-03-01 17:38:26 -08:00
parent 1f2f39f40c
commit 0a460b975d
7 changed files with 75 additions and 117 deletions

View File

@@ -1,7 +1,6 @@
package main
import (
"os"
"path/filepath"
"testing"
)
@@ -206,9 +205,7 @@ zone.example.org catalog1, catalog2
test.example.net catalog1, group=internal
`
if err := os.WriteFile(inputPath, []byte(content), 0o644); err != nil {
t.Fatal(err)
}
writeTestFile(t, dir, "zones.txt", content)
members, err := parseInput(inputPath, cfg)
if err != nil {
@@ -240,9 +237,7 @@ func TestParseInputErrors(t *testing.T) {
t.Run("invalid line in input", func(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "zones.txt")
if err := os.WriteFile(path, []byte("zone-with-no-catalog\n"), 0o644); err != nil {
t.Fatal(err)
}
writeTestFile(t, dir, "zones.txt", "zone-with-no-catalog\n")
_, err := parseInput(path, cfg)
if err == nil {
t.Fatal("expected error for invalid line")