(t *testing.T)
| 125 | } |
| 126 | |
| 127 | func TestAutoRotate(t *testing.T) { |
| 128 | currentTime = fakeTime |
| 129 | megabyte = 1 |
| 130 | |
| 131 | dir := makeTempDir("TestAutoRotate", t) |
| 132 | defer os.RemoveAll(dir) |
| 133 | |
| 134 | filename := logFile(dir) |
| 135 | l := &Logger{ |
| 136 | Filename: filename, |
| 137 | MaxSize: 10, |
| 138 | } |
| 139 | defer l.Close() |
| 140 | b := []byte("boo!") |
| 141 | n, err := l.Write(b) |
| 142 | isNil(err, t) |
| 143 | equals(len(b), n, t) |
| 144 | |
| 145 | existsWithContent(filename, b, t) |
| 146 | fileCount(dir, 1, t) |
| 147 | |
| 148 | newFakeTime() |
| 149 | |
| 150 | b2 := []byte("foooooo!") |
| 151 | n, err = l.Write(b2) |
| 152 | isNil(err, t) |
| 153 | equals(len(b2), n, t) |
| 154 | |
| 155 | // the old logfile should be moved aside and the main logfile should have |
| 156 | // only the last write in it. |
| 157 | existsWithContent(filename, b2, t) |
| 158 | |
| 159 | // the backup file will use the current fake time and have the old contents. |
| 160 | existsWithContent(backupFile(dir), b, t) |
| 161 | |
| 162 | fileCount(dir, 2, t) |
| 163 | } |
| 164 | |
| 165 | func TestFirstWriteRotate(t *testing.T) { |
| 166 | currentTime = fakeTime |
nothing calls this directly
no test coverage detected
searching dependent graphs…