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

Function TestRotatingFile_AppendsToExisting

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

Source from the content-addressed store, hash-verified

101}
102
103func TestRotatingFile_AppendsToExisting(t *testing.T) {
104 t.Parallel()
105 dir := t.TempDir()
106 path := filepath.Join(dir, "test.log")
107
108 // Create a file with existing content
109 err := os.WriteFile(path, []byte("existing\n"), 0o600)
110 require.NoError(t, err)
111
112 rf, err := NewRotatingFile(path, WithMaxSize(1000), WithMaxBackups(2))
113 require.NoError(t, err)
114 defer rf.Close()
115
116 _, err = rf.Write([]byte("new\n"))
117 require.NoError(t, err)
118
119 content, err := os.ReadFile(path)
120 require.NoError(t, err)
121 assert.Equal(t, "existing\nnew\n", string(content))
122}
123
124func TestRotatingFile_CreatesDirectory(t *testing.T) {
125 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