Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Mar 26, 2019
1 parent b7fc766 commit 84d70eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/kubernetes-deploy/render_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ def render_filename(filename, stream)
@logger.info("Rendering #{File.basename(filename)} ...")
file_content = File.read(File.join(@template_dir, filename))
rendered_content = @renderer.render_template(filename, file_content)
YAML.load_stream(rendered_content, "<rendered> #{filename}") do |doc|
YAML.dump(doc)
end
implicit = true
YAML.parse_stream(rendered_content) { |d| implicit = d.implicit }
YAML.parse_stream(rendered_content, "<rendered> #{filename}") { |d| implicit = d.implicit }
stream.puts "---\n" if implicit
stream.puts rendered_content
@logger.info("Rendered #{File.basename(filename)}")
Expand Down
22 changes: 22 additions & 0 deletions test/integration/render_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,28 @@ def test_render_valid_fixtures
end
end

def test_render_only_adds_initial_doc_seperator_when_missing
render = build_render_task(fixture_path('partials'))
fixture = 'no-doc-seperator.yml'
expected = "---\n# This doc has no yaml seperator\nkey1: foo\n"

assert_render_success(render.run(mock_output_stream, [fixture]))
stdout_assertion do |output|
assert_equal expected, output
end
end

def test_render_preserves_duplicate_keys_adds_doc_initial_seperator_when_needed
render = build_render_task(fixture_path('invalid-partials'))
fixture = 'duplicate-keys.yml'
expected = "---\nkey1: foo\nkey1: bar\n"

assert_render_success(render.run(mock_output_stream, [fixture]))
stdout_assertion do |output|
assert_equal expected, output
end
end

private

def build_render_task(template_dir, bindings = {})
Expand Down

0 comments on commit 84d70eb

Please sign in to comment.