MCPcopy Index your code
hub / github.com/docker/docker-agent / TestRotatingFile_MaxBackups

Function TestRotatingFile_MaxBackups

pkg/logging/rotate_test.go:68–101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func 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
103func TestRotatingFile_AppendsToExisting(t *testing.T) {
104 t.Parallel()

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
WriteMethod · 0.95
NewRotatingFileFunction · 0.85
WithMaxSizeFunction · 0.85
WithMaxBackupsFunction · 0.85

Tested by

no test coverage detected