(t *testing.T)
| 194 | } |
| 195 | |
| 196 | func TestMaxBackups(t *testing.T) { |
| 197 | currentTime = fakeTime |
| 198 | megabyte = 1 |
| 199 | dir := makeTempDir("TestMaxBackups", t) |
| 200 | defer os.RemoveAll(dir) |
| 201 | |
| 202 | filename := logFile(dir) |
| 203 | l := &Logger{ |
| 204 | Filename: filename, |
| 205 | MaxSize: 10, |
| 206 | MaxBackups: 1, |
| 207 | } |
| 208 | defer l.Close() |
| 209 | b := []byte("boo!") |
| 210 | n, err := l.Write(b) |
| 211 | isNil(err, t) |
| 212 | equals(len(b), n, t) |
| 213 | |
| 214 | existsWithContent(filename, b, t) |
| 215 | fileCount(dir, 1, t) |
| 216 | |
| 217 | newFakeTime() |
| 218 | |
| 219 | // this will put us over the max |
| 220 | b2 := []byte("foooooo!") |
| 221 | n, err = l.Write(b2) |
| 222 | isNil(err, t) |
| 223 | equals(len(b2), n, t) |
| 224 | |
| 225 | // this will use the new fake time |
| 226 | secondFilename := backupFile(dir) |
| 227 | existsWithContent(secondFilename, b, t) |
| 228 | |
| 229 | // make sure the old file still exists with the same content. |
| 230 | existsWithContent(filename, b2, t) |
| 231 | |
| 232 | fileCount(dir, 2, t) |
| 233 | |
| 234 | newFakeTime() |
| 235 | |
| 236 | // this will make us rotate again |
| 237 | b3 := []byte("baaaaaar!") |
| 238 | n, err = l.Write(b3) |
| 239 | isNil(err, t) |
| 240 | equals(len(b3), n, t) |
| 241 | |
| 242 | // this will use the new fake time |
| 243 | thirdFilename := backupFile(dir) |
| 244 | existsWithContent(thirdFilename, b2, t) |
| 245 | |
| 246 | existsWithContent(filename, b3, t) |
| 247 | |
| 248 | // we need to wait a little bit since the files get deleted on a different |
| 249 | // goroutine. |
| 250 | <-time.After(time.Millisecond * 10) |
| 251 | |
| 252 | // should only have two files in the dir still |
| 253 | fileCount(dir, 2, t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…