Skip to content

Commit 75dacb4

Browse files
authored
Tests pass regardless of codebase directory (#1087)
1 parent d38507c commit 75dacb4

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

config_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ func TestConfig(t *testing.T) {
4242
desc: "production",
4343
cfg: NewProductionConfig(),
4444
expectN: 2 + 100 + 1, // 2 from initial logs, 100 initial sampled logs, 1 from off-by-one in sampler
45-
expectRe: `{"level":"info","caller":"zap/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" +
46-
`{"level":"warn","caller":"zap/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n",
45+
expectRe: `{"level":"info","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" +
46+
`{"level":"warn","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n",
4747
},
4848
{
4949
desc: "development",
5050
cfg: NewDevelopmentConfig(),
5151
expectN: 3 + 200, // 3 initial logs, all 200 subsequent logs
52-
expectRe: "DEBUG\tzap/config_test.go:" + `\d+` + "\tdebug\t" + `{"k": "v", "z": "zz"}` + "\n" +
53-
"INFO\tzap/config_test.go:" + `\d+` + "\tinfo\t" + `{"k": "v", "z": "zz"}` + "\n" +
54-
"WARN\tzap/config_test.go:" + `\d+` + "\twarn\t" + `{"k": "v", "z": "zz"}` + "\n" +
52+
expectRe: "DEBUG\t[a-z0-9_-]+/config_test.go:" + `\d+` + "\tdebug\t" + `{"k": "v", "z": "zz"}` + "\n" +
53+
"INFO\t[a-z0-9_-]+/config_test.go:" + `\d+` + "\tinfo\t" + `{"k": "v", "z": "zz"}` + "\n" +
54+
"WARN\t[a-z0-9_-]+/config_test.go:" + `\d+` + "\twarn\t" + `{"k": "v", "z": "zz"}` + "\n" +
5555
`go.uber.org/zap.TestConfig.\w+`,
5656
},
5757
}
@@ -175,8 +175,8 @@ func TestConfigWithSamplingHook(t *testing.T) {
175175
OutputPaths: []string{"stderr"},
176176
ErrorOutputPaths: []string{"stderr"},
177177
}
178-
expectRe := `{"level":"info","caller":"zap/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" +
179-
`{"level":"warn","caller":"zap/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n"
178+
expectRe := `{"level":"info","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"info","k":"v","z":"zz"}` + "\n" +
179+
`{"level":"warn","caller":"[a-z0-9_-]+/config_test.go:\d+","msg":"warn","k":"v","z":"zz"}` + "\n"
180180
expectDropped := 99 // 200 - 100 initial - 1 thereafter
181181
expectSampled := 103 // 2 from initial + 100 + 1 thereafter
182182

logger_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ func TestLoggerAddCaller(t *testing.T) {
345345
{opts(AddCaller(), WithCaller(false)), `^undefined$`},
346346
{opts(WithCaller(true)), `.+/logger_test.go:[\d]+$`},
347347
{opts(WithCaller(true), WithCaller(false)), `^undefined$`},
348-
{opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/zap/logger_test.go:[\d]+$`},
349-
{opts(AddCaller(), AddCallerSkip(1)), `.+/zap/common_test.go:[\d]+$`},
348+
{opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/logger_test.go:[\d]+$`},
349+
{opts(AddCaller(), AddCallerSkip(1)), `.+/common_test.go:[\d]+$`},
350350
{opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(3)), `.+/src/runtime/.*:[\d]+$`},
351351
}
352352
for _, tt := range tests {

sugar_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ func TestSugarAddCaller(t *testing.T) {
381381
pat string
382382
}{
383383
{opts(AddCaller()), `.+/sugar_test.go:[\d]+$`},
384-
{opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/zap/sugar_test.go:[\d]+$`},
385-
{opts(AddCaller(), AddCallerSkip(1)), `.+/zap/common_test.go:[\d]+$`},
384+
{opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)), `.+/sugar_test.go:[\d]+$`},
385+
{opts(AddCaller(), AddCallerSkip(1)), `.+/common_test.go:[\d]+$`},
386386
{opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(5)), `.+/src/runtime/.*:[\d]+$`},
387387
}
388388
for _, tt := range tests {

0 commit comments

Comments
 (0)