(t *testing.T)
| 588 | } |
| 589 | |
| 590 | func 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 | |
| 639 | func TestCompressOnResume(t *testing.T) { |
| 640 | currentTime = fakeTime |
nothing calls this directly
no test coverage detected
searching dependent graphs…