-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a common module and fix up tests
- Loading branch information
Showing
11 changed files
with
190 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Krane | ||
module TemplateReporting | ||
def record_invalid_template(err:, filename:, content: nil) | ||
debug_msg = ColorizedString.new("Invalid template: #{filename}\n").red | ||
debug_msg += "> Error message:\n#{KubernetesDeploy::FormattedLogger.indent_four(err)}" | ||
if content | ||
debug_msg += if content =~ /kind:\s*Secret/ | ||
"\n> Template content: Suppressed because it may contain a Secret" | ||
else | ||
"\n> Template content:\n#{KubernetesDeploy::FormattedLogger.indent_four(content)}" | ||
end | ||
end | ||
logger.summary.add_paragraph(debug_msg) | ||
end | ||
|
||
def record_warnings(warning:, filename:) | ||
warn_msg = "Template warning: #{filename}\n" | ||
warn_msg += "> Warning message:\n#{KubernetesDeploy::FormattedLogger.indent_four(warning)}" | ||
logger.summary.add_paragraph(ColorizedString.new(warn_msg).yellow) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
require 'test_helper' | ||
require 'krane/cli/krane' | ||
require 'krane/global_deploy_task' | ||
|
||
class GlobalDeployTest < KubernetesDeploy::TestCase | ||
def test_global_deploy_with_default_options | ||
set_krane_global_deploy_expectations! | ||
krane_global_deploy! | ||
end | ||
|
||
def test_deploy_parses_global_timeout | ||
set_krane_global_deploy_expectations!(new_args: { max_watch_seconds: 10 }) | ||
krane_global_deploy!(flags: '--global-timeout 10s') | ||
set_krane_global_deploy_expectations!(new_args: { max_watch_seconds: 60**2 }) | ||
krane_global_deploy!(flags: '--global-timeout 1h') | ||
end | ||
|
||
def test_deploy_passes_verify_result | ||
set_krane_global_deploy_expectations!(run_args: { verify_result: true }) | ||
krane_global_deploy!(flags: '--verify-result true') | ||
set_krane_global_deploy_expectations!(run_args: { verify_result: false }) | ||
krane_global_deploy!(flags: '--verify-result false') | ||
end | ||
|
||
def test_deploy_passes_filename | ||
set_krane_global_deploy_expectations!(new_args: { template_paths: ['/my/file/path'] }) | ||
krane_global_deploy!(flags: '-f /my/file/path') | ||
set_krane_global_deploy_expectations!(new_args: { template_paths: ['/my/other/file/path'] }) | ||
krane_global_deploy!(flags: '--filenames /my/other/file/path') | ||
end | ||
|
||
def test_deploy_parses_selector | ||
selector = 'name:web' | ||
set_krane_global_deploy_expectations!(new_args: { selector: selector }) | ||
krane_global_deploy!(flags: "--selector #{selector}") | ||
end | ||
|
||
private | ||
|
||
def set_krane_global_deploy_expectations!(new_args: {}, run_args: {}) | ||
options = default_options(new_args, run_args) | ||
selector_args = options[:new_args][:selector] | ||
selector = mock('LabelSelector') | ||
KubernetesDeploy::LabelSelector.expects(:parse).with(selector_args).returns(selector) | ||
response = mock('GlobalDeployTask') | ||
response.expects(:run!).with(options[:run_args]).returns(true) | ||
Krane::GlobalDeployTask.expects(:new).with(options[:new_args].merge(selector: selector)).returns(response) | ||
end | ||
|
||
def krane_global_deploy!(flags: '') | ||
flags += ' -f /tmp' unless flags.include?('-f') | ||
flags += ' --selector name:web' unless flags.include?('--selector') | ||
krane = Krane::CLI::Krane.new( | ||
[task_config.context], | ||
flags.split | ||
) | ||
krane.invoke("global_deploy") | ||
end | ||
|
||
def default_options(new_args = {}, run_args = {}) | ||
{ | ||
new_args: { | ||
context: task_config.context, | ||
template_paths: ['/tmp'], | ||
max_watch_seconds: 300, | ||
selector: 'name:web', | ||
}.merge(new_args), | ||
run_args: { | ||
verify_result: true, | ||
prune: false, | ||
}.merge(run_args), | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.