Browse Source
Co-authored-by: Matt Holt <mholt@users.noreply.github.com> Co-authored-by: Francis Lavoie <lavofr@gmail.com>master
Kévin Dunglas
3 years ago
committed by
GitHub
3 changed files with 189 additions and 0 deletions
@ -0,0 +1,41 @@ |
|||
package logging |
|||
|
|||
import ( |
|||
"testing" |
|||
|
|||
"go.uber.org/zap/zapcore" |
|||
) |
|||
|
|||
func TestQueryFilter(t *testing.T) { |
|||
f := QueryFilter{[]queryFilterAction{ |
|||
{replaceAction, "foo", "REDACTED"}, |
|||
{replaceAction, "notexist", "REDACTED"}, |
|||
{deleteAction, "bar", ""}, |
|||
{deleteAction, "notexist", ""}, |
|||
}} |
|||
|
|||
if f.Validate() != nil { |
|||
t.Fatalf("the filter must be valid") |
|||
} |
|||
|
|||
out := f.Filter(zapcore.Field{String: "/path?foo=a&foo=b&bar=c&bar=d&baz=e"}) |
|||
if out.String != "/path?baz=e&foo=REDACTED&foo=REDACTED" { |
|||
t.Fatalf("query parameters have not been filtered: %s", out.String) |
|||
} |
|||
} |
|||
|
|||
func TestValidateQueryFilter(t *testing.T) { |
|||
f := QueryFilter{[]queryFilterAction{ |
|||
{}, |
|||
}} |
|||
if f.Validate() == nil { |
|||
t.Fatalf("empty action type must be invalid") |
|||
} |
|||
|
|||
f = QueryFilter{[]queryFilterAction{ |
|||
{Type: "foo"}, |
|||
}} |
|||
if f.Validate() == nil { |
|||
t.Fatalf("unknown action type must be invalid") |
|||
} |
|||
} |
Loading…
Reference in new issue