Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not add doc separator when render result is blank #467

Merged
merged 2 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## next

*Bug fixes*
- Fixes a bug introduced in 0.26.2 where kubernetes-render started adding YAML headers to empty render results

## 0.26.2

*Enhancements*
Expand Down
2 changes: 1 addition & 1 deletion lib/kubernetes-deploy/render_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def render_filename(filename, stream)
rendered_content = @renderer.render_template(filename, file_content)
implicit = true
YAML.parse_stream(rendered_content, "<rendered> #{filename}") { |d| implicit = d.implicit }
stream.puts "---\n" if implicit
stream.puts "---\n" if implicit && rendered_content.present?
KnVerey marked this conversation as resolved.
Show resolved Hide resolved
stream.puts rendered_content
@logger.info("Rendered #{File.basename(filename)}")
rescue Psych::SyntaxError => exception
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/collection-with-erb/effectively_empty.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%- if false -%>
---
apiVersion: v1
kind: ConfigMap
metadata:
name: never-created
data:
will_never: exist
<%- end -%>
8 changes: 8 additions & 0 deletions test/integration/render_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ def test_render_preserves_duplicate_keys
end
end

def test_render_does_not_generate_extra_blank_documents_when_file_is_empty
renderer = build_render_task(fixture_path('collection-with-erb'))
assert_render_success(renderer.run(mock_output_stream, ['effectively_empty.yml.erb']))
stdout_assertion do |output|
assert_equal "", output.strip
end
end

private

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