v0.27.2 minor update: long lines, switches, tls
Package / arch (push) Canceled after 0s
Package / user (push) Canceled after 0s
Package / deb (push) Canceled after 0s
Package / freebsd (push) Canceled after 0s
Package / image (push) Canceled after 0s
Test / test (push) Canceled after 0s
Test / e2e (push) Canceled after 0s
Package / arch (push) Canceled after 0s
Package / user (push) Canceled after 0s
Package / deb (push) Canceled after 0s
Package / freebsd (push) Canceled after 0s
Package / image (push) Canceled after 0s
Test / test (push) Canceled after 0s
Test / e2e (push) Canceled after 0s
This commit is contained in:
1 parent
4513a9e62b
commit
a1648ce17b
16 files changed
+159
-34
No files matched your search
@@ -4,14 +4,41 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lixenwraith/logwisp/internal/config"
|
||||
"github.com/lixenwraith/logwisp/internal/core"
|
||||
"github.com/lixenwraith/logwisp/internal/testutil"
|
||||
|
||||
"github.com/lixenwraith/log"
|
||||
)
|
||||
|
||||
// A file source never follows the file lw's stdout or stderr is: `lw > out.log`
|
||||
// in the directory it follows would read its own output back, endlessly
|
||||
func TestFileSourceSkipsItsOwnOutput(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
testutil.WriteFile(t, filepath.Join(dir, "app.log"), "")
|
||||
testutil.WriteFile(t, filepath.Join(dir, "out.log"), "")
|
||||
own, err := os.Stat(filepath.Join(dir, "out.log"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := &FileSource{
|
||||
config: &config.FileSourceOptions{Directory: dir, Pattern: "*.log"},
|
||||
own: []os.FileInfo{own},
|
||||
ownSkipped: map[string]bool{},
|
||||
logger: log.NewLogger(),
|
||||
}
|
||||
files, err := source.scanFile()
|
||||
if err != nil || len(files) != 1 || filepath.Base(files[0]) != "app.log" {
|
||||
t.Fatalf("scanFile = %v, %v; want app.log alone", files, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoppedWatcherReturnsNormally(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "session.jsonl")
|
||||
testutil.WriteFile(t, path, "")
|
||||
@@ -45,6 +72,25 @@ func TestRemoveWatcherPreservesReplacement(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A line longer than core.MaxLogEntryBytes continues in the next entry, and the
|
||||
// lines around it are read once: the watcher used to stop at it for good
|
||||
func TestLongLineContinuesInTheNextEntry(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "app.log")
|
||||
long := strings.Repeat("x", core.MaxLogEntryBytes+10)
|
||||
testutil.WriteFile(t, path, "first\n"+long+"\nafter\n")
|
||||
var got []string
|
||||
w := newFileWatcher(path, true, true, func(e core.LogEntry) { got = append(got, e.Message) }, log.NewLogger())
|
||||
for range 2 {
|
||||
if err := w.checkFile(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
want := []string{"first", long[:core.MaxLogEntryBytes], long[core.MaxLogEntryBytes:], "after"}
|
||||
if !slices.Equal(got, want) {
|
||||
t.Fatalf("read %d entries, want %d: first, the long line in two, after", len(got), len(want))
|
||||
}
|
||||
}
|
||||
|
||||
// A rotated file reappears under its archive name with the same inode. Its
|
||||
// replacement watcher resumes where the original stopped, so a `from = "start"`
|
||||
// source does not re-emit every record the file already delivered.
|
||||
|
||||
Reference in new issue
Block a user