From cc534df68fb1890d40949c57bf95f3bfd9a4c302 Mon Sep 17 00:00:00 2001 From: Mohammed Al Sahaf Date: Sun, 30 Aug 2026 18:38:06 +0300 Subject: [PATCH] caddyfile: tighten makeArgsReplacer empty/nil tests Neither test asserted a real outcome (one compared against an unreachable literal, the other logged then discarded the result). Since Replacer.ReplaceAll substitutes the provided default for unknown placeholders, both cases can be checked with deterministic equality. Signed-off-by: Mohammed Al Sahaf --- caddyconfig/caddyfile/importargs_test.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/caddyconfig/caddyfile/importargs_test.go b/caddyconfig/caddyfile/importargs_test.go index 13dcf707d..baa63b737 100644 --- a/caddyconfig/caddyfile/importargs_test.go +++ b/caddyconfig/caddyfile/importargs_test.go @@ -252,21 +252,17 @@ func TestMakeArgsReplacer(t *testing.T) { func TestMakeArgsReplacerEmpty(t *testing.T) { repl := makeArgsReplacer([]string{}) - // With no args, any index should be out of bounds got := repl.ReplaceAll("{args[0]}", "") - if got == "something" { - t.Errorf("repl.ReplaceAll with empty args should not produce a value, got %q", got) + if got != "" { + t.Errorf("repl.ReplaceAll({args[0]}, \"\") with empty args = %q, want \"\"", got) } } func TestMakeArgsReplacerNil(t *testing.T) { repl := makeArgsReplacer(nil) - // Should not panic with nil args got := repl.ReplaceAll("{args[0]}", "DEFAULT") - if got == "" { - // The replacer returns the default when unmatched - t.Log("nil args: correctly returned empty/default for {args[0]}") + if got != "DEFAULT" { + t.Errorf("repl.ReplaceAll({args[0]}, \"DEFAULT\") with nil args = %q, want \"DEFAULT\"", got) } - _ = got }