Skip to content

Commit 0f55e37

Browse files
author
James Yeh
committed
more test coverage
1 parent d0f4237 commit 0f55e37

File tree

1 file changed

+177
-1
lines changed

1 file changed

+177
-1
lines changed

provider/bitmovin/bitmovin_test.go

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,48 @@ func TestDeletePresetH264(t *testing.T) {
215215
}
216216
}
217217

218+
func TestDeletePresetVP8(t *testing.T) {
219+
testPresetID := "i_want_to_delete_this"
220+
audioPresetID := "embedded_audio_id"
221+
customData := make(map[string]interface{})
222+
customData["audio"] = audioPresetID
223+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
224+
switch r.URL.Path {
225+
case "/encoding/configurations/video/vp8/" + testPresetID + "/customData":
226+
resp := models.VP8CodecConfigurationResponse{
227+
Status: bitmovintypes.ResponseStatusSuccess,
228+
Data: models.VP8CodecConfigurationData{
229+
Result: models.VP8CodecConfiguration{
230+
CustomData: customData,
231+
},
232+
},
233+
}
234+
json.NewEncoder(w).Encode(resp)
235+
case "/encoding/configurations/audio/vorbis/" + audioPresetID:
236+
resp := models.VorbisCodecConfigurationResponse{
237+
Status: bitmovintypes.ResponseStatusSuccess,
238+
}
239+
json.NewEncoder(w).Encode(resp)
240+
case "/encoding/configurations/video/h264/" + testPresetID:
241+
w.WriteHeader(http.StatusNotFound)
242+
w.Write([]byte("404 - no API found with those values"))
243+
case "/encoding/configurations/video/vp8/" + testPresetID:
244+
resp := models.VP8CodecConfigurationResponse{
245+
Status: bitmovintypes.ResponseStatusSuccess,
246+
}
247+
json.NewEncoder(w).Encode(resp)
248+
default:
249+
t.Fatal(errors.New("unexpected path hit"))
250+
}
251+
}))
252+
defer ts.Close()
253+
prov := getBitmovinProvider(ts.URL)
254+
err := prov.DeletePreset(testPresetID)
255+
if err != nil {
256+
t.Fatal(err)
257+
}
258+
}
259+
218260
func TestDeletePresetFailsOnAPIError(t *testing.T) {
219261
testPresetID := "i_want_to_delete_this"
220262
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -256,7 +298,7 @@ func TestDeletePresetFailsOnGenericErrors(t *testing.T) {
256298
}
257299
}
258300

259-
func TestGetPreset(t *testing.T) {
301+
func TestGetPresetH264(t *testing.T) {
260302
testPresetID := "this_is_a_video_preset_id"
261303
audioPresetID := "this_is_a_audio_preset_id"
262304
customData := make(map[string]interface{})
@@ -302,6 +344,55 @@ func TestGetPreset(t *testing.T) {
302344
}
303345
}
304346

347+
func TestGetPresetVP8(t *testing.T) {
348+
testPresetID := "this_is_a_video_preset_id"
349+
audioPresetID := "this_is_a_audio_preset_id"
350+
customData := make(map[string]interface{})
351+
customData["audio"] = audioPresetID
352+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
353+
switch r.URL.Path {
354+
case "/encoding/configurations/video/h264/" + testPresetID:
355+
w.WriteHeader(http.StatusNotFound)
356+
w.Write([]byte("404 - no API found with those values"))
357+
case "/encoding/configurations/video/vp8/" + testPresetID:
358+
resp := models.VP8CodecConfigurationResponse{
359+
Status: bitmovintypes.ResponseStatusSuccess,
360+
}
361+
json.NewEncoder(w).Encode(resp)
362+
case "/encoding/configurations/video/vp8/" + testPresetID + "/customData":
363+
resp := models.VP8CodecConfigurationResponse{
364+
Status: bitmovintypes.ResponseStatusSuccess,
365+
Data: models.VP8CodecConfigurationData{
366+
Result: models.VP8CodecConfiguration{
367+
CustomData: customData,
368+
},
369+
},
370+
}
371+
json.NewEncoder(w).Encode(resp)
372+
case "/encoding/configurations/audio/vorbis/" + audioPresetID:
373+
resp := models.VorbisCodecConfigurationResponse{
374+
Status: bitmovintypes.ResponseStatusSuccess,
375+
}
376+
json.NewEncoder(w).Encode(resp)
377+
default:
378+
t.Fatal(errors.New("unexpected path hit"))
379+
}
380+
}))
381+
defer ts.Close()
382+
prov := getBitmovinProvider(ts.URL)
383+
i, err := prov.GetPreset(testPresetID)
384+
if err != nil {
385+
t.Fatal(err)
386+
}
387+
expected := bitmovinVP8Preset{
388+
Video: models.VP8CodecConfiguration{CustomData: customData},
389+
Audio: models.VorbisCodecConfiguration{},
390+
}
391+
if !reflect.DeepEqual(i, expected) {
392+
t.Errorf("GetPreset: want %#v. Got %#v", expected, i)
393+
}
394+
}
395+
305396
func TestGetPresetFailsOnAPIError(t *testing.T) {
306397
testPresetID := "this_is_a_video_preset_id"
307398
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -415,6 +506,19 @@ func TestTranscodeWithS3Input(t *testing.T) {
415506
},
416507
}
417508
json.NewEncoder(w).Encode(resp)
509+
case "/encoding/configurations/video/vp8/videoID4/customData":
510+
customData := make(map[string]interface{})
511+
customData["audio"] = "audioID4"
512+
customData["container"] = "webm"
513+
resp := models.VP8CodecConfigurationResponse{
514+
Status: bitmovintypes.ResponseStatusSuccess,
515+
Data: models.VP8CodecConfigurationData{
516+
Result: models.VP8CodecConfiguration{
517+
CustomData: customData,
518+
},
519+
},
520+
}
521+
json.NewEncoder(w).Encode(resp)
418522
case "/encoding/manifests/hls":
419523
resp := models.HLSManifestResponse{
420524
Status: bitmovintypes.ResponseStatusSuccess,
@@ -442,6 +546,14 @@ func TestTranscodeWithS3Input(t *testing.T) {
442546
Status: bitmovintypes.ResponseStatusSuccess,
443547
}
444548
json.NewEncoder(w).Encode(resp)
549+
case "/encoding/configurations/video/h264/videoID4":
550+
w.WriteHeader(http.StatusNotFound)
551+
w.Write([]byte("404 - no API found with those values"))
552+
case "/encoding/configurations/video/vp8/videoID4":
553+
resp := models.VP8CodecConfigurationResponse{
554+
Status: bitmovintypes.ResponseStatusSuccess,
555+
}
556+
json.NewEncoder(w).Encode(resp)
445557
case "/encoding/encodings/" + encodingID + "/streams":
446558
resp := models.StreamResponse{
447559
Status: bitmovintypes.ResponseStatusSuccess,
@@ -467,6 +579,11 @@ func TestTranscodeWithS3Input(t *testing.T) {
467579
},
468580
}
469581
json.NewEncoder(w).Encode(resp)
582+
case "/encoding/encodings/" + encodingID + "/muxings/progressive-webm":
583+
resp := models.MP4MuxingResponse{
584+
Status: bitmovintypes.ResponseStatusSuccess,
585+
}
586+
json.NewEncoder(w).Encode(resp)
470587
case "/encoding/manifests/hls/" + manifestID + "/media":
471588
resp := models.MediaInfoResponse{
472589
Status: bitmovintypes.ResponseStatusSuccess,
@@ -568,6 +685,19 @@ func TestTranscodeWithHTTPInput(t *testing.T) {
568685
},
569686
}
570687
json.NewEncoder(w).Encode(resp)
688+
case "/encoding/configurations/video/vp8/videoID4/customData":
689+
customData := make(map[string]interface{})
690+
customData["audio"] = "audioID4"
691+
customData["container"] = "webm"
692+
resp := models.VP8CodecConfigurationResponse{
693+
Status: bitmovintypes.ResponseStatusSuccess,
694+
Data: models.VP8CodecConfigurationData{
695+
Result: models.VP8CodecConfiguration{
696+
CustomData: customData,
697+
},
698+
},
699+
}
700+
json.NewEncoder(w).Encode(resp)
571701
case "/encoding/manifests/hls":
572702
resp := models.HLSManifestResponse{
573703
Status: bitmovintypes.ResponseStatusSuccess,
@@ -595,6 +725,14 @@ func TestTranscodeWithHTTPInput(t *testing.T) {
595725
Status: bitmovintypes.ResponseStatusSuccess,
596726
}
597727
json.NewEncoder(w).Encode(resp)
728+
case "/encoding/configurations/video/h264/videoID4":
729+
w.WriteHeader(http.StatusNotFound)
730+
w.Write([]byte("404 - no API found with those values"))
731+
case "/encoding/configurations/video/vp8/videoID4":
732+
resp := models.VP8CodecConfigurationResponse{
733+
Status: bitmovintypes.ResponseStatusSuccess,
734+
}
735+
json.NewEncoder(w).Encode(resp)
598736
case "/encoding/encodings/" + encodingID + "/streams":
599737
resp := models.StreamResponse{
600738
Status: bitmovintypes.ResponseStatusSuccess,
@@ -620,6 +758,11 @@ func TestTranscodeWithHTTPInput(t *testing.T) {
620758
},
621759
}
622760
json.NewEncoder(w).Encode(resp)
761+
case "/encoding/encodings/" + encodingID + "/muxings/progressive-webm":
762+
resp := models.MP4MuxingResponse{
763+
Status: bitmovintypes.ResponseStatusSuccess,
764+
}
765+
json.NewEncoder(w).Encode(resp)
623766
case "/encoding/manifests/hls/" + manifestID + "/media":
624767
resp := models.MediaInfoResponse{
625768
Status: bitmovintypes.ResponseStatusSuccess,
@@ -721,6 +864,19 @@ func TestTranscodeWithHTTPSInput(t *testing.T) {
721864
},
722865
}
723866
json.NewEncoder(w).Encode(resp)
867+
case "/encoding/configurations/video/vp8/videoID4/customData":
868+
customData := make(map[string]interface{})
869+
customData["audio"] = "audioID4"
870+
customData["container"] = "webm"
871+
resp := models.VP8CodecConfigurationResponse{
872+
Status: bitmovintypes.ResponseStatusSuccess,
873+
Data: models.VP8CodecConfigurationData{
874+
Result: models.VP8CodecConfiguration{
875+
CustomData: customData,
876+
},
877+
},
878+
}
879+
json.NewEncoder(w).Encode(resp)
724880
case "/encoding/manifests/hls":
725881
resp := models.HLSManifestResponse{
726882
Status: bitmovintypes.ResponseStatusSuccess,
@@ -748,6 +904,14 @@ func TestTranscodeWithHTTPSInput(t *testing.T) {
748904
Status: bitmovintypes.ResponseStatusSuccess,
749905
}
750906
json.NewEncoder(w).Encode(resp)
907+
case "/encoding/configurations/video/h264/videoID4":
908+
w.WriteHeader(http.StatusNotFound)
909+
w.Write([]byte("404 - no API found with those values"))
910+
case "/encoding/configurations/video/vp8/videoID4":
911+
resp := models.VP8CodecConfigurationResponse{
912+
Status: bitmovintypes.ResponseStatusSuccess,
913+
}
914+
json.NewEncoder(w).Encode(resp)
751915
case "/encoding/encodings/" + encodingID + "/streams":
752916
resp := models.StreamResponse{
753917
Status: bitmovintypes.ResponseStatusSuccess,
@@ -773,6 +937,11 @@ func TestTranscodeWithHTTPSInput(t *testing.T) {
773937
},
774938
}
775939
json.NewEncoder(w).Encode(resp)
940+
case "/encoding/encodings/" + encodingID + "/muxings/progressive-webm":
941+
resp := models.MP4MuxingResponse{
942+
Status: bitmovintypes.ResponseStatusSuccess,
943+
}
944+
json.NewEncoder(w).Encode(resp)
776945
case "/encoding/manifests/hls/" + manifestID + "/media":
777946
resp := models.MediaInfoResponse{
778947
Status: bitmovintypes.ResponseStatusSuccess,
@@ -1504,6 +1673,13 @@ func getJob(sourceMedia string) *db.Job {
15041673
},
15051674
OutputOpts: db.OutputOptions{Extension: "m3u8"},
15061675
},
1676+
{
1677+
Name: "webm_480p",
1678+
ProviderMapping: map[string]string{
1679+
Name: "videoID4",
1680+
},
1681+
OutputOpts: db.OutputOptions{Extension: "webm"},
1682+
},
15071683
}
15081684
outputs := make([]db.TranscodeOutput, len(presets))
15091685
for i, preset := range presets {

0 commit comments

Comments
 (0)