Skip to content

Commit

Permalink
chore(tests): withMethodExpr => withMethod
Browse files Browse the repository at this point in the history
withMethodExpr is an unnecessary level of detail
in this context.
  • Loading branch information
abhinav committed Sep 9, 2023
1 parent 6ac23ce commit b538e82
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions logger_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func Benchmark5WithLazysNotUsed(b *testing.B) {
benchmarkWithUsed(b, (*Logger).WithLazy, 5, false)
}

func benchmarkWithUsed(b *testing.B, withMethodExpr func(*Logger, ...zapcore.Field) *Logger, N int, use bool) {
func benchmarkWithUsed(b *testing.B, withMethod func(*Logger, ...zapcore.Field) *Logger, N int, use bool) {
keys := make([]string, N)
values := make([]string, N)
for i := 0; i < N; i++ {
Expand All @@ -232,7 +232,7 @@ func benchmarkWithUsed(b *testing.B, withMethodExpr func(*Logger, ...zapcore.Fie

withBenchedLogger(b, func(log *Logger) {
for i := 0; i < N; i++ {
log = withMethodExpr(log, String(keys[i], values[i]))
log = withMethod(log, String(keys[i], values[i]))
}
if use {
log.Info("used")
Expand Down
33 changes: 16 additions & 17 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ func TestLoggerInitialFields(t *testing.T) {
}

func TestLoggerWith(t *testing.T) {

for _, tt := range []struct {
name string
initialFields []Field
withMethodExpr func(*Logger, ...Field) *Logger
name string
initialFields []Field
withMethod func(*Logger, ...Field) *Logger
}{
{
"regular non lazy logger",
Expand All @@ -155,10 +154,10 @@ func TestLoggerWith(t *testing.T) {
withLogger(t, DebugLevel, opts(Fields(tt.initialFields...)), func(logger *Logger, logs *observer.ObservedLogs) {
// Child loggers should have copy-on-write semantics, so two children
// shouldn't stomp on each other's fields or affect the parent's fields.
tt.withMethodExpr(logger).Info("")
tt.withMethodExpr(logger, String("one", "two")).Info("")
tt.withMethodExpr(logger, String("three", "four")).Info("")
tt.withMethodExpr(logger, String("five", "six")).With(String("seven", "eight")).Info("")
tt.withMethod(logger).Info("")
tt.withMethod(logger, String("one", "two")).Info("")
tt.withMethod(logger, String("three", "four")).Info("")
tt.withMethod(logger, String("five", "six")).With(String("seven", "eight")).Info("")
logger.Info("")

assert.Equal(t, []observer.LoggedEntry{
Expand All @@ -175,13 +174,13 @@ func TestLoggerWith(t *testing.T) {

func TestLoggerWithCaptures(t *testing.T) {
for _, tt := range []struct {
name string
withMethodExpr func(*Logger, ...Field) *Logger
wantJSON [2]string
name string
withMethod func(*Logger, ...Field) *Logger
wantJSON [2]string
}{
{
name: "regular with captures arguments at time of With",
withMethodExpr: (*Logger).With,
name: "regular with captures arguments at time of With",
withMethod: (*Logger).With,
wantJSON: [2]string{
`{
"m": "hello",
Expand All @@ -196,8 +195,8 @@ func TestLoggerWithCaptures(t *testing.T) {
},
},
{
name: "lazy with captures arguments at time of With or Logging",
withMethodExpr: (*Logger).WithLazy,
name: "lazy with captures arguments at time of With or Logging",
withMethod: (*Logger).WithLazy,
wantJSON: [2]string{
`{
"m": "hello",
Expand Down Expand Up @@ -227,11 +226,11 @@ func TestLoggerWithCaptures(t *testing.T) {
})

// Demonstrate the arguments are captured when With() and Info() are invoked.
logger = tt.withMethodExpr(logger, Array("a", arr))
logger = tt.withMethod(logger, Array("a", arr))
x = 1
logger.Info("hello", Array("b", arr))
x = 2
logger = tt.withMethodExpr(logger, Array("c", arr))
logger = tt.withMethod(logger, Array("c", arr))
logger.Info("world")

if lines := bs.Lines(); assert.Len(t, lines, 2) {
Expand Down

0 comments on commit b538e82

Please sign in to comment.