From a788c26b35f9cf67310a2a501a04204d65111fd2 Mon Sep 17 00:00:00 2001 From: Marc Savy Date: Tue, 14 Jun 2011 04:46:48 +0100 Subject: [PATCH] [BGBUILD-233] fail fast when a bad path is provided as the BG_CONFIG_FILE env variable --- CHANGELOG | 4 ++++ lib/boxgrinder-core/models/config.rb | 6 ++++++ rubygem-boxgrinder-core.spec | 8 +++++++- spec/models/config-spec.rb | 11 ++++++++--- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a58705a..55a8291 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v0.3.3 + +* [BGBUILD-233] BoxGrinder Build fails to report a missing config file + v0.3.2 * [BGBUILD-210] In Fedora 14 parameters are not being expanded, and cause early string truncation. diff --git a/lib/boxgrinder-core/models/config.rb b/lib/boxgrinder-core/models/config.rb index 62c1a89..b863e48 100644 --- a/lib/boxgrinder-core/models/config.rb +++ b/lib/boxgrinder-core/models/config.rb @@ -45,6 +45,12 @@ def initialize(values = {}) :additional_plugins => [] ) + if ENV['BG_CONFIG_FILE'] + unless ENV['BG_CONFIG_FILE'].strip.empty? + raise(Errno::ENOENT, ENV['BG_CONFIG_FILE']) unless File.exists? ENV['BG_CONFIG_FILE'] + end + end + deep_merge(self, YAML.load_file(self.file)) if File.exists?(self.file) merge!(values.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }) diff --git a/rubygem-boxgrinder-core.spec b/rubygem-boxgrinder-core.spec index 2ad38ad..e70a22e 100644 --- a/rubygem-boxgrinder-core.spec +++ b/rubygem-boxgrinder-core.spec @@ -5,7 +5,7 @@ Summary: Core library for BoxGrinder Name: rubygem-%{gemname} -Version: 0.3.2 +Version: 0.3.3 Release: 1%{?dist} Group: Development/Languages License: LGPLv3+ @@ -76,6 +76,12 @@ popd %{gemdir}/doc/%{gemname}-%{version} %changelog + +* Tue Jun 14 2011 Marc Savy - 0.3.2-1 - Upstream release: 0.3.2 - [BGBUILD-210] In Fedora 14 parameters are not being expanded, and cause early string truncation. diff --git a/spec/models/config-spec.rb b/spec/models/config-spec.rb index c54d5db..3bfce72 100644 --- a/spec/models/config-spec.rb +++ b/spec/models/config-spec.rb @@ -21,8 +21,8 @@ module BoxGrinder describe Config do - it "should not load options from file if it doesn't exists" do - ENV['BG_CONFIG_FILE'] = "doesntexists" + it "should not load options from file if it doesn't exist" do + ENV['BG_CONFIG_FILE'] = "" config = Config.new config.force.should == false @@ -46,8 +46,13 @@ module BoxGrinder config.dir.root.should == 'root/dir' end + it "should raise a file not found error if BG_CONFIG_FILE is set, but the path is invalid" do + ENV['BG_CONFIG_FILE'] = "leo/tol/stoy" + lambda { Config.new }.should raise_error(Errno::ENOENT) + end + it "should merge platform" do - ENV['BG_CONFIG_FILE'] = "doesntexists" + ENV['BG_CONFIG_FILE'] = " " config = Config.new.merge(:platform => :ec2)