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 <msaa1990@gmail.com>add-tests
parent
aea7b9bdf0
commit
cc534df68f
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue