From 8849bb455850896ad9431b8c77a78d023f976383 Mon Sep 17 00:00:00 2001 From: Rock Baek Date: Tue, 18 May 2021 23:31:17 -0700 Subject: [PATCH] failing test for files rotated outside of Include path parameter --- operator/builtin/input/file/file_test.go | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/operator/builtin/input/file/file_test.go b/operator/builtin/input/file/file_test.go index 46583f2b..e54a0d56 100644 --- a/operator/builtin/input/file/file_test.go +++ b/operator/builtin/input/file/file_test.go @@ -879,6 +879,38 @@ func TestMoveFile(t *testing.T) { expectNoMessages(t, logReceived) } +func TestTrackMovedAwayFiles(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Moving files while open is unsupported on Windows") + } + t.Parallel() + operator, logReceived, tempDir := newTestFileOperator(t, nil, nil) + operator.persister = testutil.NewMockPersister("test") + + temp1 := openTemp(t, tempDir) + writeString(t, temp1, "testlog1\n") + temp1.Close() + + operator.poll(context.Background()) + defer operator.Stop() + + waitForMessage(t, logReceived, "testlog1") + + // Wait until all goroutines are finished before renaming + operator.wg.Wait() + tempDir2 := os.TempDir() + newFileName := fmt.Sprintf("%s%s", tempDir2, "newfile.log") + err := os.Rename(temp1.Name(), newFileName) + require.NoError(t, err) + + movedFile, err := os.OpenFile(newFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + require.NoError(t, err) + writeString(t, movedFile, "testlog2\n") + operator.poll(context.Background()) + + waitForMessage(t, logReceived, "testlog2") +} + // TruncateThenWrite tests that, after a file has been truncated, // any new writes are picked up func TestTruncateThenWrite(t *testing.T) {