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:
@@ -6,7 +6,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIntegrationEndToEnd(t *testing.T) {
|
||||
@@ -213,7 +212,7 @@ soa:
|
||||
// Find PTR lines and verify order
|
||||
var ptrZones []string
|
||||
for _, line := range lines {
|
||||
if containsStr(line, "\tPTR\t") && !containsStr(line, "coo.") {
|
||||
if strings.Contains(line, "\tPTR\t") && !strings.Contains(line, "coo.") {
|
||||
// Extract the PTR target
|
||||
parts := strings.Split(line, "\t")
|
||||
ptrZones = append(ptrZones, parts[len(parts)-1])
|
||||
@@ -313,9 +312,7 @@ soa:
|
||||
if err == nil {
|
||||
t.Error("expected error for unknown catalog")
|
||||
}
|
||||
if !containsStr(string(out), "unknown catalog") {
|
||||
t.Errorf("expected 'unknown catalog' in error output, got: %s", out)
|
||||
}
|
||||
assertContains(t, string(out), "unknown catalog")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -405,7 +402,7 @@ soa:
|
||||
assertContains(t, content2, "2026011601")
|
||||
|
||||
// Simulate not using the tool for a while, running on a much later date
|
||||
day3 := time.Date(2026, 6, 15, 0, 0, 0, 0, time.UTC)
|
||||
day3 := fixedTime(2026, 6, 15)
|
||||
members3 := []ZoneEntry{
|
||||
{Zone: "a.example.com.", Catalogs: []string{"cat1"}, File: "test", Line: 1},
|
||||
{Zone: "b.example.com.", Catalogs: []string{"cat1"}, File: "test", Line: 2},
|
||||
|
||||
Reference in New Issue
Block a user