(t *testing.T)
| 294 | } |
| 295 | |
| 296 | func TestConsoleIrregularLogPaths(t *testing.T) { |
| 297 | // override min rotation interval for testing |
| 298 | originalMinRotationInterval := minLogRotationInterval |
| 299 | minLogRotationInterval = time.Millisecond * 10 |
| 300 | defer func() { minLogRotationInterval = originalMinRotationInterval }() |
| 301 | |
| 302 | testCases := []struct { |
| 303 | name string |
| 304 | logPath string |
| 305 | }{ |
| 306 | { |
| 307 | name: ".log extension", |
| 308 | logPath: "foo.log", |
| 309 | // take foo-2021-01-01T00-00-00.000.log |
| 310 | }, |
| 311 | { |
| 312 | name: "no extension", |
| 313 | logPath: "foo", |
| 314 | // foo-2021-01-01T00-00-00.000 |
| 315 | }, |
| 316 | { |
| 317 | name: "multiple dots", |
| 318 | logPath: "two.ext.log", |
| 319 | // two.ext-2021-01-01T00-00-00.000.log |
| 320 | }, |
| 321 | { |
| 322 | name: "start with .", |
| 323 | logPath: ".hidden.log", |
| 324 | // .hidden-2021-01-01T00-00-00.000.log |
| 325 | }, |
| 326 | { |
| 327 | name: "start with ., no ext", |
| 328 | logPath: ".hidden", |
| 329 | // -2021-01-01T00-00-00.000.hidden |
| 330 | }, |
| 331 | } |
| 332 | for _, test := range testCases { |
| 333 | t.Run(test.name, func(t *testing.T) { |
| 334 | tempdir := lumberjackTempDir(t) |
| 335 | config := &ConsoleLoggerConfig{ |
| 336 | LogLevel: logLevelPtr(LevelDebug), |
| 337 | LogKeys: []string{"HTTP"}, |
| 338 | FileOutput: filepath.Join(tempdir, test.logPath), |
| 339 | FileLoggerConfig: FileLoggerConfig{ |
| 340 | Enabled: Ptr(true), |
| 341 | CollationBufferSize: Ptr(0), |
| 342 | Rotation: logRotationConfig{ |
| 343 | RotationInterval: NewConfigDuration(10 * time.Millisecond), |
| 344 | }, |
| 345 | }} |
| 346 | |
| 347 | ctx := TestCtx(t) |
| 348 | logger, err := NewConsoleLogger(ctx, false, config) |
| 349 | require.NoError(t, err) |
| 350 | |
| 351 | // ensure logging is done before closing the logger |
| 352 | wg := sync.WaitGroup{} |
| 353 | wg.Add(1) |
nothing calls this directly
no test coverage detected