(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestRotatingFile_MaxBackups(t *testing.T) { |
| 69 | t.Parallel() |
| 70 | dir := t.TempDir() |
| 71 | path := filepath.Join(dir, "test.log") |
| 72 | |
| 73 | rf, err := NewRotatingFile(path, WithMaxSize(20), WithMaxBackups(2)) |
| 74 | require.NoError(t, err) |
| 75 | defer rf.Close() |
| 76 | |
| 77 | data := make([]byte, 15) |
| 78 | |
| 79 | // Write 4 times to trigger multiple rotations |
| 80 | for i := range 4 { |
| 81 | for j := range data { |
| 82 | data[j] = byte('a' + i) |
| 83 | } |
| 84 | _, err = rf.Write(data) |
| 85 | require.NoError(t, err) |
| 86 | } |
| 87 | |
| 88 | // Should have current file + 2 backups (maxBackups=2) |
| 89 | _, err = os.Stat(path) |
| 90 | require.NoError(t, err, "current file should exist") |
| 91 | |
| 92 | _, err = os.Stat(path + ".1") |
| 93 | require.NoError(t, err, "backup .1 should exist") |
| 94 | |
| 95 | _, err = os.Stat(path + ".2") |
| 96 | require.NoError(t, err, "backup .2 should exist") |
| 97 | |
| 98 | // .3 should NOT exist because maxBackups=2 |
| 99 | _, err = os.Stat(path + ".3") |
| 100 | require.True(t, os.IsNotExist(err), "backup .3 should not exist") |
| 101 | } |
| 102 | |
| 103 | func TestRotatingFile_AppendsToExisting(t *testing.T) { |
| 104 | t.Parallel() |
nothing calls this directly
no test coverage detected