From 0f55e37c634118aad42f683a26d31239fab158b6 Mon Sep 17 00:00:00 2001 From: James Yeh Date: Thu, 30 Nov 2017 18:22:24 -0800 Subject: [PATCH] more test coverage --- provider/bitmovin/bitmovin_test.go | 178 ++++++++++++++++++++++++++++- 1 file changed, 177 insertions(+), 1 deletion(-) diff --git a/provider/bitmovin/bitmovin_test.go b/provider/bitmovin/bitmovin_test.go index 69fbb823..5634dcbe 100644 --- a/provider/bitmovin/bitmovin_test.go +++ b/provider/bitmovin/bitmovin_test.go @@ -215,6 +215,48 @@ func TestDeletePresetH264(t *testing.T) { } } +func TestDeletePresetVP8(t *testing.T) { + testPresetID := "i_want_to_delete_this" + audioPresetID := "embedded_audio_id" + customData := make(map[string]interface{}) + customData["audio"] = audioPresetID + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/encoding/configurations/video/vp8/" + testPresetID + "/customData": + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + Data: models.VP8CodecConfigurationData{ + Result: models.VP8CodecConfiguration{ + CustomData: customData, + }, + }, + } + json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/audio/vorbis/" + audioPresetID: + resp := models.VorbisCodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/h264/" + testPresetID: + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("404 - no API found with those values")) + case "/encoding/configurations/video/vp8/" + testPresetID: + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) + default: + t.Fatal(errors.New("unexpected path hit")) + } + })) + defer ts.Close() + prov := getBitmovinProvider(ts.URL) + err := prov.DeletePreset(testPresetID) + if err != nil { + t.Fatal(err) + } +} + func TestDeletePresetFailsOnAPIError(t *testing.T) { testPresetID := "i_want_to_delete_this" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -256,7 +298,7 @@ func TestDeletePresetFailsOnGenericErrors(t *testing.T) { } } -func TestGetPreset(t *testing.T) { +func TestGetPresetH264(t *testing.T) { testPresetID := "this_is_a_video_preset_id" audioPresetID := "this_is_a_audio_preset_id" customData := make(map[string]interface{}) @@ -302,6 +344,55 @@ func TestGetPreset(t *testing.T) { } } +func TestGetPresetVP8(t *testing.T) { + testPresetID := "this_is_a_video_preset_id" + audioPresetID := "this_is_a_audio_preset_id" + customData := make(map[string]interface{}) + customData["audio"] = audioPresetID + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/encoding/configurations/video/h264/" + testPresetID: + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("404 - no API found with those values")) + case "/encoding/configurations/video/vp8/" + testPresetID: + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/vp8/" + testPresetID + "/customData": + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + Data: models.VP8CodecConfigurationData{ + Result: models.VP8CodecConfiguration{ + CustomData: customData, + }, + }, + } + json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/audio/vorbis/" + audioPresetID: + resp := models.VorbisCodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) + default: + t.Fatal(errors.New("unexpected path hit")) + } + })) + defer ts.Close() + prov := getBitmovinProvider(ts.URL) + i, err := prov.GetPreset(testPresetID) + if err != nil { + t.Fatal(err) + } + expected := bitmovinVP8Preset{ + Video: models.VP8CodecConfiguration{CustomData: customData}, + Audio: models.VorbisCodecConfiguration{}, + } + if !reflect.DeepEqual(i, expected) { + t.Errorf("GetPreset: want %#v. Got %#v", expected, i) + } +} + func TestGetPresetFailsOnAPIError(t *testing.T) { testPresetID := "this_is_a_video_preset_id" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -415,6 +506,19 @@ func TestTranscodeWithS3Input(t *testing.T) { }, } json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/vp8/videoID4/customData": + customData := make(map[string]interface{}) + customData["audio"] = "audioID4" + customData["container"] = "webm" + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + Data: models.VP8CodecConfigurationData{ + Result: models.VP8CodecConfiguration{ + CustomData: customData, + }, + }, + } + json.NewEncoder(w).Encode(resp) case "/encoding/manifests/hls": resp := models.HLSManifestResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -442,6 +546,14 @@ func TestTranscodeWithS3Input(t *testing.T) { Status: bitmovintypes.ResponseStatusSuccess, } json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/h264/videoID4": + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("404 - no API found with those values")) + case "/encoding/configurations/video/vp8/videoID4": + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) case "/encoding/encodings/" + encodingID + "/streams": resp := models.StreamResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -467,6 +579,11 @@ func TestTranscodeWithS3Input(t *testing.T) { }, } json.NewEncoder(w).Encode(resp) + case "/encoding/encodings/" + encodingID + "/muxings/progressive-webm": + resp := models.MP4MuxingResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) case "/encoding/manifests/hls/" + manifestID + "/media": resp := models.MediaInfoResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -568,6 +685,19 @@ func TestTranscodeWithHTTPInput(t *testing.T) { }, } json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/vp8/videoID4/customData": + customData := make(map[string]interface{}) + customData["audio"] = "audioID4" + customData["container"] = "webm" + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + Data: models.VP8CodecConfigurationData{ + Result: models.VP8CodecConfiguration{ + CustomData: customData, + }, + }, + } + json.NewEncoder(w).Encode(resp) case "/encoding/manifests/hls": resp := models.HLSManifestResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -595,6 +725,14 @@ func TestTranscodeWithHTTPInput(t *testing.T) { Status: bitmovintypes.ResponseStatusSuccess, } json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/h264/videoID4": + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("404 - no API found with those values")) + case "/encoding/configurations/video/vp8/videoID4": + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) case "/encoding/encodings/" + encodingID + "/streams": resp := models.StreamResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -620,6 +758,11 @@ func TestTranscodeWithHTTPInput(t *testing.T) { }, } json.NewEncoder(w).Encode(resp) + case "/encoding/encodings/" + encodingID + "/muxings/progressive-webm": + resp := models.MP4MuxingResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) case "/encoding/manifests/hls/" + manifestID + "/media": resp := models.MediaInfoResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -721,6 +864,19 @@ func TestTranscodeWithHTTPSInput(t *testing.T) { }, } json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/vp8/videoID4/customData": + customData := make(map[string]interface{}) + customData["audio"] = "audioID4" + customData["container"] = "webm" + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + Data: models.VP8CodecConfigurationData{ + Result: models.VP8CodecConfiguration{ + CustomData: customData, + }, + }, + } + json.NewEncoder(w).Encode(resp) case "/encoding/manifests/hls": resp := models.HLSManifestResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -748,6 +904,14 @@ func TestTranscodeWithHTTPSInput(t *testing.T) { Status: bitmovintypes.ResponseStatusSuccess, } json.NewEncoder(w).Encode(resp) + case "/encoding/configurations/video/h264/videoID4": + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("404 - no API found with those values")) + case "/encoding/configurations/video/vp8/videoID4": + resp := models.VP8CodecConfigurationResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) case "/encoding/encodings/" + encodingID + "/streams": resp := models.StreamResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -773,6 +937,11 @@ func TestTranscodeWithHTTPSInput(t *testing.T) { }, } json.NewEncoder(w).Encode(resp) + case "/encoding/encodings/" + encodingID + "/muxings/progressive-webm": + resp := models.MP4MuxingResponse{ + Status: bitmovintypes.ResponseStatusSuccess, + } + json.NewEncoder(w).Encode(resp) case "/encoding/manifests/hls/" + manifestID + "/media": resp := models.MediaInfoResponse{ Status: bitmovintypes.ResponseStatusSuccess, @@ -1504,6 +1673,13 @@ func getJob(sourceMedia string) *db.Job { }, OutputOpts: db.OutputOptions{Extension: "m3u8"}, }, + { + Name: "webm_480p", + ProviderMapping: map[string]string{ + Name: "videoID4", + }, + OutputOpts: db.OutputOptions{Extension: "webm"}, + }, } outputs := make([]db.TranscodeOutput, len(presets)) for i, preset := range presets {