Skip to content

Commit

Permalink
if default_template_dir does not exist, we erroneously treat the trai…
Browse files Browse the repository at this point in the history
…ling name as a file, not a dir. Need to fail fast on OptionsHelper instead
  • Loading branch information
timothysmith0609 committed Sep 3, 2019
1 parent 96ad5f0 commit ec40d8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/kubernetes-deploy/options_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def default_template_dir

unless template_dir
raise OptionsError, "Template directory is unknown. " \
"Either specify --template-dir argument or set $ENVIRONMENT to use config/deploy/$ENVIRONMENT " \
"as a default path."
"Either specify --template-dir argument or set $ENVIRONMENT to use config/deploy/$ENVIRONMENT " \
"as a default path."
end
unless Dir.exist?(template_dir)
raise OptionsError, "Template directory #{template_dir} does not exist."
end

template_dir
Expand Down
1 change: 1 addition & 0 deletions lib/kubernetes-deploy/template_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def validate
end
return errors << "Template directory #{@template_dir} does not contain any valid templates"
end

@files.each do |filename|
filename = File.join(@template_dir, filename)
if !File.exist?(filename)
Expand Down
10 changes: 7 additions & 3 deletions test/unit/kubernetes-deploy/options_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ def test_with_template_dir

def test_template_dir_with_default_env_var
with_env("ENVIRONMENT", "test") do
KubernetesDeploy::OptionsHelper.with_processed_template_paths([]) do |template_paths|
assert_equal(template_paths, [File.join("config", "deploy", "test")])
assert_raises_message(KubernetesDeploy::OptionsHelper::OptionsError,
"Template directory config/deploy/test does not exist") do
KubernetesDeploy::OptionsHelper.with_processed_template_paths([])
end
end
end

def test_missing_template_dir_raises
with_env("ENVIRONMENT", nil) do
assert_raises(KubernetesDeploy::OptionsHelper::OptionsError) do
assert_raises_message(KubernetesDeploy::OptionsHelper::OptionsError,
"Template directory is unknown. " \
"Either specify --template-dir argument or set $ENVIRONMENT to use config/deploy/$ENVIRONMENT " \
"as a default path.") do
KubernetesDeploy::OptionsHelper.with_processed_template_paths([]) do
end
end
Expand Down

0 comments on commit ec40d8d

Please sign in to comment.