(t *testing.T)
| 130 | } |
| 131 | |
| 132 | func 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 | |
| 178 | type fakeFile struct { |
| 179 | uid int |
nothing calls this directly
no test coverage detected
searching dependent graphs…