Skip to content

Commit

Permalink
Make render take keyword arg
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Nov 17, 2019
1 parent 4e03055 commit c0e60e1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
13 changes: 13 additions & 0 deletions 1.0-Upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ Old name | New name | Comments
--- | --- | ---
max_watch_seconds | global_timeout | This is now a duration that can be expressed in a more user-friendly language (e.g. `30s` or `1h`)

Method signature changed from this:

```ruby
def run(stream)
```

... to this, to maintain the convention of using keyword arguments for all the public interfaces:

```ruby
def run(stream:)
```


#### `RunnerTask#run`

Old name | New name | Comments
Expand Down
4 changes: 2 additions & 2 deletions lib/krane/cli/render_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def self.from_options(options)
end

::Krane::OptionsHelper.with_processed_template_paths(filenames) do |paths|
runner = ::Krane::RenderTask.new(
renderer = ::Krane::RenderTask.new(
current_sha: options['current-sha'],
filenames: paths,
bindings: bindings_parser.parse,
)
runner.run!(STDOUT)
renderer.run!(stream: STDOUT)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/render_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(*args)
# @param stream [IO] Place to stream the output to
#
# @return [nil]
def run!(stream)
def run!(stream:)
@logger.reset
@logger.phase_heading("Initializing render task")

Expand Down
2 changes: 1 addition & 1 deletion test/exe/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_render_uses_current_sha
def install_krane_render_expectations(new_args = {})
options = default_options(new_args)
response = mock('RenderTask')
response.expects(:run!).with(STDOUT).returns(true)
response.expects(:run!).with(stream: STDOUT).returns(true)
Krane::RenderTask.expects(:new).with(options).returns(response)
end

Expand Down
28 changes: 14 additions & 14 deletions test/integration/render_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_render_task
File.join(fixture_path('hello-cloud'), 'configmap-data.yml')
)

assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))

stdout_assertion do |output|
assert_equal output, <<~RENDERED
Expand All @@ -36,7 +36,7 @@ def test_render_task_multiple_templates
File.join(fixture_path('hello-cloud'), 'configmap-data.yml'),
File.join(fixture_path('hello-cloud'), 'unmanaged-pod-1.yml.erb'),
])
assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))

stdout_assertion do |output|
expected = <<~RENDERED
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_render_task_with_partials_and_bindings
'supports_partials': 'yep'
)

assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
expected = <<~RENDERED
---
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_render_task_with_partials_and_bindings
def test_render_task_rendering_all_files
render = build_render_task(fixture_path('hello-cloud'))

assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_match(/name: bare-replica-set/, output)
assert_match(/name: hello-cloud-configmap-data/, output)
Expand All @@ -192,7 +192,7 @@ def test_render_task_multiple_templates_with_middle_failure
File.join(fixture_path('some-invalid'), 'yaml-error.yml'),
File.join(fixture_path('some-invalid'), 'stateful_set.yml'),
])
assert_render_failure(render.run(mock_output_stream))
assert_render_failure(render.run(stream: mock_output_stream))

stdout_assertion do |output|
assert_match(/name: hello-cloud-configmap-data/, output)
Expand All @@ -210,7 +210,7 @@ def test_render_invalid_binding
'a': 'binding-a',
'b': 'binding-b'
)
assert_render_failure(render.run(mock_output_stream))
assert_render_failure(render.run(stream: mock_output_stream))
assert_logs_match_all([
/Invalid template: .*deployment.yaml.erb/,
"> Error message:",
Expand All @@ -224,7 +224,7 @@ def test_render_runtime_error_when_rendering
render = build_render_task(
File.join(fixture_path('invalid'), 'raise_inside.yml.erb')
)
assert_render_failure(render.run(mock_output_stream))
assert_render_failure(render.run(stream: mock_output_stream))
assert_logs_match_all([
/Invalid template: .*raise_inside.yml.erb/,
"> Error message:",
Expand All @@ -237,7 +237,7 @@ def test_render_runtime_error_when_rendering
def test_render_empty_template_dir
tmp_dir = Dir.mktmpdir
render = build_render_task(tmp_dir)
assert_render_failure(render.run(mock_output_stream))
assert_render_failure(render.run(stream: mock_output_stream))
assert_logs_match_all([
"Template directory #{tmp_dir} does not contain any valid templates",
])
Expand All @@ -248,7 +248,7 @@ def test_render_invalid_yaml
File.join(fixture_path('invalid'), 'yaml-error.yml'),
data: "data"
)
assert_render_failure(render.run(mock_output_stream))
assert_render_failure(render.run(stream: mock_output_stream))
assert_logs_match_all([
/Invalid template: .*yaml-error.yml/,
"> Error message:",
Expand All @@ -261,7 +261,7 @@ def test_render_valid_fixtures
render = build_render_task(
File.join(fixture_path('hello-cloud'), basename)
)
assert_render_success render.run(mock_output_stream)
assert_render_success render.run(stream: mock_output_stream)
stdout_assertion do |output|
assert !output.empty?
end
Expand All @@ -275,7 +275,7 @@ def test_render_only_adds_initial_doc_separator_when_missing
])
expected = "---\n# The first doc has no yaml separator\nkey1: foo\n---\nkey2: bar\n"

assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal "#{expected}#{expected}", output
end
Expand All @@ -296,7 +296,7 @@ def test_render_only_adds_initial_doc_separator_when_missing
value: "data"
RENDERED

assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal expected, output
end
Expand All @@ -308,7 +308,7 @@ def test_render_preserves_duplicate_keys
)
expected = "---\nkey1: \"0\"\nkey1: \"1\"\nkey1: \"2\"\n"

assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal expected, output
end
Expand All @@ -318,7 +318,7 @@ def test_render_does_not_generate_extra_blank_documents_when_file_is_empty
render = build_render_task(
File.join(fixture_path('collection-with-erb'), 'effectively_empty.yml.erb')
)
assert_render_success(render.run(mock_output_stream))
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal "", output.strip
end
Expand Down

0 comments on commit c0e60e1

Please sign in to comment.