|
|
|
@ -105,19 +105,49 @@ type ( |
|
|
|
|
dummyStringer struct { |
|
|
|
|
field string |
|
|
|
|
} |
|
|
|
|
dummyStringerRedacter struct { |
|
|
|
|
field string |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func (d *dummyStringer) String() string { |
|
|
|
|
return "my value" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyStringerRedacter) String() string { |
|
|
|
|
return "my value" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyStringerRedacter) Redact() string { |
|
|
|
|
return "my value redacted" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestExtractArgs(t *testing.T) { |
|
|
|
|
if extractArgs(&dummyStringer{field: ""}) != "my value" { |
|
|
|
|
t.Errorf(`The stringified dummyStringer structure must be equal to "my value", %v given`, extractArgs(&dummyStringer{field: ""})) |
|
|
|
|
tests := []struct { |
|
|
|
|
name string |
|
|
|
|
req interface{} |
|
|
|
|
expected string |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
name: "dummyStringer", |
|
|
|
|
req: &dummyStringer{field: ""}, |
|
|
|
|
expected: "my value", |
|
|
|
|
}, { |
|
|
|
|
name: "dummy", |
|
|
|
|
req: &dummy{field: "value"}, |
|
|
|
|
expected: "&{field:value}", |
|
|
|
|
}, { |
|
|
|
|
name: "dummyStringerRedacter", |
|
|
|
|
req: &dummyStringerRedacter{field: ""}, |
|
|
|
|
expected: "my value redacted", |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if extractArgs(&dummy{field: "value"}) != "&{field:value}" { |
|
|
|
|
t.Errorf(`The stringified dummy structure must be equal to "&{field:value}", %v given`, extractArgs(&dummy{field: "value"})) |
|
|
|
|
for _, test := range tests { |
|
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
if value := extractArgs(test.req); value != test.expected { |
|
|
|
|
t.Errorf(`The stringified %s structure must be equal to "%s", %v given`, test.name, test.expected, value) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|