-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtmplog_test.go
151 lines (149 loc) · 6.42 KB
/
rtmplog_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package cflogparser
import (
"net"
"reflect"
"testing"
"time"
)
func TestParseRTMPLogSamples(t *testing.T) {
tests := []struct {
in string
out *RTMPLog
}{
// Log samples is borrowed from here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html
{
`2010-03-12 23:51:20 SEA4 192.0.2.147 connect 2014 OK bfd8a98bee0840d9b871b7f6ade9908f rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st key=value http://player.longtailvideo.com/player.swf http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204 LNX%2010,0,32,18 - - - -`,
&RTMPLog{
Time: time.Date(2010, 3, 12, 23, 51, 20, 0, time.UTC),
Location: "SEA4",
RequestIP: net.ParseIP("192.0.2.147"),
EventType: "connect",
Bytes: 2014,
Status: "OK",
ClientID: "bfd8a98bee0840d9b871b7f6ade9908f",
URI: "rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st",
QueryString: "key=value",
Referrer: "http://player.longtailvideo.com/player.swf",
PageURL: "http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204",
UserAgent: "LNX 10,0,32,18",
StreamName: "",
StreamQuery: "",
StreamFileExt: "",
StreamID: 0,
},
},
{
`2010-03-12 23:51:21 SEA4 192.0.2.222 play 3914 OK bfd8a98bee0840d9b871b7f6ade9908f rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st key=value http://player.longtailvideo.com/player.swf http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204 LNX%2010,0,32,18 myvideo p=2&q=4 flv 1`,
&RTMPLog{
Time: time.Date(2010, 3, 12, 23, 51, 21, 0, time.UTC),
Location: "SEA4",
RequestIP: net.ParseIP("192.0.2.222"),
EventType: "play",
Bytes: 3914,
Status: "OK",
ClientID: "bfd8a98bee0840d9b871b7f6ade9908f",
URI: "rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st",
QueryString: "key=value",
Referrer: "http://player.longtailvideo.com/player.swf",
PageURL: "http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204",
UserAgent: "LNX 10,0,32,18",
StreamName: "myvideo",
StreamQuery: "p=2&q=4",
StreamFileExt: "flv",
StreamID: 1,
},
},
{
`2010-03-12 23:53:44 SEA4 192.0.2.4 stop 323914 OK bfd8a98bee0840d9b871b7f6ade9908f rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st key=value http://player.longtailvideo.com/player.swf http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204 LNX%2010,0,32,18 dir/other/myvideo p=2&q=4 flv 1`,
&RTMPLog{
Time: time.Date(2010, 3, 12, 23, 53, 44, 0, time.UTC),
Location: "SEA4",
RequestIP: net.ParseIP("192.0.2.4"),
EventType: "stop",
Bytes: 323914,
Status: "OK",
ClientID: "bfd8a98bee0840d9b871b7f6ade9908f",
URI: "rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st",
QueryString: "key=value",
Referrer: "http://player.longtailvideo.com/player.swf",
PageURL: "http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204",
UserAgent: "LNX 10,0,32,18",
StreamName: "dir/other/myvideo",
StreamQuery: "p=2&q=4",
StreamFileExt: "flv",
StreamID: 1,
},
},
{
`2010-03-12 23:53:44 SEA4 192.0.2.103 play 8783724 OK bfd8a98bee0840d9b871b7f6ade9908f rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st key=value http://player.longtailvideo.com/player.swf http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204 LNX%2010,0,32,18 dir/favs/myothervideo p=42&q=14 mp4 2`,
&RTMPLog{
Time: time.Date(2010, 3, 12, 23, 53, 44, 0, time.UTC),
Location: "SEA4",
RequestIP: net.ParseIP("192.0.2.103"),
EventType: "play",
Bytes: 8783724,
Status: "OK",
ClientID: "bfd8a98bee0840d9b871b7f6ade9908f",
URI: "rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st",
QueryString: "key=value",
Referrer: "http://player.longtailvideo.com/player.swf",
PageURL: "http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204",
UserAgent: "LNX 10,0,32,18",
StreamName: "dir/favs/myothervideo",
StreamQuery: "p=42&q=14",
StreamFileExt: "mp4",
StreamID: 2,
},
},
{
`2010-03-12 23:56:21 SEA4 192.0.2.199 stop 429822014 OK bfd8a98bee0840d9b871b7f6ade9908f rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st key=value http://player.longtailvideo.com/player.swf http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204 LNX%2010,0,32,18 dir/favs/myothervideo p=42&q=14 mp4 2`,
&RTMPLog{
Time: time.Date(2010, 3, 12, 23, 56, 21, 0, time.UTC),
Location: "SEA4",
RequestIP: net.ParseIP("192.0.2.199"),
EventType: "stop",
Bytes: 429822014,
Status: "OK",
ClientID: "bfd8a98bee0840d9b871b7f6ade9908f",
URI: "rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st",
QueryString: "key=value",
Referrer: "http://player.longtailvideo.com/player.swf",
PageURL: "http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204",
UserAgent: "LNX 10,0,32,18",
StreamName: "dir/favs/myothervideo",
StreamQuery: "p=42&q=14",
StreamFileExt: "mp4",
StreamID: 2,
},
},
{
`2010-03-12 23:59:44 SEA4 192.0.2.14 disconnect 429824092 OK bfd8a98bee0840d9b871b7f6ade9908f rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st key=value http://player.longtailvideo.com/player.swf http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204 LNX%2010,0,32,18 - - - -`,
&RTMPLog{
Time: time.Date(2010, 3, 12, 23, 59, 44, 0, time.UTC),
Location: "SEA4",
RequestIP: net.ParseIP("192.0.2.14"),
EventType: "disconnect",
Bytes: 429824092,
Status: "OK",
ClientID: "bfd8a98bee0840d9b871b7f6ade9908f",
URI: "rtmp://shqshne4jdp4b6.cloudfront.net/cfx/st",
QueryString: "key=value",
Referrer: "http://player.longtailvideo.com/player.swf",
PageURL: "http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204",
UserAgent: "LNX 10,0,32,18",
StreamName: "",
StreamQuery: "",
StreamFileExt: "",
StreamID: 0,
},
},
}
for _, test := range tests {
log, err := ParseLineRTMP(test.in)
if err != nil {
t.Error(err)
} else if !reflect.DeepEqual(log, test.out) {
t.Errorf(`got %v, want %v`, log, test.out)
}
}
}