-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpath_limits_test.go
More file actions
91 lines (73 loc) · 2.24 KB
/
path_limits_test.go
File metadata and controls
91 lines (73 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// path_limits_test.go: Testing Argus Path Length Limits
//
// Copyright (c) 2025 AGILira - A. Giordano
// Series: an AGILira fragment
// SPDX-License-Identifier: MPL-2.0
package argus
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestBoreasLite_PathLimits(t *testing.T) {
// Test with a simple, short path first
tempDir, err := os.MkdirTemp("", "test")
if err != nil {
t.Fatal(err)
}
defer func() {
if err := os.RemoveAll(tempDir); err != nil {
t.Logf("Failed to remove tempDir: %v", err)
}
}()
testFile := filepath.Join(tempDir, "test.json")
t.Logf("Testing with path: %s (len=%d)", testFile, len(testFile))
// Start watching BEFORE creating the file (like integration test)
config := Config{
PollInterval: 50 * time.Millisecond, // Polling more frequently for test
CacheTTL: 25 * time.Millisecond,
OptimizationStrategy: OptimizationSingleEvent, // Strategy for single file test
}
watcher := New(*config.WithDefaults())
defer func() {
if err := watcher.Stop(); err != nil {
t.Logf("Failed to stop watcher: %v", err)
}
}()
var events []ChangeEvent
if err := watcher.Watch(testFile, func(event ChangeEvent) {
events = append(events, event)
t.Logf("Event: Path=%s (len=%d)", event.Path, len(event.Path))
}); err != nil {
t.Fatal(err)
}
if err := watcher.Start(); err != nil {
t.Fatalf("Failed to start watcher: %v", err)
}
time.Sleep(100 * time.Millisecond)
t.Logf("Watcher started, now creating file...")
// NOW create the file (like integration test)
if err := os.WriteFile(testFile, []byte("initial"), 0644); err != nil {
t.Fatal(err)
}
t.Logf("File created, waiting for events...")
time.Sleep(200 * time.Millisecond) // Let first event settle
t.Logf("Now modifying file...")
// MODIFY the file (this should definitely trigger)
if err := os.WriteFile(testFile, []byte("modified content"), 0644); err != nil {
t.Fatal(err)
}
t.Logf("File modified, waiting for events...")
time.Sleep(500 * time.Millisecond) // Wait longer
// Check BoreasLite stats
if watcher.eventRing != nil {
stats := watcher.eventRing.Stats()
t.Logf("BoreasLite stats: %+v", stats)
}
if len(events) == 0 {
t.Error("No events received!")
} else {
t.Logf("SUCCESS: Got %d events", len(events))
}
}