MCPcopy
hub / github.com/natefinch/lumberjack / TestCompressMaintainOwner

Function TestCompressMaintainOwner

linux_test.go:132–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestCompressMaintainOwner(t *testing.T) {
133 fakeFS := newFakeFS()
134 osChown = fakeFS.Chown
135 osStat = fakeFS.Stat
136 defer func() {
137 osChown = os.Chown
138 osStat = os.Stat
139 }()
140 currentTime = fakeTime
141 dir := makeTempDir("TestCompressMaintainOwner", t)
142 defer os.RemoveAll(dir)
143
144 filename := logFile(dir)
145
146 f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0644)
147 isNil(err, t)
148 f.Close()
149
150 l := &Logger{
151 Compress: true,
152 Filename: filename,
153 MaxBackups: 1,
154 MaxSize: 100, // megabytes
155 }
156 defer l.Close()
157 b := []byte("boo!")
158 n, err := l.Write(b)
159 isNil(err, t)
160 equals(len(b), n, t)
161
162 newFakeTime()
163
164 err = l.Rotate()
165 isNil(err, t)
166
167 // we need to wait a little bit since the files get compressed on a different
168 // goroutine.
169 <-time.After(10 * time.Millisecond)
170
171 // a compressed version of the log file should now exist with the correct
172 // owner.
173 filename2 := backupFile(dir)
174 equals(555, fakeFS.files[filename2+compressSuffix].uid, t)
175 equals(666, fakeFS.files[filename2+compressSuffix].gid, t)
176}
177
178type fakeFile struct {
179 uid int

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
WriteMethod · 0.95
RotateMethod · 0.95
newFakeFSFunction · 0.85
makeTempDirFunction · 0.85
logFileFunction · 0.85
isNilFunction · 0.85
equalsFunction · 0.85
newFakeTimeFunction · 0.85
backupFileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…