Skip to content

Commit a745dc3

Browse files
jonnyzzzclaude
andcommitted
ci: use strings.ReplaceAll (staticcheck QF1004)
strings.Replace(s, old, new, -1) is idiomatically strings.ReplaceAll. golangci-lint's staticcheck flags it; this was the last remaining blocker after enabling v2.11. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e010b46 commit a745dc3

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

internal/caddy/generator_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,35 @@ func TestTemplateFunctions(t *testing.T) {
208208
}
209209
}
210210

211+
func TestWriteFileIfChanged(t *testing.T) {
212+
tmpDir := t.TempDir()
213+
path := filepath.Join(tmpDir, "Caddyfile")
214+
215+
changed, err := writeFileIfChanged(path, []byte("first"))
216+
if err != nil {
217+
t.Fatalf("writeFileIfChanged failed: %v", err)
218+
}
219+
if !changed {
220+
t.Fatal("expected initial write to be reported as changed")
221+
}
222+
223+
changed, err = writeFileIfChanged(path, []byte("first"))
224+
if err != nil {
225+
t.Fatalf("writeFileIfChanged failed: %v", err)
226+
}
227+
if changed {
228+
t.Fatal("expected identical content to report unchanged")
229+
}
230+
231+
changed, err = writeFileIfChanged(path, []byte("second"))
232+
if err != nil {
233+
t.Fatalf("writeFileIfChanged failed: %v", err)
234+
}
235+
if !changed {
236+
t.Fatal("expected different content to report changed")
237+
}
238+
}
239+
211240
func TestGenerateContent_HealthCheckHTTP(t *testing.T) {
212241
cfg := &config.Config{
213242
Domain: "example.com",
@@ -359,6 +388,6 @@ handle @{{.Subdomain}} {
359388
b.ResetTimer()
360389
for i := 0; i < b.N; i++ {
361390
// Template parsing and execution
362-
_ = strings.Replace(tmplContent, "{{.Domain}}", data.Domain, -1)
391+
_ = strings.ReplaceAll(tmplContent, "{{.Domain}}", data.Domain)
363392
}
364393
}

0 commit comments

Comments
 (0)