MCPcopy
hub / github.com/natefinch/lumberjack / TestCompressOnRotate

Function TestCompressOnRotate

lumberjack_test.go:590–637  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

588}
589
590func TestCompressOnRotate(t *testing.T) {
591 currentTime = fakeTime
592 megabyte = 1
593
594 dir := makeTempDir("TestCompressOnRotate", t)
595 defer os.RemoveAll(dir)
596
597 filename := logFile(dir)
598 l := &Logger{
599 Compress: true,
600 Filename: filename,
601 MaxSize: 10,
602 }
603 defer l.Close()
604 b := []byte("boo!")
605 n, err := l.Write(b)
606 isNil(err, t)
607 equals(len(b), n, t)
608
609 existsWithContent(filename, b, t)
610 fileCount(dir, 1, t)
611
612 newFakeTime()
613
614 err = l.Rotate()
615 isNil(err, t)
616
617 // the old logfile should be moved aside and the main logfile should have
618 // nothing in it.
619 existsWithContent(filename, []byte{}, t)
620
621 // we need to wait a little bit since the files get compressed on a different
622 // goroutine.
623 <-time.After(300 * time.Millisecond)
624
625 // a compressed version of the log file should now exist and the original
626 // should have been removed.
627 bc := new(bytes.Buffer)
628 gz := gzip.NewWriter(bc)
629 _, err = gz.Write(b)
630 isNil(err, t)
631 err = gz.Close()
632 isNil(err, t)
633 existsWithContent(backupFile(dir)+compressSuffix, bc.Bytes(), t)
634 notExist(backupFile(dir), t)
635
636 fileCount(dir, 2, t)
637}
638
639func TestCompressOnResume(t *testing.T) {
640 currentTime = fakeTime

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
WriteMethod · 0.95
RotateMethod · 0.95
makeTempDirFunction · 0.85
logFileFunction · 0.85
isNilFunction · 0.85
equalsFunction · 0.85
existsWithContentFunction · 0.85
fileCountFunction · 0.85
newFakeTimeFunction · 0.85
backupFileFunction · 0.85
notExistFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…