diff --git a/lib/kubernetes-deploy/options_helper.rb b/lib/kubernetes-deploy/options_helper.rb index 4b96fd922..5f30e4b57 100644 --- a/lib/kubernetes-deploy/options_helper.rb +++ b/lib/kubernetes-deploy/options_helper.rb @@ -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 diff --git a/lib/kubernetes-deploy/template_sets.rb b/lib/kubernetes-deploy/template_sets.rb index 1be4bfab4..453705273 100644 --- a/lib/kubernetes-deploy/template_sets.rb +++ b/lib/kubernetes-deploy/template_sets.rb @@ -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) diff --git a/test/unit/kubernetes-deploy/options_helper_test.rb b/test/unit/kubernetes-deploy/options_helper_test.rb index a067deddf..dbb8baf44 100644 --- a/test/unit/kubernetes-deploy/options_helper_test.rb +++ b/test/unit/kubernetes-deploy/options_helper_test.rb @@ -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