Skip to content

Commit

Permalink
Better Redactors
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed May 8, 2024
1 parent bee9c19 commit 24c90cf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (user User) String() string {

type Metadata struct {
UserID string `json:"userId"`
Name string `json:"name"`
City string `json:"city"`
Name string `json:"name"`
City string `json:"city"`
}

func (metadata Metadata) Redact(keyToRedact ...string) interface{} {
Expand Down
3 changes: 3 additions & 0 deletions logger_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,16 @@ func (suite *InternalLoggerSuite) TestIsHijacker() {
}

type hijackerResponse struct{}

func (*hijackerResponse) Header() http.Header { return nil }
func (*hijackerResponse) Write([]byte) (int, error) { return 0, nil }
func (*hijackerResponse) WriteHeader(statusCode int) {}
func (*hijackerResponse) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return nil, nil, errors.NotImplemented.WithStack()
}

type noopResponse struct{}

func (*noopResponse) Header() http.Header { return nil }
func (*noopResponse) Write([]byte) (int, error) { return 0, nil }
func (*noopResponse) WriteHeader(statusCode int) {}
Expand Down
2 changes: 1 addition & 1 deletion record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,4 @@ func (suite *RecordSuite) TestCanAddKeysToRedact() {
suite.Assert().Contains(record.KeysToRedact, "key2")
suite.Assert().Contains(record.KeysToRedact, "key3")
suite.Assert().NotContains(record.KeysToRedact, "key4")
}
}
9 changes: 5 additions & 4 deletions redact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ func (suite *RedactSuite) TestCanMergeWithString() {
suite.Assert().Equal("message with nothing", redacted)
}

type stringer logger.Redactor
func (s stringer) String() string {
return logger.Redactor(s).String()
}
type stringer logger.Redactor

func (s stringer) String() string {
return logger.Redactor(s).String()
}

func (suite *RedactSuite) TestCanMergeWithStringer() {
expected := `3[47]\d{2}[- ]*\d{6}[- ]*\d{5}|4\d{3}[- ]*\d{4}[- ]*\d{4}[- ]*\d{4}`
Expand Down

0 comments on commit 24c90cf

Please sign in to comment.