Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
failing test for files rotated outside of Include path parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rockb1017 committed May 19, 2021
1 parent 3b22d2e commit 8849bb4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions operator/builtin/input/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8849bb4

Please sign in to comment.