@@ -208,6 +208,66 @@ func TestLocationMiddle(t *testing.T) {
208
208
tailTest .Cleanup (tail , true )
209
209
}
210
210
211
+ func TestLineLocationFull (t * testing.T ) {
212
+ tailTest := NewTailTest ("location-full" , t )
213
+ tailTest .CreateFile ("test.txt" , "hello\n world\n " )
214
+ tail := tailTest .StartTail ("test.txt" , Config {Follow : true , LineLocation : nil })
215
+ go tailTest .VerifyTailOutput (tail , []string {"hello" , "world" }, false )
216
+
217
+ // Delete after a reasonable delay, to give tail sufficient time
218
+ // to read all lines.
219
+ <- time .After (100 * time .Millisecond )
220
+ tailTest .RemoveFile ("test.txt" )
221
+ tailTest .Cleanup (tail , true )
222
+ }
223
+
224
+ func TestLineLocationFullDontFollow (t * testing.T ) {
225
+ tailTest := NewTailTest ("location-full-dontfollow" , t )
226
+ tailTest .CreateFile ("test.txt" , "hello\n world\n " )
227
+ tail := tailTest .StartTail ("test.txt" , Config {Follow : false , LineLocation : nil })
228
+ go tailTest .VerifyTailOutput (tail , []string {"hello" , "world" }, false )
229
+
230
+ // Add more data only after reasonable delay.
231
+ <- time .After (100 * time .Millisecond )
232
+ tailTest .AppendFile ("test.txt" , "more\n data\n " )
233
+ <- time .After (100 * time .Millisecond )
234
+
235
+ tailTest .Cleanup (tail , true )
236
+ }
237
+
238
+ func TestLineLocationEnd (t * testing.T ) {
239
+ tailTest := NewTailTest ("location-end" , t )
240
+ tailTest .CreateFile ("test.txt" , "hello\n world\n " )
241
+ tail := tailTest .StartTail ("test.txt" , Config {Follow : true , LineLocation : & SeekInfo {0 , os .SEEK_END }})
242
+ go tailTest .VerifyTailOutput (tail , []string {"more" , "data" }, false )
243
+
244
+ <- time .After (100 * time .Millisecond )
245
+ tailTest .AppendFile ("test.txt" , "more\n data\n " )
246
+
247
+ // Delete after a reasonable delay, to give tail sufficient time
248
+ // to read all lines.
249
+ <- time .After (100 * time .Millisecond )
250
+ tailTest .RemoveFile ("test.txt" )
251
+ tailTest .Cleanup (tail , true )
252
+ }
253
+
254
+ func TestLineLocationMiddle (t * testing.T ) {
255
+ // Test reading from middle.
256
+ tailTest := NewTailTest ("location-middle" , t )
257
+ tailTest .CreateFile ("test.txt" , "hello\n world\n " )
258
+ tail := tailTest .StartTail ("test.txt" , Config {Follow : true , LineLocation : & SeekInfo {- 1 , os .SEEK_END }})
259
+ go tailTest .VerifyTailOutput (tail , []string {"world" , "more" , "data" }, false )
260
+
261
+ <- time .After (100 * time .Millisecond )
262
+ tailTest .AppendFile ("test.txt" , "more\n data\n " )
263
+
264
+ // Delete after a reasonable delay, to give tail sufficient time
265
+ // to read all lines.
266
+ <- time .After (100 * time .Millisecond )
267
+ tailTest .RemoveFile ("test.txt" )
268
+ tailTest .Cleanup (tail , true )
269
+ }
270
+
211
271
// The use of polling file watcher could affect file rotation
212
272
// (detected via renames), so test these explicitly.
213
273
0 commit comments