Navigation Menu

Skip to content

Commit

Permalink
[BGBUILD-233] fail fast when a bad path is provided as the BG_CONFIG_…
Browse files Browse the repository at this point in the history
…FILE env variable
  • Loading branch information
msavy committed Jun 14, 2011
1 parent e722bd0 commit a788c26
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions 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.
Expand Down
6 changes: 6 additions & 0 deletions lib/boxgrinder-core/models/config.rb
Expand Up @@ -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 })

Expand Down
8 changes: 7 additions & 1 deletion rubygem-boxgrinder-core.spec
Expand Up @@ -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+
Expand Down Expand Up @@ -76,6 +76,12 @@ popd
%{gemdir}/doc/%{gemname}-%{version}

%changelog

* Tue Jun 14 2011 Marc Savy <msavy@redhat.com - 0.3.3-1
- Upstream release: 0.3.3
- [BGBUILD-233] BoxGrinder Build fails to report a missing config file


* Tue May 10 2011 Marek Goldmann <mgoldman@redhat.com> - 0.3.2-1
- Upstream release: 0.3.2
- [BGBUILD-210] In Fedora 14 parameters are not being expanded, and cause early string truncation.
Expand Down
11 changes: 8 additions & 3 deletions spec/models/config-spec.rb
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit a788c26

Please sign in to comment.