generated from streamingriver/template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
157 lines (140 loc) · 3.56 KB
/
main_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
152
153
154
155
156
157
package main
import (
"bytes"
"log"
"testing"
)
type FakeLogOutput struct {
t *testing.T
}
func (log FakeLogOutput) Write(b []byte) (int, error) {
log.t.Logf("%s", b)
return len(b), nil
}
var programsDataFfmpeg = []byte(`
{
"videoffmpeg" : [
{
"name": "test",
"url": "http://test"
},
{
"name": "anothertest1",
"url": "http://anothertest1"
}
]
}
`)
var programsDataCache = []byte(`
{
"videocache" : [
{
"name": "test",
"url": "http://test"
},
{
"name": "anothertest1",
"url": "http://anothertest1"
}
]
}
`)
var programsDataFfmpegExpected = `[program:test]
command=/bin/bash -c "mkdir -p /dev/shm/test; cd /dev/shm/test; /ffmpeg -nostats -nostdin -user-agent "streamingriveriptv/1.0" -i "http://test" -codec copy -map 0:0 -map 0:1 -map_metadata 0 -f hls -hls_list_size 3 -hls_flags delete_segments -hls_time 5 -segment_list_size 3 -hls_segment_filename file%%07d.ts stream.m3u8"
autostart = true
startsec = 1
user = root
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
autorestart=true
startretries=5000000000
stopasgroup=true
killasgroup=true
stdout_events_enabled=true
stderr_events_enabled=true
[program:anothertest1]
command=/bin/bash -c "mkdir -p /dev/shm/anothertest1; cd /dev/shm/anothertest1; /ffmpeg -nostats -nostdin -user-agent "streamingriveriptv/1.0" -i "http://anothertest1" -codec copy -map 0:0 -map 0:1 -map_metadata 0 -f hls -hls_list_size 3 -hls_flags delete_segments -hls_time 5 -segment_list_size 3 -hls_segment_filename file%%07d.ts stream.m3u8"
autostart = true
startsec = 1
user = root
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
autorestart=true
startretries=5000000000
stopasgroup=true
killasgroup=true
stdout_events_enabled=true
stderr_events_enabled=true
`
var programsDataCacheExpected = `[program:proxy-test]
command=/opt/tools/hls-proxy_linux_amd64 --url "http://localhost:9005/test/stream.m3u8" --name "test" --frontend http://127.0.0.1:8085
autostart = true
startsec = 1
user = root
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
autorestart=true
startretries=5000000000
stopasgroup=true
killasgroup=true
stdout_events_enabled=true
stderr_events_enabled=true
[program:proxy-anothertest1]
command=/opt/tools/hls-proxy_linux_amd64 --url "http://localhost:9005/anothertest1/stream.m3u8" --name "anothertest1" --frontend http://127.0.0.1:8085
autostart = true
startsec = 1
user = root
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
autorestart=true
startretries=5000000000
stopasgroup=true
killasgroup=true
stdout_events_enabled=true
stderr_events_enabled=true
`
type MyWriter struct {
t *testing.T
buff *bytes.Buffer
}
func (mw MyWriter) Write(b []byte) (int, error) {
mw.buff.Write(b)
return len(b), nil
}
func (mw MyWriter) Close() error { return nil }
func TestParserFFMPEG(t *testing.T) {
writer := &MyWriter{t, bytes.NewBuffer(nil)}
app := &App{}
parser := &Parser{
app,
log.New(&FakeLogOutput{t}, "", 0),
"ffmpeg",
writer,
}
parser.Parse(programsDataFfmpeg)
if string(writer.buff.Bytes()) != programsDataFfmpegExpected {
t.Errorf("Unexpected output, %s", writer.buff.String())
}
}
func TestParserCache(t *testing.T) {
app := &App{}
writer := &MyWriter{t, bytes.NewBuffer(nil)}
parser := &Parser{
app,
log.New(&FakeLogOutput{t}, "", 0),
"cache",
writer,
}
parser.Parse(programsDataCache)
if string(writer.buff.Bytes()) != programsDataCacheExpected {
t.Errorf("Unexpected output,")
}
}