Skip to content

Commit

Permalink
Use relative urls in dash manifests
Browse files Browse the repository at this point in the history
Rewrite `have_output` matcher by composing built in matchers.
  • Loading branch information
tf committed Aug 16, 2017
1 parent 81ccc6b commit 6fb73d6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/pageflow/zencoder_video_output_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ def dash_stream_definitions
[
{
source: 'dash-low',
path: video_file.dash_low.url
path: video_file.dash_low.url_relative_to(video_file.dash_playlist)
},
{
source: 'dash-medium',
path: video_file.dash_medium.url
path: video_file.dash_medium.url_relative_to(video_file.dash_playlist)
},
{
source: 'dash-high',
path: video_file.dash_high.url
path: video_file.dash_high.url_relative_to(video_file.dash_playlist)
}
] + dash_highdef_stream_definitions
end
Expand All @@ -261,11 +261,11 @@ def dash_highdef_stream_definitions
[
{
source: 'dash-fullhd',
path: video_file.dash_fullhd.url
path: video_file.dash_fullhd.url_relative_to(video_file.dash_playlist)
},
{
source: 'dash-4k',
path: video_file.dash_4k.url
path: video_file.dash_4k.url_relative_to(video_file.dash_playlist)
}
]
end
Expand Down
9 changes: 9 additions & 0 deletions spec/pageflow/zencoder_video_output_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ module Pageflow
expect(definition).to have_output.to_s3(video_file.hls_playlist.path)
expect(definition).to have_output.to_s3(video_file.smil.path)
end

it 'uses relative urls in dash playlist' do
video_file = build(:video_file, :with_highdef_encoding)
definition = ZencoderVideoOutputDefinition.new(video_file)

expect(definition).to have_output
.with_label('dash-playlist')
.with_all_streams_having(path: a_relative_url)
end
end
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
config.infer_base_class_for_anonymous_controllers = false
config.infer_spec_type_from_file_location!

config.expect_with :rspec do |c|
c.include_chain_clauses_in_custom_matcher_descriptions = true
end

config.example_status_persistence_file_path = './tmp/rspec_failures'

config.order = "random"
Expand Down
34 changes: 28 additions & 6 deletions spec/support/matchers/have_output.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
RSpec::Matchers.define :have_output do
chain :to_s3 do |path|
@s3_url = path.prepend('s3://com-example-pageflow-out')
output_matchers[:url] = path.prepend('s3://com-example-pageflow-out')
end

chain :with_label do |label|
output_matchers[:label] = label
end

chain :with_stream do |stream_attributes|
output_matchers[:streams] = array_including(hash_including(stream_attributes))
end

chain :with_all_streams_having do |stream_attributes|
output_matchers[:streams] = all(include(stream_attributes))
end

match do |definition|
definition.outputs.detect { |output| output[:url] == @s3_url }.try(:any?)
expect(definition.outputs).to include(hash_including(output_matchers))
end

failure_message do |definition|
urls = definition.outputs.map { |output| output[:url] }
"expected to find URL #{@s3_url} in output URLs #{urls}."
"expected #{description_of @actual} to #{description}#{pretty_print_actual(definition)}"
end

failure_message do |definition|
"expected #{description_of @actual} not to #{description}#{pretty_print_actual(definition)}"
end

def pretty_print_actual(definition)
"\n\nActual:\n#{JSON.pretty_generate(definition.outputs)}"
end
failure_message_when_negated do
"expected to not find URL #{@s3_url} in output URLs, but found it."

def output_matchers
@matchers ||= {}
end
end
14 changes: 14 additions & 0 deletions spec/support/matchers/url_matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'uri'

RSpec::Matchers.define :be_relative_url do
match do |url|
begin
uri = URI.parse(url)
uri.host.nil? && !uri.path.start_with?('/')
rescue URI::InvalidURIError
false
end
end
end

RSpec::Matchers.alias_matcher :a_relative_url, :be_relative_url

0 comments on commit 6fb73d6

Please sign in to comment.