@@ -102,6 +102,38 @@ const tests = `
102102 - [expect, test line 3 dir 1 file 2, logdir1/logfile-2.log]
103103 - [expect, test line 3 dir 2 file 1, logdir2/logfile-1.log]
104104 - [expect, test line 3 dir 2 file 2, logdir2/logfile-2.log]
105+
106+ - name: nested directories
107+ commands:
108+ - [mkdir, outer]
109+ - [mkdir, outer/inner]
110+ - [log, outer line 1, outer/logfile.log]
111+ - [log, inner line 1, outer/inner/logfile.log]
112+ - [start file tailer, readall=true, fail_on_missing_logfile=false, outer/*.log, outer/inner/*.log]
113+ - [expect, outer line 1, outer/logfile.log]
114+ - [expect, inner line 1, outer/inner/logfile.log]
115+ - [log, outer line 2, outer/logfile.log]
116+ - [log, inner line 2, outer/inner/logfile.log]
117+ - [expect, outer line 2, outer/logfile.log]
118+ - [expect, inner line 2, outer/inner/logfile.log]
119+ - [logrotate, outer/logfile.log, outer/logfile.log.1]
120+ - [logrotate, outer/inner/logfile.log, outer/inner/logfile.log.1]
121+ - [log, outer line 3, outer/logfile.log]
122+ - [log, inner line 3, outer/inner/logfile.log]
123+ - [expect, outer line 3, outer/logfile.log]
124+ - [expect, inner line 3, outer/inner/logfile.log]
125+
126+ - name: watch after logrotate
127+ commands:
128+ - [mkdir, logdir]
129+ - [log, line 1, logdir/logfile.log]
130+ - [start file tailer, readall=true, fail_on_missing_logfile=false, logdir/*]
131+ - [expect, line 1, logdir/logfile.log]
132+ - [log, line 2, logdir/logfile.log]
133+ - [expect, line 2, logdir/logfile.log]
134+ - [logrotate, logdir/logfile.log, logdir/logfile.log.1]
135+ - [log, line 3, logdir/logfile.log]
136+ - [expect, line 3, logdir/logfile.log]
105137`
106138
107139// // The following test fails on Windows in tearDown() when removing logdir.
@@ -209,14 +241,19 @@ func executeCommands(t *testing.T, ctx *context, cmds [][]string) {
209241 for _ , cmd := range cmds {
210242 exec (t , ctx , cmd )
211243 }
212- closeTailer (t , ctx )
244+ // The "watch after logrotate" test watches logdir/* and rotates logdir/logfile.log
245+ // to logdir/logfile.log.1. As a result, the file is still watched after it is rotated.
246+ // Depending on the logrotate config the lines are read again (cp) or not (mv).
247+ // We ignore unexpected lines for that test.
248+ // TODO: Make ignoreUnexpectedLines an explicit paramter in the test yaml instead of using the test name here.
249+ closeTailer (t , ctx , ctx .testName == "watch after logrotate" )
213250 assertGoroutinesTerminated (t , ctx , nGoroutinesBefore )
214251 for _ , writer := range ctx .logFileWriters {
215252 writer .close (t , ctx )
216253 }
217254}
218255
219- func closeTailer (t * testing.T , ctx * context ) {
256+ func closeTailer (t * testing.T , ctx * context , ignoreUnexpectedLines bool ) {
220257 // Note: This function checks if the Lines() channel gets closed.
221258 // While it's good to check this, it doesn't guarantee that the tailer is
222259 // fully shut down. There might be an fseventProducerLoop running in the
@@ -230,7 +267,7 @@ func closeTailer(t *testing.T, ctx *context) {
230267 // check if the lines channel gets closed
231268 select {
232269 case line , open := <- ctx .tailer .Lines ():
233- if open {
270+ if open && ! ignoreUnexpectedLines {
234271 fatalf (t , ctx , "read unexpected line line from file %q: %q" , line .File , line .Line )
235272 }
236273 case <- time .After (timeout ):
0 commit comments