berkshelf-vagrant 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,13 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in berkshelf-vagrant.gemspec
4
3
  gemspec
5
4
 
6
5
  group :development do
7
6
  gem 'vagrant', github: "mitchellh/vagrant", tag: "v1.1.2"
8
- end
9
-
10
- group :test do
11
7
  gem 'coolline'
12
8
  gem 'guard', '>= 1.5.0'
13
9
  gem 'guard-rspec'
@@ -16,7 +12,6 @@ group :test do
16
12
  gem 'redcarpet'
17
13
  gem 'yard'
18
14
  gem 'fuubar'
19
- gem 'rspec'
20
15
 
21
16
  require 'rbconfig'
22
17
 
@@ -18,20 +18,24 @@ module Berkshelf
18
18
  # and copied to Vagrant's shelf
19
19
  attr_accessor :except
20
20
 
21
- def initialize
22
- super
21
+ # @return [String]
22
+ # the Chef node name (client name) to use to authenticate with the remote
23
+ # chef server to upload cookbooks when using the chef client provisioner
24
+ attr_accessor :node_name
23
25
 
24
- @berksfile_path = UNSET_VALUE
25
- @except = UNSET_VALUE
26
- @only = UNSET_VALUE
26
+ # @return [String]
27
+ # a filepath to a chef client key to use to authenticate with the remote
28
+ # chef server to upload cookbooks when using the chef client provisioner
29
+ attr_accessor :client_key
27
30
 
28
- finalize! # temporary workaround for configuration loading race condition
29
- end
31
+ def initialize
32
+ super
30
33
 
31
- def finalize!
32
- @berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME) if @berksfile_path == UNSET_VALUE
33
- @except = Array.new if @except == UNSET_VALUE
34
- @only = Array.new if @only == UNSET_VALUE
34
+ @berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
35
+ @except = Array.new
36
+ @only = Array.new
37
+ @node_name = Berkshelf::Config.instance.chef.node_name
38
+ @client_key = Berkshelf::Config.instance.chef.client_key
35
39
  end
36
40
 
37
41
  # @param [String] value
@@ -49,17 +53,25 @@ module Berkshelf
49
53
  def validate(machine)
50
54
  errors = Array.new
51
55
 
56
+ if machine.config.berkshelf.berksfile_path.nil?
57
+ errors << "berkshelf.berksfile_path cannot be nil."
58
+ end
59
+
60
+ unless File.exist?(machine.config.berkshelf.berksfile_path)
61
+ errors << "No Berskfile was found at #{machine.config.berkshelf.berksfile_path}."
62
+ end
63
+
52
64
  if !except.empty? && !only.empty?
53
- errors.add("A value for berkshelf.empty and berkshelf.only cannot both be defined.")
65
+ errors << "A value for berkshelf.empty and berkshelf.only cannot both be defined."
54
66
  end
55
67
 
56
68
  if chef_client?(machine.env)
57
- if Berkshelf::Config.instance.chef.node_name.nil?
58
- errors.add("A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration.")
69
+ if machine.config.berkshelf.node_name.nil?
70
+ errors << "A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
59
71
  end
60
72
 
61
- if Berkshelf::Config.instance.chef.client_key.nil?
62
- errors.add("A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration.")
73
+ if machine.config.berkshelf.client_key.nil?
74
+ errors << "A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
63
75
  end
64
76
  end
65
77
 
@@ -1,5 +1,5 @@
1
1
  module Berkshelf
2
2
  module Vagrant
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'bundler'
2
+ require 'bundler/setup'
3
3
  require 'spork'
4
4
 
5
5
  Spork.prefork do
@@ -9,23 +9,11 @@ Spork.prefork do
9
9
  require 'rspec'
10
10
 
11
11
  RSpec.configure do |config|
12
- config.mock_with :rspec
13
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
14
- config.filter_run focus: true
15
13
  config.run_all_when_everything_filtered = true
14
+ config.filter_run focus: true
16
15
 
17
- config.around(:each) do
18
- clean_tmp_path
19
- end
20
- end
21
-
22
- def clean_tmp_path
23
- FileUtils.rm_rf(tmp_path)
24
- FileUtils.mkdir_p(tmp_path)
25
- end
26
-
27
- def tmp_path
28
- File.join(APP_ROOT, 'spec', 'tmp')
16
+ config.order = 'random'
29
17
  end
30
18
  end
31
19
 
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Berkshelf::Vagrant::Config do
4
+ let(:unset_value) { described_class::UNSET_VALUE }
5
+
6
+ subject { described_class.new }
7
+
8
+ it "sets a path to a Berksfile in the current working directory for berksfile_path" do
9
+ subject.berksfile_path.should eql(File.join(Dir.pwd, "Berksfile"))
10
+ end
11
+
12
+ it "sets the value of only to an empty array" do
13
+ subject.only.should be_a(Array)
14
+ subject.only.should be_empty
15
+ end
16
+
17
+ it "sets the value of except to an empty array" do
18
+ subject.except.should be_a(Array)
19
+ subject.except.should be_empty
20
+ end
21
+
22
+ it "sets the value of node_name to the value in the Berkshelf::Config.instance" do
23
+ subject.node_name.should eql(Berkshelf::Config.instance.chef.node_name)
24
+ end
25
+
26
+ it "sets the value of client_key to the value in Berkshelf::Config.instance" do
27
+ subject.client_key.should eql(Berkshelf::Config.instance.chef.client_key)
28
+ end
29
+
30
+ describe "#validate" do
31
+ let(:env) { double('env') }
32
+ let(:config) { double('config', berkshelf: subject) }
33
+ let(:machine) { double('machine', config: config, env: env) }
34
+
35
+ before(:each) do
36
+ subject.finalize!
37
+ subject.should_receive(:chef_client?).with(env).and_return(true)
38
+ end
39
+
40
+ let(:result) { subject.validate(machine) }
41
+
42
+ it "returns a Hash with a 'berkshelf configuration' key" do
43
+ result.should be_a(Hash)
44
+ result.should have_key("berkshelf configuration")
45
+ end
46
+
47
+ context "when all validations pass" do
48
+ before(:each) do
49
+ File.should_receive(:exist?).with(subject.berksfile_path).and_return(true)
50
+ end
51
+
52
+ it "contains an empty Array for the 'berkshelf configuration' key" do
53
+ result["berkshelf configuration"].should be_a(Array)
54
+ result["berkshelf configuration"].should be_empty
55
+ end
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-20 00:00:00.000000000 Z
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: berkshelf
@@ -216,6 +216,7 @@ files:
216
216
  - lib/berkshelf/vagrant/plugin.rb
217
217
  - lib/berkshelf/vagrant/version.rb
218
218
  - spec/spec_helper.rb
219
+ - spec/unit/berkshelf/vagrant/config_spec.rb
219
220
  - spec/unit/berkshelf/vagrant/errors_spec.rb
220
221
  - spec/unit/berkshelf/vagrant_spec.rb
221
222
  homepage: http://berkshelf.com
@@ -239,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
240
  version: '0'
240
241
  segments:
241
242
  - 0
242
- hash: -2373621278737506155
243
+ hash: -3541994389694666662
243
244
  requirements: []
244
245
  rubyforge_project:
245
246
  rubygems_version: 1.8.24
@@ -248,6 +249,7 @@ specification_version: 3
248
249
  summary: A Vagrant plugin to add Berkshelf integration to the Chef provisioners
249
250
  test_files:
250
251
  - spec/spec_helper.rb
252
+ - spec/unit/berkshelf/vagrant/config_spec.rb
251
253
  - spec/unit/berkshelf/vagrant/errors_spec.rb
252
254
  - spec/unit/berkshelf/vagrant_spec.rb
253
255
  has_rdoc: