Skip to content

Commit

Permalink
more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
James Yeh committed Dec 1, 2017
1 parent d0f4237 commit 0f55e37
Showing 1 changed file with 177 additions and 1 deletion.
178 changes: 177 additions & 1 deletion provider/bitmovin/bitmovin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0f55e37

Please sign in to comment.