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

Function TestRotatingFile_Rotate

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

Source from the content-addressed store, hash-verified

29}
30
31func TestRotatingFile_Rotate(t *testing.T) {
32 t.Parallel()
33 dir := t.TempDir()
34 path := filepath.Join(dir, "test.log")
35
36 rf, err := NewRotatingFile(path, WithMaxSize(50), WithMaxBackups(2))
37 require.NoError(t, err)
38 defer rf.Close()
39
40 // Write enough data to trigger rotation
41 data := make([]byte, 30)
42 for i := range data {
43 data[i] = 'a'
44 }
45
46 _, err = rf.Write(data)
47 require.NoError(t, err)
48
49 // This write should trigger rotation
50 _, err = rf.Write(data)
51 require.NoError(t, err)
52
53 // Check that backup file was created
54 _, err = os.Stat(path + ".1")
55 require.NoError(t, err, "backup file should exist")
56
57 // Original file should have new content
58 content, err := os.ReadFile(path)
59 require.NoError(t, err)
60 assert.Equal(t, data, content)
61
62 // Backup should have old content
63 backup, err := os.ReadFile(path + ".1")
64 require.NoError(t, err)
65 assert.Equal(t, data, backup)
66}
67
68func TestRotatingFile_MaxBackups(t *testing.T) {
69 t.Parallel()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected