File tree 2 files changed +71
-16
lines changed
2 files changed +71
-16
lines changed Original file line number Diff line number Diff line change 1
1
package encodingcom
2
2
3
- import (
4
- "encoding/json"
5
- "log"
6
- )
3
+ import "encoding/json"
7
4
8
5
const (
9
6
// AllPresets is used to retrieve all presets in the response of
@@ -86,21 +83,17 @@ type PresetFormat struct {
86
83
// Stream function returns a slice of Advanced HLS stream settings for a
87
84
// preset format.
88
85
func (p PresetFormat ) Stream () []Stream {
89
- streamSlice := []Stream {}
90
- newStream := Stream {}
86
+ var (
87
+ stream Stream
88
+ streams []Stream
89
+ )
91
90
streamRaw , _ := json .Marshal (p .StreamRawMap )
92
- err := json .Unmarshal (streamRaw , & newStream )
93
- if err != nil {
94
- errWithSlice := json .Unmarshal (streamRaw , & streamSlice )
95
- if errWithSlice != nil {
96
- log .Printf ("Could NOT parse Preset stream data into Stream object: %s" , err .Error ())
97
- log .Printf ("Could NOT parse Preset stream data into Stream slice: %s" , errWithSlice .Error ())
98
- return streamSlice
99
- }
91
+ if err := json .Unmarshal (streamRaw , & stream ); err != nil {
92
+ json .Unmarshal (streamRaw , & streams )
100
93
} else {
101
- streamSlice = append (streamSlice , newStream )
94
+ streams = append (streams , stream )
102
95
}
103
- return streamSlice
96
+ return streams
104
97
}
105
98
106
99
// SavePresetResponse is the response returned in the SavePreset method.
Original file line number Diff line number Diff line change @@ -267,6 +267,68 @@ func (s *S) TestGetPresetsList(c *check.C) {
267
267
}
268
268
}
269
269
270
+ func (s * S ) TestPresetFormatStream (c * check.C ) {
271
+ var tests = []struct {
272
+ testCase string
273
+ streamRaw interface {}
274
+ expected []Stream
275
+ }{
276
+ {
277
+ "single stream" ,
278
+ map [string ]interface {}{
279
+ "audio_bitrate" : "64k" ,
280
+ "audio_volume" : "100" ,
281
+ "size" : "1080x720" ,
282
+ "two_pass" : "yes" ,
283
+ },
284
+ []Stream {
285
+ {
286
+ AudioBitrate : "64k" ,
287
+ AudioVolume : 100 ,
288
+ Size : "1080x720" ,
289
+ TwoPass : YesNoBoolean (true ),
290
+ },
291
+ },
292
+ },
293
+ {
294
+ "multiple streams" ,
295
+ []map [string ]interface {}{
296
+ {
297
+ "audio_bitrate" : "64k" ,
298
+ "audio_volume" : "100" ,
299
+ "size" : "1080x720" ,
300
+ "two_pass" : "yes" ,
301
+ },
302
+ {
303
+ "audio_bitrate" : "128k" ,
304
+ "audio_volume" : "100" ,
305
+ "size" : "1920x1080" ,
306
+ "two_pass" : "yes" ,
307
+ },
308
+ },
309
+ []Stream {
310
+ {
311
+ AudioBitrate : "64k" ,
312
+ AudioVolume : 100 ,
313
+ Size : "1080x720" ,
314
+ TwoPass : YesNoBoolean (true ),
315
+ },
316
+ {
317
+ AudioBitrate : "128k" ,
318
+ AudioVolume : 100 ,
319
+ Size : "1920x1080" ,
320
+ TwoPass : YesNoBoolean (true ),
321
+ },
322
+ },
323
+ },
324
+ }
325
+ for _ , test := range tests {
326
+ p := PresetFormat {StreamRawMap : test .streamRaw }
327
+ streams := p .Stream ()
328
+ c .Check (streams , check .DeepEquals , test .expected )
329
+ }
330
+ }
331
+
270
332
func (s * S ) TestGetPreset (c * check.C ) {
271
333
server , requests := s .startServer (`
272
334
{
You can’t perform that action at this time.
0 commit comments