-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathintegration_test.go
More file actions
74 lines (69 loc) · 1.73 KB
/
integration_test.go
File metadata and controls
74 lines (69 loc) · 1.73 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
package cotlib_test
import (
"bytes"
"context"
"io/fs"
"os"
"path/filepath"
"regexp"
"testing"
"time"
"github.com/NERVsystems/cotlib"
)
var (
timeRe = regexp.MustCompile(`time="[^"]*"`)
startRe = regexp.MustCompile(`start="[^"]*"`)
staleRe = regexp.MustCompile(`stale="[^"]*"`)
)
func updateTimes(data []byte) []byte {
now := time.Now().UTC().Truncate(time.Second)
start := now.Add(-2 * time.Hour)
stale := now.Add(2 * time.Hour)
data = timeRe.ReplaceAll(data, []byte("time=\""+now.Format(cotlib.CotTimeFormat)+"\""))
data = startRe.ReplaceAll(data, []byte("start=\""+start.Format(cotlib.CotTimeFormat)+"\""))
data = staleRe.ReplaceAll(data, []byte("stale=\""+stale.Format(cotlib.CotTimeFormat)+"\""))
return data
}
func TestChatSamples(t *testing.T) {
var files []string
err := filepath.WalkDir("testdata/chat_samples", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || filepath.Ext(d.Name()) != ".xml" {
return nil
}
files = append(files, path)
return nil
})
if err != nil {
t.Fatalf("walk samples: %v", err)
}
for _, path := range files {
t.Run(filepath.Base(path), func(t *testing.T) {
raw, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read file: %v", err)
}
raw = updateTimes(raw)
evt, err := cotlib.UnmarshalXMLEvent(context.Background(), raw)
if err != nil {
t.Fatalf("unmarshal: %v", err)
}
defer cotlib.ReleaseEvent(evt)
if evt.Detail == nil {
t.Fatalf("missing detail")
}
found := false
for _, u := range evt.Detail.Unknown {
if bytes.Contains(u, []byte("_flow-tags_")) {
found = true
break
}
}
if !found {
t.Error("_flow-tags_ element not captured in Unknown")
}
})
}
}