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

Function TestCompressMaintainMode

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

Source from the content-addressed store, hash-verified

85}
86
87func TestCompressMaintainMode(t *testing.T) {
88 currentTime = fakeTime
89
90 dir := makeTempDir("TestCompressMaintainMode", t)
91 defer os.RemoveAll(dir)
92
93 filename := logFile(dir)
94
95 mode := os.FileMode(0600)
96 f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, mode)
97 isNil(err, t)
98 f.Close()
99
100 l := &Logger{
101 Compress: true,
102 Filename: filename,
103 MaxBackups: 1,
104 MaxSize: 100, // megabytes
105 }
106 defer l.Close()
107 b := []byte("boo!")
108 n, err := l.Write(b)
109 isNil(err, t)
110 equals(len(b), n, t)
111
112 newFakeTime()
113
114 err = l.Rotate()
115 isNil(err, t)
116
117 // we need to wait a little bit since the files get compressed on a different
118 // goroutine.
119 <-time.After(10 * time.Millisecond)
120
121 // a compressed version of the log file should now exist with the correct
122 // mode.
123 filename2 := backupFile(dir)
124 info, err := os.Stat(filename)
125 isNil(err, t)
126 info2, err := os.Stat(filename2 + compressSuffix)
127 isNil(err, t)
128 equals(mode, info.Mode(), t)
129 equals(mode, info2.Mode(), t)
130}
131
132func TestCompressMaintainOwner(t *testing.T) {
133 fakeFS := newFakeFS()

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…