-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlogsrc_test.go
112 lines (104 loc) · 4.31 KB
/
logsrc_test.go
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"testing"
"time"
"github.com/leighmacdonald/steamid/v4/steamid"
"github.com/stretchr/testify/require"
)
func TestParseEvent(t *testing.T) {
type tc struct {
text string
match bool
expected LogEvent
}
timeStamp := time.Date(2023, time.February, 24, 23, 37, 19, 0, time.UTC)
cases := []tc{
{
text: "02/24/2023 - 23:37:19: PopcornBucketGames : I did tell you vix.",
match: true,
expected: LogEvent{Type: EvtMsg, Player: "PopcornBucketGames", Message: "I did tell you vix.", Timestamp: timeStamp},
},
{
text: "02/24/2023 - 23:37:19: *DEAD* that's pretty thick-headed : ty",
match: true,
expected: LogEvent{Type: EvtMsg, Player: "that's pretty thick-headed", Message: "ty", Timestamp: timeStamp, Dead: true},
},
{
text: "02/24/2023 - 23:37:19: *DEAD*(TEAM) Hassium : thats the problem vixian",
match: true,
expected: LogEvent{Type: EvtMsg, Player: "Hassium", Message: "thats the problem vixian", Timestamp: timeStamp, Dead: true, TeamOnly: true},
},
{
text: "02/24/2023 - 23:37:19: ❤ Ashley ❤ killed [TrC] Nosy with spy_cicle.",
match: true,
expected: LogEvent{Type: EvtKill, Player: "❤ Ashley ❤", Victim: "[TrC] Nosy", Timestamp: timeStamp},
},
{
text: "02/24/2023 - 23:37:19: ❤ Ashley ❤ killed [TrC] Nosy with spy_cicle. (crit)",
match: true,
expected: LogEvent{Type: EvtKill, Player: "❤ Ashley ❤", Victim: "[TrC] Nosy", Timestamp: timeStamp},
},
{
text: "02/24/2023 - 23:37:19: Hassium connected",
match: true,
expected: LogEvent{Type: EvtConnect, Player: "Hassium", Timestamp: timeStamp},
},
{
text: "02/24/2023 - 23:37:19: # 672 \"🎄AndreaJingling🎄\" [U:1:238393055] 42:57 62 0 active",
match: true,
expected: LogEvent{
Type: EvtStatusID, Timestamp: timeStamp, PlayerPing: 62, UserID: 672, Player: "🎄AndreaJingling🎄",
PlayerSID: steamid.New(76561198198658783), PlayerConnected: time.Duration(2577000000000),
},
},
{
text: "02/24/2023 - 23:37:19: # 672 \"some nerd\" [U:1:238393055] 42:57:02 62 0 active",
match: true,
expected: LogEvent{
Type: EvtStatusID, Timestamp: timeStamp, PlayerPing: 62, UserID: 672, Player: "some nerd",
PlayerSID: steamid.New(76561198198658783), PlayerConnected: time.Duration(154622000000000),
},
},
{
text: "02/24/2023 - 23:37:19: hostname: Uncletopia | Seattle | 1 | All Maps",
match: true,
expected: LogEvent{Type: EvtHostname, Timestamp: timeStamp, MetaData: "Uncletopia | Seattle | 1 | All Maps"},
},
{
text: "02/24/2023 - 23:37:19: map : pl_swiftwater_final1 at: 0 x, 0 y, 0 z",
match: true,
expected: LogEvent{Type: EvtMap, Timestamp: timeStamp, MetaData: "pl_swiftwater_final1"},
},
{
text: "02/24/2023 - 23:37:19: tags : nocrits,nodmgspread,payload,uncletopia",
match: true,
expected: LogEvent{Type: EvtTags, Timestamp: timeStamp, MetaData: "nocrits,nodmgspread,payload,uncletopia"},
},
{
text: "02/24/2023 - 23:37:19: udp/ip : 74.91.117.2:27015",
match: true,
expected: LogEvent{Type: EvtAddress, Timestamp: timeStamp, MetaData: "74.91.117.2:27015"},
},
{
// 02/26/2023 - 16:45:43: Disconnect: #TF_Idle_kicked.
// 02/26/2023 - 16:39:59: Connected to 169.254.174.254:26128
// 02/26/2023 - 16:32:28: ุ has been idle for too long and has been kicked
// 03/09/2023 - 01:08:03: Differing lobby received. Lobby: [A:1:1191368713:22805]/Match79636263/Lobby601530352177650 CurrentlyAssigned: [A:1:1191368713:22805]/Match79636024/Lobby601530352177650 ConnectedToMatchServer: 1 HasLobby: 1 AssignedMatchEnded: 0
text: "02/24/2023 - 23:37:19: Differing lobby received. Lobby: [A:1:1191368713:22805]/Match79636263/Lobby601530352177650 CurrentlyAssigned: [A:1:1191368713:22805]/Match79636024/Lobby601530352177650 ConnectedToMatchServer: 1 HasLobby: 1 AssignedMatchEnded: 0",
match: true,
expected: LogEvent{Type: EvtDisconnect, Timestamp: timeStamp, MetaData: "Differing lobby received."},
},
}
reader := newLogParser()
for num, testCase := range cases {
var (
event LogEvent
err = reader.parse(testCase.text, &event)
)
if testCase.match {
require.EqualValuesf(t, testCase.expected, event, "Test failed: %d", num)
} else {
require.ErrorIs(t, err, ErrNoMatch)
}
}
}