From 75dacb47ccd67c3c1fd765ac43a71b7005f0ae51 Mon Sep 17 00:00:00 2001 From: Chris Suszynski Date: Fri, 22 Apr 2022 18:51:49 +0200 Subject: [PATCH] Tests pass regardless of codebase directory (#1087) --- config_test.go | 14 +++++++------- logger_test.go | 4 ++-- sugar_test.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/config_test.go b/config_test.go index ac098aafe..0925a7239 100644 --- a/config_test.go +++ b/config_test.go @@ -42,16 +42,16 @@ func TestConfig(t *testing.T) { desc: "production", cfg: NewProductionConfig(), expectN: 2 + 100 + 1, // 2 from initial logs, 100 initial sampled logs, 1 from off-by-one in sampler - expectRe: `{"level":"info","caller":"zap/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" + - `{"level":"warn","caller":"zap/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n", + expectRe: `{"level":"info","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" + + `{"level":"warn","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n", }, { desc: "development", cfg: NewDevelopmentConfig(), expectN: 3 + 200, // 3 initial logs, all 200 subsequent logs - expectRe: "DEBUG\tzap/config_test.go:" + `\d+` + "\tdebug\t" + `{"k": "v", "z": "zz"}` + "\n" + - "INFO\tzap/config_test.go:" + `\d+` + "\tinfo\t" + `{"k": "v", "z": "zz"}` + "\n" + - "WARN\tzap/config_test.go:" + `\d+` + "\twarn\t" + `{"k": "v", "z": "zz"}` + "\n" + + expectRe: "DEBUG\t[a-z0-9_-]+/config_test.go:" + `\d+` + "\tdebug\t" + `{"k": "v", "z": "zz"}` + "\n" + + "INFO\t[a-z0-9_-]+/config_test.go:" + `\d+` + "\tinfo\t" + `{"k": "v", "z": "zz"}` + "\n" + + "WARN\t[a-z0-9_-]+/config_test.go:" + `\d+` + "\twarn\t" + `{"k": "v", "z": "zz"}` + "\n" + `go.uber.org/zap.TestConfig.\w+`, }, } @@ -175,8 +175,8 @@ func TestConfigWithSamplingHook(t *testing.T) { OutputPaths: []string{"stderr"}, ErrorOutputPaths: []string{"stderr"}, } - expectRe := `{"level":"info","caller":"zap/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" + - `{"level":"warn","caller":"zap/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n" + expectRe := `{"level":"info","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" + + `{"level":"warn","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n" expectDropped := 99 // 200 - 100 initial - 1 thereafter expectSampled := 103 // 2 from initial + 100 + 1 thereafter diff --git a/logger_test.go b/logger_test.go index 4b54ff470..6fbf12266 100644 --- a/logger_test.go +++ b/logger_test.go @@ -345,8 +345,8 @@ func TestLoggerAddCaller(t *testing.T) { {opts(AddCaller(), WithCaller(false)), `^undefined$`}, {opts(WithCaller(true)), `.+/logger_test.go:[\d]+$`}, {opts(WithCaller(true), WithCaller(false)), `^undefined$`}, - {opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/zap/logger_test.go:[\d]+$`}, - {opts(AddCaller(), AddCallerSkip(1)), `.+/zap/common_test.go:[\d]+$`}, + {opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/logger_test.go:[\d]+$`}, + {opts(AddCaller(), AddCallerSkip(1)), `.+/common_test.go:[\d]+$`}, {opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(3)), `.+/src/runtime/.*:[\d]+$`}, } for _, tt := range tests { diff --git a/sugar_test.go b/sugar_test.go index 67ba76fe6..1824e348f 100644 --- a/sugar_test.go +++ b/sugar_test.go @@ -381,8 +381,8 @@ func TestSugarAddCaller(t *testing.T) { pat string }{ {opts(AddCaller()), `.+/sugar_test.go:[\d]+$`}, - {opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/zap/sugar_test.go:[\d]+$`}, - {opts(AddCaller(), AddCallerSkip(1)), `.+/zap/common_test.go:[\d]+$`}, + {opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/sugar_test.go:[\d]+$`}, + {opts(AddCaller(), AddCallerSkip(1)), `.+/common_test.go:[\d]+$`}, {opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(5)), `.+/src/runtime/.*:[\d]+$`}, } for _, tt := range tests {