vagrant-r10k 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11ae37b7c28f43dcdd732d3b5515e4f2c0eadcc1
4
- data.tar.gz: a7d31bd3f78eea85d5e1e0098471d26f6c08a477
3
+ metadata.gz: a4666dcc1faa126330ef66752ae6271931d6d856
4
+ data.tar.gz: 335eee055654f32f1ac8605dc5368ca1ec6857dd
5
5
  SHA512:
6
- metadata.gz: 336d24166bda7d40cd6a8c3a6ffecc8e6247aae15892fadb9ce8b887e8b36ec3b271f6ad1bf417d93c53f7738ae3054bf57c60eea49883541e4dea818e5d8a1c
7
- data.tar.gz: 7a11489ace64e0edb07410b28740e4df80f6c952fb94243a59fe673024db027418b3e5b37b8be44484b6a92df8db3e3786075f77249a9d3e95163851d576aa12
6
+ metadata.gz: 4e378b000c0d0772d99c1bd5a34b415f0c821a1249cc1893846702d84aa10cd606fb596ab54ad1fdb04e7f03d6426d5ddc9622bec119e4c2573fadebe9c9b740
7
+ data.tar.gz: e66844a6f7c8e937c3bd6b92a465b34b14a1eac75033fb2f6c10888faa2535ccd9bf31d0db9a1dc85b59f18660f4b3bf4af90f8b19baf8316cd9de4f85868ed5
data/.gitignore CHANGED
@@ -23,3 +23,4 @@ mkmf.log
23
23
  vendor
24
24
  Vagrantfile
25
25
  .vagrant
26
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ language: ruby
3
+ before_install:
4
+ - gem install bundler --version $BUNDLER_VERSION
5
+ install: bundle _${BUNDLER_VERSION}_ install
6
+ script: bundle _${BUNDLER_VERSION}_ exec rspec --color --format documentation
7
+ notifications:
8
+ email: true
9
+ rvm:
10
+ - 2.0.0
11
+ env:
12
+ global:
13
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
14
+ matrix:
15
+ - VAGRANT_VERSION=1.6.5 BUNDLER_VERSION=1.6.9
16
+ - VAGRANT_VERSION=1.7.0 BUNDLER_VERSION=1.7.9
17
+ - BUNDLER_VERSION=1.7.9
data/CHANGES.md ADDED
@@ -0,0 +1,21 @@
1
+ # vagrant-r10k changelog
2
+
3
+ ## 0.2.0 2015-01-10 Jason Antman <jason@jasonantman.com>
4
+
5
+ * Add unit tests for modulegetter and config.
6
+ * Readme updates.
7
+ * Add changelog.
8
+ * Fix bug in newer Vagrant where provider does not have .name ([issue #3](https://github.com/jantman/vagrant-r10k/issues/3))
9
+ * Update README.md
10
+
11
+ ## 0.1.1 2014-08-07 Jason Antman <jason@jasonantman.com>
12
+
13
+ * Add support for optional config of r10k module_path and check if it is defined ([Oliver Bertuch](https://github.com/poikilotherm)).
14
+ * Add documentation
15
+ * Add default Rake task to list available tasks
16
+ * Add development docs and `.ruby_version`.
17
+ * Update contributing docs and contributors list.
18
+
19
+ ## 0.1.0 2014-07-01 Jason Antman <jason@jasonantman.com>
20
+
21
+ * Initial Release
data/Gemfile CHANGED
@@ -1,9 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
4
+ if ENV.has_key?('VAGRANT_VERSION')
5
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", tag: "v#{ENV['VAGRANT_VERSION']}"
6
+ else
7
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", branch: 'master'
8
+ end
9
+ # Pinned on 12/10/2014. Compatible with Vagrant 1.5.x, 1.6.x and 1.7.x.
10
+ gem 'vagrant-spec', :github => 'mitchellh/vagrant-spec', :ref => '1df5a3a'
11
+ gem 'simplecov', :require => false
12
+ gem 'codecov', :require => false
5
13
  end
6
14
 
7
15
  group :plugins do
8
- gem "vagrant-r10k", path: "."
16
+ gemspec
9
17
  end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Vagrant::R10k
2
2
 
3
+ [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active)
4
+
3
5
  vagrant-r10k is a [Vagrant](http://www.vagrantup.com/) 1.2+ middleware plugin to allow you to have just a Puppetfile and
4
6
  manifests in your vagrant project, and pull in the required modules via [r10k](https://github.com/adrienthebo/r10k). This
5
7
  plugin only works with the 'puppet' provisioner, not a puppet server. It expects you to have a Puppetfile in the same repository
@@ -97,10 +99,9 @@ The configuration for r10k and puppet would look like:
97
99
  1. Fork it ( https://github.com/jantman/vagrant-r10k/fork )
98
100
  2. Create your feature branch (`git checkout -b my-new-feature`)
99
101
  3. Commit your changes (`git commit -am 'Add some feature'`)
100
- 4. Increment the version number in `lib/vagrant-r10k/version.rb`
101
- 5. Add yourself to the "Contributors" list below.
102
- 6. Push to the branch (`git push origin my-new-feature`)
103
- 7. Create a new Pull Request
102
+ 4. Add yourself to the "Contributors" list below.
103
+ 5. Push to the branch (`git push origin my-new-feature`)
104
+ 6. Create a new Pull Request
104
105
 
105
106
  ### Contributors
106
107
 
@@ -127,10 +128,19 @@ to the above command).
127
128
 
128
129
  Exporting ``VAGRANT_LOG=debug`` will also turn on debug-level logging for r10k.
129
130
 
131
+ ## Releasing
132
+
133
+ 1. Ensure all tests are passing, coverage is acceptable, etc.
134
+ 2. Increment the version number in ``lib/vagrant-r10k/version.rb``
135
+ 3. Update CHANGES.md
136
+ 4. Push those changes to origin.
137
+ 5. ``bundle exec rake build``
138
+ 6. ``bundle exec rake release``
139
+
130
140
  ## Acknowlegements
131
141
 
132
142
  Thanks to the following people:
133
143
 
134
- * [@adrienthebo](https://github.com/adrienthebo) for [r10k](https://github.com/adrienthebo/r10k)
144
+ * [@adrienthebo](https://github.com/adrienthebo) for [r10k](https://github.com/adrienthebo/r10k) and for [vagrant-pe_build](https://github.com/adrienthebo/vagrant-pe_build) as a wonderful example of unit testing Vagrant plugins.
135
145
  * [@garethr](https://github.com/garethr) for [librarian-puppet-vagrant](https://github.com/garethr/librarian-puppet-vagrant) which inspired this plugin
136
146
  * [Alex Kahn](http://akahn.net/) of Paperless Post for his [How to Write a Vagrant Middleware](http://akahn.net/2014/05/05/vagrant-middleware.html) blog post, documenting the new middleware API
data/Rakefile CHANGED
@@ -5,6 +5,12 @@ Bundler::GemHelper.install_tasks
5
5
 
6
6
  task :default => [:help]
7
7
 
8
+ begin
9
+ require 'rspec/core/rake_task'
10
+ RSpec::Core::RakeTask.new(:spec)
11
+ rescue LoadError
12
+ end
13
+
8
14
  desc "Display the list of available rake tasks"
9
15
  task :help do
10
16
  system("rake -T")
@@ -60,27 +60,30 @@ module VagrantPlugins
60
60
  manifest_file = nil
61
61
  manifests_path = nil
62
62
  @env[:machine].config.vm.provisioners.each do |prov|
63
- if prov.name == :puppet
64
- # if module_path has been set before, check if it fits to one defined in the provisioner config
65
- if module_path != nil
66
- if prov.config.module_path.is_a?(Array) and ! prov.config.module_path.include?(module_path)
67
- @env[:ui].detail "vagrant-r10k: module_path \"#{module_path}\" is not within the ones defined in puppet provisioner; not running"
68
- @app.call(env)
69
- return
70
- elsif ! prov.config.module_path.is_a?(Array) and prov.config.module_path != module_path
71
- @env[:ui].detail "vagrant-r10k: module_path \"#{module_path}\" is not the same as in puppet provisioner; not running"
72
- @app.call(env)
73
- return
74
- end
75
- # no modulepath explict set in config, build one from the provisioner config
76
- else
77
- module_path = prov.config.module_path.is_a?(Array) ? prov.config.module_path[0] : prov.config.module_path
78
- @env[:ui].info "vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"#{module_path}\". (if module_path is an array, first element is used)"
63
+ if prov.respond_to?(:type)
64
+ next if prov.type != :puppet
65
+ else
66
+ next if prov.name != :puppet
67
+ end
68
+ # if module_path has been set before, check if it fits to one defined in the provisioner config
69
+ if module_path != nil
70
+ if prov.config.module_path.is_a?(Array) and ! prov.config.module_path.include?(module_path)
71
+ @env[:ui].detail "vagrant-r10k: module_path \"#{module_path}\" is not within the ones defined in puppet provisioner; not running"
72
+ @app.call(env)
73
+ return
74
+ elsif ! prov.config.module_path.is_a?(Array) and prov.config.module_path != module_path
75
+ @env[:ui].detail "vagrant-r10k: module_path \"#{module_path}\" is not the same as in puppet provisioner; not running"
76
+ @app.call(env)
77
+ return
79
78
  end
80
-
81
- manifest_file = File.join(env_dir, prov.config.manifest_file)
82
- manifests_path = File.join(env_dir, prov.config.manifests_path[1])
79
+ # no modulepath explict set in config, build one from the provisioner config
80
+ else
81
+ module_path = prov.config.module_path.is_a?(Array) ? prov.config.module_path[0] : prov.config.module_path
82
+ @env[:ui].info "vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"#{module_path}\". (if module_path is an array, first element is used)"
83
83
  end
84
+
85
+ manifest_file = File.join(env_dir, prov.config.manifest_file)
86
+ manifests_path = File.join(env_dir, prov.config.manifests_path[1])
84
87
  end
85
88
 
86
89
  # now join the module_path with the env_dir to have an absolute path
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module R10k
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ # Disable Vagrant autoloading so that other plugins defined in the Gemfile for
4
+ # Acceptance tests are not loaded.
5
+ ENV['VAGRANT_NO_PLUGINS'] = '1'
6
+
7
+ require 'vagrant-spec/unit'
8
+
9
+ require 'simplecov'
10
+ SimpleCov.start do
11
+ add_filter "/vendor/"
12
+ if ENV['CI']=='true'
13
+ require 'codecov'
14
+ formatter = SimpleCov::Formatter::Codecov
15
+ end
16
+ end
17
+
18
+ require 'vagrant-r10k'
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vagrant-r10k/config'
4
+
5
+ describe VagrantPlugins::R10k::Config do
6
+ include_context 'vagrant-unit'
7
+ let(:test_env) do
8
+ test_env = isolated_environment
9
+ test_env.vagrantfile <<-EOF
10
+ Vagrant.configure('2') do |config|
11
+ config.vm.define :test
12
+ end
13
+ EOF
14
+ test_env
15
+ end
16
+ let(:env) { test_env.create_vagrant_env }
17
+ let(:machine) { env.machine(:test, :dummy) }
18
+
19
+ context 'when validated' do
20
+ before(:each) { subject.finalize! }
21
+ describe 'with puppet_dir and puppetfile_path unset' do
22
+ it 'passes validation' do
23
+ errors = subject.validate(machine)
24
+ errors.should eq({})
25
+ end
26
+ end
27
+
28
+ describe 'with puppet_dir unset' do
29
+ it 'fails validation' do
30
+ subject.puppetfile_path = '/foo/bar'
31
+ errors = subject.validate(machine)
32
+ errors.should eq({"vagrant-r10k"=>["config.r10k.puppet_dir must be set"]})
33
+ end
34
+ end
35
+
36
+ describe 'when puppet_dir does not exist' do
37
+ it 'fails validation' do
38
+ puppetfile = '/foo/bar'
39
+ puppet_dir = '/baz/blam'
40
+ puppetfile_path = File.join(env.root_path, puppetfile)
41
+ puppet_dir_path = File.join(env.root_path, puppet_dir)
42
+
43
+ subject.puppetfile_path = puppetfile
44
+ subject.puppet_dir = puppet_dir
45
+
46
+ # stub only for the checks we care about
47
+ File.stub(:file?).and_call_original
48
+ File.stub(:file?).with(puppetfile_path).and_return(true)
49
+ File.stub(:directory?).and_call_original
50
+ File.stub(:directory?).with(puppet_dir_path).and_return(false)
51
+ errors = subject.validate(machine)
52
+ errors.should eq({"vagrant-r10k"=>["puppet_dir directory '#{puppet_dir_path}' does not exist"]})
53
+ end
54
+ end
55
+
56
+ describe 'with puppetfile_path unset' do
57
+ it 'fails validation' do
58
+ puppet_dir = '/baz/blam'
59
+ puppet_dir_path = File.join(env.root_path, puppet_dir)
60
+
61
+ subject.puppet_dir = puppet_dir
62
+
63
+ # stub File.directory? only for /baz/blam
64
+ File.stub(:directory?).and_call_original
65
+ File.stub(:directory?).with(puppet_dir_path).and_return(true)
66
+ errors = subject.validate(machine)
67
+ errors.should eq({"vagrant-r10k"=>["config.r10k.puppetfile_path must be set"]})
68
+ end
69
+ end
70
+
71
+ describe 'when puppetfile_path does not exist' do
72
+ it 'fails validation' do
73
+ puppetfile = '/foo/bar'
74
+ puppet_dir = '/baz/blam'
75
+ puppetfile_path = File.join(env.root_path, puppetfile)
76
+ puppet_dir_path = File.join(env.root_path, puppet_dir)
77
+
78
+ subject.puppetfile_path = puppetfile
79
+ subject.puppet_dir = puppet_dir
80
+
81
+ # stub only for the checks we care about
82
+ File.stub(:file?).and_call_original
83
+ File.stub(:file?).with(puppetfile_path).and_return(false)
84
+ File.stub(:directory?).and_call_original
85
+ File.stub(:directory?).with(puppet_dir_path).and_return(true)
86
+ errors = subject.validate(machine)
87
+ errors.should eq({"vagrant-r10k"=>["puppetfile '#{puppetfile_path}' does not exist"]})
88
+ end
89
+ end
90
+
91
+ describe 'if module_path specified but does not exist' do
92
+ it 'fails validation' do
93
+ puppetfile = '/foo/bar'
94
+ puppet_dir = '/baz/blam'
95
+ module_path = '/blarg/modules'
96
+ puppetfile_path = File.join(env.root_path, puppetfile)
97
+ puppet_dir_path = File.join(env.root_path, puppet_dir)
98
+ module_path_path = File.join(env.root_path, module_path)
99
+
100
+ subject.puppetfile_path = puppetfile
101
+ subject.puppet_dir = puppet_dir
102
+ subject.module_path = module_path
103
+
104
+ # stub only for the checks we care about
105
+ File.stub(:file?).and_call_original
106
+ File.stub(:file?).with(puppetfile_path).and_return(true)
107
+ File.stub(:directory?).and_call_original
108
+ File.stub(:directory?).with(puppet_dir_path).and_return(true)
109
+ File.stub(:directory?).with(module_path_path).and_return(false)
110
+ errors = subject.validate(machine)
111
+ errors.should eq({"vagrant-r10k"=>["module_path directory '#{module_path_path}' does not exist"]})
112
+ end
113
+ end
114
+
115
+ describe 'if module_path specified and exists' do
116
+ it 'passes validation' do
117
+ puppetfile = '/foo/bar'
118
+ puppet_dir = '/baz/blam'
119
+ module_path = '/blarg/modules'
120
+ puppetfile_path = File.join(env.root_path, puppetfile)
121
+ puppet_dir_path = File.join(env.root_path, puppet_dir)
122
+ module_path_path = File.join(env.root_path, module_path)
123
+
124
+ subject.puppetfile_path = puppetfile
125
+ subject.puppet_dir = puppet_dir
126
+ subject.module_path = module_path
127
+
128
+ # stub only for the checks we care about
129
+ File.stub(:file?).and_call_original
130
+ File.stub(:file?).with(puppetfile_path).and_return(true)
131
+ File.stub(:directory?).and_call_original
132
+ File.stub(:directory?).with(puppet_dir_path).and_return(true)
133
+ File.stub(:directory?).with(module_path_path).and_return(true)
134
+ errors = subject.validate(machine)
135
+ errors.should eq({"vagrant-r10k"=>[]})
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,369 @@
1
+ require 'spec_helper'
2
+ require_relative 'sharedcontext'
3
+ require_relative 'shared_expectations'
4
+
5
+ require 'r10k/puppetfile'
6
+ require 'r10k/task_runner'
7
+ require 'r10k/task/puppetfile'
8
+ require 'vagrant-r10k/modulegetter'
9
+
10
+ include SharedExpectations
11
+
12
+ describe Log4r::Logger do
13
+ subject { described_class.new('testlogger') }
14
+ describe '#debug1' do
15
+ it 'should pass through to debug' do
16
+ expect(subject).to receive(:debug).with('a message').once
17
+ subject.debug1('a message')
18
+ end
19
+ end
20
+ describe '#debug2' do
21
+ it 'should pass through to debug' do
22
+ expect(subject).to receive(:debug).with('different message').once
23
+ subject.debug2('different message')
24
+ end
25
+ end
26
+ end
27
+
28
+ describe R10K::TaskRunner do
29
+ subject { described_class.new({}) }
30
+ describe '#get_errors' do
31
+ it 'returns @errors' do
32
+ subject.instance_variable_set(:@errors, ['foo'])
33
+ expect(subject).to receive(:get_errors).once.and_call_original
34
+ foo = subject.get_errors
35
+ expect(foo).to eq(['foo'])
36
+ end
37
+ end
38
+ end
39
+
40
+ describe VagrantPlugins::R10k::Modulegetter do
41
+ subject { described_class.new(app, env) }
42
+
43
+ describe '#call' do
44
+ describe 'puppet_dir unset' do
45
+ include_context 'unit' do
46
+ let(:vagrantfile) { <<-EOF
47
+ Vagrant.configure('2') do |config|
48
+ config.vm.define :test
49
+ # r10k plugin to deploy puppet modules
50
+ # config.r10k.puppet_dir = 'puppet'
51
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
52
+
53
+ # Provision the machine with the appliction
54
+ config.vm.provision "puppet" do |puppet|
55
+ puppet.manifests_path = "puppet/manifests"
56
+ puppet.manifest_file = "default.pp"
57
+ puppet.module_path = "puppet/modules"
58
+ end
59
+ end
60
+ EOF
61
+ }
62
+ end
63
+ it 'should raise an error' do
64
+ expect(ui).to receive(:detail).with("vagrant-r10k: puppet_dir and/or puppetfile_path not set in config; not running").once
65
+ File.stub(:join).and_call_original
66
+ File.stub(:join).with('/rootpath', 'puppet/Puppetfile').and_return('foobarbaz')
67
+ expect(File).to receive(:join).with('/rootpath', 'puppet/Puppetfile').exactly(0).times
68
+ expect_did_not_run(ui, app, env)
69
+
70
+ retval = subject.call(env)
71
+ expect(retval).to be_nil
72
+ end
73
+ end
74
+ describe 'puppetfile_path unset' do
75
+ include_context 'unit' do
76
+ let(:vagrantfile) { <<-EOF
77
+ Vagrant.configure('2') do |config|
78
+ config.vm.define :test
79
+ # r10k plugin to deploy puppet modules
80
+ config.r10k.puppet_dir = 'puppet'
81
+ # config.r10k.puppetfile_path = 'puppet/Puppetfile'
82
+
83
+ # Provision the machine with the appliction
84
+ config.vm.provision "puppet" do |puppet|
85
+ puppet.manifests_path = "puppet/manifests"
86
+ puppet.manifest_file = "default.pp"
87
+ puppet.module_path = "puppet/modules"
88
+ end
89
+ end
90
+ EOF
91
+ }
92
+ end
93
+ it 'should raise an error' do
94
+ expect(ui).to receive(:detail).with("vagrant-r10k: puppet_dir and/or puppetfile_path not set in config; not running").once
95
+ File.stub(:join).and_call_original
96
+ File.stub(:join).with('/rootpath', 'puppet/Puppetfile').and_return('foobarbaz')
97
+ expect(File).to receive(:join).with('/rootpath', 'puppet/Puppetfile').exactly(0).times
98
+ expect_did_not_run(ui, app, env)
99
+
100
+ retval = subject.call(env)
101
+ expect(retval).to be_nil
102
+ end
103
+ end
104
+ describe 'r10k module_path set differently from puppet' do
105
+ include_context 'unit' do
106
+ let(:vagrantfile) { <<-EOF
107
+ Vagrant.configure('2') do |config|
108
+ config.vm.define :test
109
+ # r10k plugin to deploy puppet modules
110
+ config.r10k.puppet_dir = 'puppet'
111
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
112
+ config.r10k.module_path = "mymodulepath/foo"
113
+
114
+ # Provision the machine with the appliction
115
+ config.vm.provision "puppet" do |puppet|
116
+ puppet.manifests_path = "puppet/manifests"
117
+ puppet.manifest_file = "default.pp"
118
+ puppet.module_path = "puppet/modules"
119
+ end
120
+ end
121
+ EOF
122
+ }
123
+ end
124
+ it 'should raise an error' do
125
+ expect(ui).to receive(:detail).with("vagrant-r10k: module_path \"mymodulepath/foo\" is not the same as in puppet provisioner; not running").once
126
+ File.stub(:file?).with('/rootpath/puppet/Puppetfile').and_return(true)
127
+ expect(File).to receive(:join).with('/rootpath', 'default.pp').exactly(0).times
128
+ expect_did_not_run(ui, app, env)
129
+
130
+ retval = subject.call(env)
131
+ expect(retval).to be_nil
132
+ end
133
+ end
134
+ describe 'r10k module_path set differently from puppet array' do
135
+ include_context 'unit' do
136
+ let(:vagrantfile) { <<-EOF
137
+ Vagrant.configure('2') do |config|
138
+ config.vm.define :test
139
+ # r10k plugin to deploy puppet modules
140
+ config.r10k.puppet_dir = 'puppet'
141
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
142
+ config.r10k.module_path = "mymodulepath/foo"
143
+
144
+ # Provision the machine with the appliction
145
+ config.vm.provision "puppet" do |puppet|
146
+ puppet.manifests_path = "puppet/manifests"
147
+ puppet.manifest_file = "default.pp"
148
+ puppet.module_path = ["puppet/modules", "foo/modules"]
149
+ end
150
+ end
151
+ EOF
152
+ }
153
+ end
154
+ it 'should raise an error' do
155
+ expect(ui).to receive(:detail).with("vagrant-r10k: module_path \"mymodulepath/foo\" is not within the ones defined in puppet provisioner; not running").once
156
+ File.stub(:file?).with('/rootpath/puppet/Puppetfile').and_return(true)
157
+ expect(File).to receive(:join).with('/rootpath', 'default.pp').exactly(0).times
158
+ expect_did_not_run(ui, app, env)
159
+
160
+ retval = subject.call(env)
161
+ expect(retval).to be_nil
162
+ end
163
+ end
164
+ describe 'r10k module_path not set' do
165
+ include_context 'unit' do
166
+ let(:vagrantfile) { <<-EOF
167
+ Vagrant.configure('2') do |config|
168
+ config.vm.define :test
169
+ # r10k plugin to deploy puppet modules
170
+ config.r10k.puppet_dir = 'puppet'
171
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
172
+
173
+ # Provision the machine with the appliction
174
+ config.vm.provision "puppet" do |puppet|
175
+ puppet.manifests_path = "puppet/manifests"
176
+ puppet.manifest_file = "default.pp"
177
+ puppet.module_path = "puppet/modules"
178
+ end
179
+ end
180
+ EOF
181
+ }
182
+ end
183
+ it 'should use the module_path from provisioner' do
184
+ expect_ran_successfully({:ui => ui,
185
+ :subject => subject,
186
+ :module_path => 'puppet/modules',
187
+ :puppetfile_path => 'puppet/Puppetfile',
188
+ :rootpath => '/rootpath',
189
+ :puppet_dir => 'puppet',
190
+ })
191
+ retval = subject.call(env)
192
+ expect(retval).to be_nil
193
+ end
194
+ end
195
+ describe 'vagrant normal logging' do
196
+ include_context 'unit' do
197
+ let(:vagrantfile) { <<-EOF
198
+ Vagrant.configure('2') do |config|
199
+ config.vm.define :test
200
+ # r10k plugin to deploy puppet modules
201
+ config.r10k.puppet_dir = 'puppet'
202
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
203
+
204
+ # Provision the machine with the appliction
205
+ config.vm.provision "puppet" do |puppet|
206
+ puppet.manifests_path = "puppet/manifests"
207
+ puppet.manifest_file = "default.pp"
208
+ puppet.module_path = "puppet/modules"
209
+ end
210
+ end
211
+ EOF
212
+ }
213
+ end
214
+ it 'should set r10k normal logging' do
215
+ expect_ran_successfully({:ui => ui,
216
+ :subject => subject,
217
+ :module_path => 'puppet/modules',
218
+ :puppetfile_path => 'puppet/Puppetfile',
219
+ :rootpath => '/rootpath',
220
+ :puppet_dir => 'puppet',
221
+ })
222
+ retval = subject.call(env)
223
+ expect(R10K::Logging.level).to eq(3)
224
+ expect(retval).to be_nil
225
+ end
226
+ end
227
+ describe 'vagrant debug logging' do
228
+ include_context 'unit' do
229
+ let(:vagrantfile) { <<-EOF
230
+ Vagrant.configure('2') do |config|
231
+ config.vm.define :test
232
+ # r10k plugin to deploy puppet modules
233
+ config.r10k.puppet_dir = 'puppet'
234
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
235
+
236
+ # Provision the machine with the appliction
237
+ config.vm.provision "puppet" do |puppet|
238
+ puppet.manifests_path = "puppet/manifests"
239
+ puppet.manifest_file = "default.pp"
240
+ puppet.module_path = "puppet/modules"
241
+ end
242
+ end
243
+ EOF
244
+ }
245
+ end
246
+ it 'should set r10k debug logging' do
247
+ expect_ran_successfully({:ui => ui,
248
+ :subject => subject,
249
+ :module_path => 'puppet/modules',
250
+ :puppetfile_path => 'puppet/Puppetfile',
251
+ :rootpath => '/rootpath',
252
+ :puppet_dir => 'puppet',
253
+ })
254
+ with_temp_env("VAGRANT_LOG" => "debug") do
255
+ retval = subject.call(env)
256
+ expect(R10K::Logging.level).to eq(0)
257
+ expect(retval).to be_nil
258
+ end
259
+ end
260
+ end
261
+ describe 'puppetfile does not exist' do
262
+ include_context 'unit' do
263
+ let(:vagrantfile) { <<-EOF
264
+ Vagrant.configure('2') do |config|
265
+ config.vm.define :test
266
+ # r10k plugin to deploy puppet modules
267
+ config.r10k.puppet_dir = 'puppet'
268
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
269
+
270
+ # Provision the machine with the appliction
271
+ config.vm.provision "puppet" do |puppet|
272
+ puppet.manifests_path = "puppet/manifests"
273
+ puppet.manifest_file = "default.pp"
274
+ puppet.module_path = "puppet/modules"
275
+ end
276
+ end
277
+ EOF
278
+ }
279
+ end
280
+ it 'raise an error' do
281
+ File.stub(:file?).with('/rootpath/puppet/Puppetfile').and_return(false)
282
+ expect(ui).to receive(:info).with(/Building the r10k module path with puppet provisioner module_path/).once
283
+ expect(ui).to receive(:info).with(/Beginning r10k deploy/).once
284
+ expect_did_not_run(ui, app, env, nobegin=false, appcall=false)
285
+ expect{subject.call(env)}.to raise_error(VagrantPlugins::R10k::ErrorWrapper, "RuntimeError: Puppetfile at /rootpath/puppet/Puppetfile does not exist.")
286
+ end
287
+ end
288
+ describe 'puppetfile syntax error' do
289
+ include_context 'unit' do
290
+ let(:vagrantfile) { <<-EOF
291
+ Vagrant.configure('2') do |config|
292
+ config.vm.define :test
293
+ # r10k plugin to deploy puppet modules
294
+ config.r10k.puppet_dir = 'puppet'
295
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
296
+
297
+ # Provision the machine with the appliction
298
+ config.vm.provision "puppet" do |puppet|
299
+ puppet.manifests_path = "puppet/manifests"
300
+ puppet.manifest_file = "default.pp"
301
+ puppet.module_path = "puppet/modules"
302
+ end
303
+ end
304
+ EOF
305
+ }
306
+ end
307
+ it 'raise an error' do
308
+ File.stub(:file?).with('/rootpath/puppet/Puppetfile').and_return(true)
309
+ expect(ui).to receive(:info).with(/Building the r10k module path with puppet provisioner module_path/).once
310
+ expect(ui).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"puppet/modules\". (if module_path is an array, first element is used)").exactly(0).times
311
+ full_puppetfile_path = File.join('/rootpath', 'puppet/Puppetfile')
312
+ full_puppet_dir = File.join('/rootpath', 'puppet')
313
+ full_module_path = File.join('/rootpath', 'puppet/modules')
314
+ File.stub(:file?).with(full_puppetfile_path).and_return(true)
315
+ File.stub(:readable?).with(full_puppetfile_path).and_return(true)
316
+ File.stub(:read).with(full_puppetfile_path).and_return("mod 'branan/eight_hundred' :git => 'https://github.com/branan/eight_hundred'")
317
+ errmsg = /SyntaxError: \/rootpath\/puppet\/Puppetfile:1: syntax error, unexpected ':', expecting end-of-input/
318
+ expect(ui).to receive(:info).with(/Beginning r10k deploy/).once
319
+ expect(ui).to receive(:info).with('vagrant-r10k: Deploy finished').exactly(0).times
320
+ expect(ui).to receive(:error).with('Invalid syntax in Puppetfile at /rootpath/puppet/Puppetfile').exactly(1).times
321
+ expect{subject.call(env)}.to raise_error(VagrantPlugins::R10k::ErrorWrapper, errmsg)
322
+ end
323
+ end
324
+ describe 'runner failed' do
325
+ include_context 'unit' do
326
+ let(:vagrantfile) { <<-EOF
327
+ Vagrant.configure('2') do |config|
328
+ config.vm.define :test
329
+ # r10k plugin to deploy puppet modules
330
+ config.r10k.puppet_dir = 'puppet'
331
+ config.r10k.puppetfile_path = 'puppet/Puppetfile'
332
+
333
+ # Provision the machine with the appliction
334
+ config.vm.provision "puppet" do |puppet|
335
+ puppet.manifests_path = "puppet/manifests"
336
+ puppet.manifest_file = "default.pp"
337
+ puppet.module_path = "puppet/modules"
338
+ end
339
+ end
340
+ EOF
341
+ }
342
+ end
343
+ it 'raise an error' do
344
+ File.stub(:file?).with('/rootpath/puppet/Puppetfile').and_return(true)
345
+ expect(ui).to receive(:info).with(/Building the r10k module path with puppet provisioner module_path/).once
346
+ expect(ui).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"puppet/modules\". (if module_path is an array, first element is used)").exactly(0).times
347
+ full_puppetfile_path = File.join('/rootpath', 'puppet/Puppetfile')
348
+ full_puppet_dir = File.join('/rootpath', 'puppet')
349
+ full_module_path = File.join('/rootpath', 'puppet/modules')
350
+ File.stub(:file?).with(full_puppetfile_path).and_return(true)
351
+ File.stub(:readable?).with(full_puppetfile_path).and_return(true)
352
+ File.stub(:read).with(full_puppetfile_path).and_return("mod 'puppetlabs/apache'")
353
+ expect(ui).to receive(:info).with(/Beginning r10k deploy/).once
354
+ runner = R10K::TaskRunner.new([])
355
+ R10K::TaskRunner.stub(:new).and_return(runner)
356
+ R10K::TaskRunner.stub(:append_task).and_call_original
357
+ runner.stub(:run)
358
+ runner.stub(:succeeded?).and_return(false)
359
+ runner.stub(:get_errors).and_return([['foo', 'this is an error']])
360
+ expect(runner).to receive(:append_task).once
361
+ expect(runner).to receive(:run).once
362
+ expect(ui).to receive(:info).with('vagrant-r10k: Deploy finished').exactly(0).times
363
+ expect{subject.call(env)}.to raise_error(VagrantPlugins::R10k::ErrorWrapper, /this is an error/)
364
+ end
365
+ end
366
+
367
+
368
+ end
369
+ end
@@ -0,0 +1,48 @@
1
+ module SharedExpectations
2
+ def expect_ran_successfully(vars)
3
+ # expect it to run with the right arguments, etc.
4
+ mp = vars[:module_path]
5
+ full_puppetfile_path = File.join(vars[:rootpath], vars[:puppetfile_path])
6
+ full_puppet_dir = File.join(vars[:rootpath], vars[:puppet_dir])
7
+ full_module_path = File.join(vars[:rootpath], vars[:module_path])
8
+ expect(vars[:ui]).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"#{mp}\". (if module_path is an array, first element is used)").once
9
+ File.stub(:file?).with(full_puppetfile_path).and_return(true)
10
+ expect(vars[:ui]).to receive(:info).with(/Beginning r10k deploy/).once
11
+ R10K::Puppetfile.stub(:new)
12
+ expect(R10K::Puppetfile).to receive(:new).with(full_puppet_dir, full_module_path, full_puppetfile_path).once
13
+ R10K::Task::Puppetfile::Sync.stub(:new).and_call_original
14
+ expect(R10K::Task::Puppetfile::Sync).to receive(:new).once
15
+ runner = R10K::TaskRunner.new([])
16
+ R10K::TaskRunner.stub(:new).and_return(runner)
17
+ R10K::TaskRunner.stub(:append_task).and_call_original
18
+ runner.stub(:run)
19
+ runner.stub(:succeeded?).and_return(true)
20
+ runner.stub(:get_errors).and_return([])
21
+ expect(runner).to receive(:append_task).once
22
+ expect(runner).to receive(:run).once
23
+ expect(vars[:ui]).to receive(:info).with('vagrant-r10k: Deploy finished').once
24
+ expect(ui).to receive(:error).exactly(0).times
25
+ end
26
+
27
+ def expect_did_not_run(ui, app, env, nobegin=true, appcall=true)
28
+ # expect it to not really run
29
+ if appcall
30
+ expect(app).to receive(:call).with(env).once
31
+ end
32
+ if nobegin
33
+ expect(ui).to receive(:info).with(/Beginning r10k deploy/).exactly(0).times
34
+ end
35
+ R10K::Puppetfile.stub(:new)
36
+ expect(R10K::Puppetfile).to receive(:new).exactly(0).times
37
+ runner = R10K::TaskRunner.new([])
38
+ R10K::TaskRunner.stub(:new).and_return(runner)
39
+ R10K::TaskRunner.stub(:append_task).and_call_original
40
+ runner.stub(:run)
41
+ runner.stub(:succeeded?).and_return(false)
42
+ runner.stub(:get_errors).and_return(['foo'])
43
+ expect(runner).to receive(:append_task).exactly(0).times
44
+ expect(runner).to receive(:run).exactly(0).times
45
+ end
46
+ end
47
+
48
+
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ shared_context "unit" do
4
+ include_context 'vagrant-unit'
5
+
6
+ let(:test_env) do
7
+ test_env = isolated_environment
8
+ test_env.vagrantfile vagrantfile
9
+ test_env
10
+ end
11
+ let(:env) { { env: iso_env, machine: machine, ui: ui, root_path: '/rootpath' } }
12
+ let(:conf) { Vagrant::Config::V2::DummyConfig.new() }
13
+ let(:ui) { Vagrant::UI::Basic.new() }
14
+ let(:iso_env) { test_env.create_vagrant_env ui_class: Vagrant::UI::Basic }
15
+ let(:machine) { iso_env.machine(:test, :dummy) }
16
+ # Mock the communicator to prevent SSH commands for being executed.
17
+ let(:communicator) { double('communicator') }
18
+ # Mock the guest operating system.
19
+ let(:guest) { double('guest') }
20
+ let(:app) { lambda { |env| } }
21
+ let(:plugin) { register_plugin() }
22
+
23
+ before (:each) do
24
+ machine.stub(:guest => guest)
25
+ machine.stub(:communicator => communicator)
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Antman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: r10k
@@ -62,6 +62,8 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
64
  - ".ruby-version"
65
+ - ".travis.yml"
66
+ - CHANGES.md
65
67
  - Gemfile
66
68
  - LICENSE.txt
67
69
  - README.md
@@ -71,6 +73,11 @@ files:
71
73
  - lib/vagrant-r10k/modulegetter.rb
72
74
  - lib/vagrant-r10k/plugin.rb
73
75
  - lib/vagrant-r10k/version.rb
76
+ - spec/spec_helper.rb
77
+ - spec/unit/config_spec.rb
78
+ - spec/unit/modulegetter_spec.rb
79
+ - spec/unit/shared_expectations.rb
80
+ - spec/unit/sharedcontext.rb
74
81
  - vagrant-r10k.gemspec
75
82
  homepage: https://github.com/jantman/vagrant-r10k
76
83
  licenses:
@@ -96,4 +103,9 @@ rubygems_version: 2.2.2
96
103
  signing_key:
97
104
  specification_version: 4
98
105
  summary: Vagrant middleware plugin to retrieve puppet modules using r10k.
99
- test_files: []
106
+ test_files:
107
+ - spec/spec_helper.rb
108
+ - spec/unit/config_spec.rb
109
+ - spec/unit/modulegetter_spec.rb
110
+ - spec/unit/shared_expectations.rb
111
+ - spec/unit/sharedcontext.rb