vagrant-r10k 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/.pullreview.yml +4 -0
- data/.rspec +5 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -1
- data/CHANGES.md +26 -0
- data/Gemfile +7 -2
- data/Gemfile.lock +181 -0
- data/README.md +122 -7
- data/Rakefile +111 -0
- data/lib/vagrant-r10k/action/base.rb +44 -0
- data/lib/vagrant-r10k/action/deploy.rb +91 -0
- data/lib/vagrant-r10k/action/validate.rb +46 -0
- data/lib/vagrant-r10k/config.rb +13 -4
- data/lib/vagrant-r10k/helpers.rb +174 -0
- data/lib/vagrant-r10k/plugin.rb +11 -5
- data/lib/vagrant-r10k/version.rb +2 -1
- data/spec/acceptance/skeletons/correct/Vagrantfile +21 -0
- data/spec/acceptance/skeletons/correct/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/correct/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/correct/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/correct/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/correct/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/Vagrantfile +21 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/Puppetfile +7 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/different_mod_path/Vagrantfile +19 -0
- data/spec/acceptance/skeletons/different_mod_path/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_mod_path/Vagrantfile +17 -0
- data/spec/acceptance/skeletons/no_mod_path/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_puppet_dir/Vagrantfile +18 -0
- data/spec/acceptance/skeletons/no_puppet_dir/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/Vagrantfile +14 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/Vagrantfile +18 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/Puppetfile +1 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/vagrant-r10k/vagrant-r10k_spec.rb +255 -0
- data/spec/spec_helper.rb +10 -7
- data/spec/unit/action_base_spec.rb +57 -0
- data/spec/unit/action_deploy_spec.rb +550 -0
- data/spec/unit/action_validate_spec.rb +240 -0
- data/spec/unit/helpers_spec.rb +307 -0
- data/spec/unit/plugin_spec.rb +49 -0
- data/support/testrunner.py +189 -0
- data/vagrant-r10k.gemspec +1 -1
- data/vagrant-spec.config.rb +18 -0
- metadata +111 -19
- data/lib/vagrant-r10k/modulegetter.rb +0 -145
- data/spec/unit/modulegetter_spec.rb +0 -369
@@ -0,0 +1,240 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'sharedcontext'
|
3
|
+
require_relative 'shared_expectations'
|
4
|
+
require 'vagrant-r10k/action/base'
|
5
|
+
require 'vagrant-r10k/action/validate'
|
6
|
+
|
7
|
+
include SharedExpectations
|
8
|
+
|
9
|
+
describe VagrantPlugins::R10k::Action::Validate do
|
10
|
+
|
11
|
+
subject { described_class.new(app, env) }
|
12
|
+
|
13
|
+
include_context 'vagrant-unit'
|
14
|
+
|
15
|
+
describe '#call' do
|
16
|
+
describe 'r10k not enabled' do
|
17
|
+
let(:pf_dbl) { double }
|
18
|
+
before do
|
19
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(false)
|
20
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(true)
|
21
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return({:puppetfile_path => 'p'})
|
22
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
23
|
+
end
|
24
|
+
include_context 'unit' do
|
25
|
+
let(:vagrantfile) { <<-EOF
|
26
|
+
Vagrant.configure('2') do |config|
|
27
|
+
config.vm.define :test
|
28
|
+
# r10k plugin to deploy puppet modules
|
29
|
+
# config.r10k.puppet_dir = 'puppet'
|
30
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
31
|
+
|
32
|
+
# Provision the machine with the appliction
|
33
|
+
config.vm.provision "puppet" do |puppet|
|
34
|
+
puppet.manifests_path = "puppet/manifests"
|
35
|
+
puppet.manifest_file = "default.pp"
|
36
|
+
puppet.module_path = "puppet/modules"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
EOF
|
40
|
+
}
|
41
|
+
end
|
42
|
+
it 'should send ui info and return' do
|
43
|
+
# positive assertions
|
44
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
45
|
+
expect(ui).to receive(:info).with("vagrant-r10k not configured; skipping").once
|
46
|
+
expect(app).to receive(:call).once.with(env)
|
47
|
+
# negative assetions
|
48
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to_not receive(:provision_enabled?)
|
49
|
+
expect(ui).to_not receive(:info).with(/Beginning r10k deploy/)
|
50
|
+
expect(subject).to receive(:deploy).exactly(0).times
|
51
|
+
# run
|
52
|
+
expect(subject.call(env)).to be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'provisioning not enabled' do
|
57
|
+
let(:pf_dbl) { double }
|
58
|
+
before do
|
59
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(true)
|
60
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(false)
|
61
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return({:puppetfile_path => 'p'})
|
62
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
63
|
+
end
|
64
|
+
include_context 'unit' do
|
65
|
+
let(:vagrantfile) { <<-EOF
|
66
|
+
Vagrant.configure('2') do |config|
|
67
|
+
config.vm.define :test
|
68
|
+
# r10k plugin to deploy puppet modules
|
69
|
+
config.r10k.puppet_dir = 'puppet'
|
70
|
+
config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
71
|
+
|
72
|
+
# Provision the machine with the appliction
|
73
|
+
config.vm.provision "puppet" do |puppet|
|
74
|
+
puppet.manifests_path = "puppet/manifests"
|
75
|
+
puppet.manifest_file = "default.pp"
|
76
|
+
puppet.module_path = "puppet/modules"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
EOF
|
80
|
+
}
|
81
|
+
end
|
82
|
+
it 'should send ui info and return' do
|
83
|
+
# positive assertions
|
84
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
85
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).with(env).once
|
86
|
+
expect(ui).to receive(:info).with("provisioning disabled; skipping vagrant-r10k").once
|
87
|
+
expect(app).to receive(:call).once.with(env)
|
88
|
+
# negative assetions
|
89
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to_not receive(:r10k_config)
|
90
|
+
expect(ui).to_not receive(:info).with(/Beginning r10k deploy/)
|
91
|
+
expect(subject).to receive(:deploy).exactly(0).times
|
92
|
+
# run
|
93
|
+
expect(subject.call(env)).to be_nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'config is nil' do
|
98
|
+
let(:pf_dbl) { double }
|
99
|
+
before do
|
100
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(true)
|
101
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(true)
|
102
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return(nil)
|
103
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
104
|
+
end
|
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
|
+
|
113
|
+
# Provision the machine with the appliction
|
114
|
+
config.vm.provision "puppet" do |puppet|
|
115
|
+
puppet.manifests_path = "puppet/manifests"
|
116
|
+
puppet.manifest_file = "default.pp"
|
117
|
+
puppet.module_path = "puppet/modules"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
EOF
|
121
|
+
}
|
122
|
+
end
|
123
|
+
it 'should raise exception' do
|
124
|
+
# positive assertions
|
125
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
126
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).with(env).once
|
127
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).once
|
128
|
+
logger = subject.instance_variable_get(:@logger)
|
129
|
+
expect(logger).to receive(:info).once.with("vagrant::r10k::deploy got nil configuration")
|
130
|
+
expect(app).to_not receive(:call)
|
131
|
+
# negative assetions
|
132
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to_not receive(:r10k_config)
|
133
|
+
expect(ui).to_not receive(:info).with(/Beginning r10k deploy/)
|
134
|
+
expect(subject).to receive(:deploy).exactly(0).times
|
135
|
+
# run
|
136
|
+
expect { subject.call(env) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /vagrant-r10k configuration error; cannot continue/)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'puppetfile passes validation' do
|
141
|
+
let(:config) {{
|
142
|
+
:env_dir_path => 'env/dir/path',
|
143
|
+
:puppetfile_path => 'puppetfile/path',
|
144
|
+
:module_path => 'module/path',
|
145
|
+
:manifests => 'manifests',
|
146
|
+
:manifest_file => 'manifest/file',
|
147
|
+
:puppet_dir => 'puppet/dir',
|
148
|
+
}}
|
149
|
+
let(:pf_dbl) { double }
|
150
|
+
before do
|
151
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(true)
|
152
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(true)
|
153
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return(config)
|
154
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
155
|
+
end
|
156
|
+
include_context 'unit' do
|
157
|
+
let(:vagrantfile) { <<-EOF
|
158
|
+
Vagrant.configure('2') do |config|
|
159
|
+
config.vm.define :test
|
160
|
+
# r10k plugin to deploy puppet modules
|
161
|
+
config.r10k.puppet_dir = 'puppet'
|
162
|
+
config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
163
|
+
|
164
|
+
# Provision the machine with the appliction
|
165
|
+
config.vm.provision "puppet" do |puppet|
|
166
|
+
puppet.manifests_path = "puppet/manifests"
|
167
|
+
puppet.manifest_file = "default.pp"
|
168
|
+
puppet.module_path = "puppet/modules"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
EOF
|
172
|
+
}
|
173
|
+
end
|
174
|
+
it 'should call app.call' do
|
175
|
+
# positive assertions
|
176
|
+
allow(pf_dbl).to receive(:load).exactly(1).times.and_return(true)
|
177
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
178
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).with(env).once
|
179
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).once
|
180
|
+
logger = subject.instance_variable_get(:@logger)
|
181
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::validate called")
|
182
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::validate: validating Puppetfile at puppetfile/path")
|
183
|
+
expect(pf_dbl).to receive(:load).once
|
184
|
+
expect(app).to receive(:call).once.with(env)
|
185
|
+
expect(subject.call(env)).to be_nil
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe 'puppetfile fails validation' do
|
190
|
+
let(:config) {{
|
191
|
+
:env_dir_path => 'env/dir/path',
|
192
|
+
:puppetfile_path => 'puppetfile/path',
|
193
|
+
:module_path => 'module/path',
|
194
|
+
:manifests => 'manifests',
|
195
|
+
:manifest_file => 'manifest/file',
|
196
|
+
:puppet_dir => 'puppet/dir',
|
197
|
+
}}
|
198
|
+
let(:pf_dbl) { double }
|
199
|
+
before do
|
200
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(true)
|
201
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(true)
|
202
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return(config)
|
203
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
204
|
+
end
|
205
|
+
include_context 'unit' do
|
206
|
+
let(:vagrantfile) { <<-EOF
|
207
|
+
Vagrant.configure('2') do |config|
|
208
|
+
config.vm.define :test
|
209
|
+
# r10k plugin to deploy puppet modules
|
210
|
+
config.r10k.puppet_dir = 'puppet'
|
211
|
+
config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
212
|
+
|
213
|
+
# Provision the machine with the appliction
|
214
|
+
config.vm.provision "puppet" do |puppet|
|
215
|
+
puppet.manifests_path = "puppet/manifests"
|
216
|
+
puppet.manifest_file = "default.pp"
|
217
|
+
puppet.module_path = "puppet/modules"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
EOF
|
221
|
+
}
|
222
|
+
end
|
223
|
+
it 'should call app.call' do
|
224
|
+
# positive assertions
|
225
|
+
allow(pf_dbl).to receive(:load).and_raise(RuntimeError)
|
226
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
227
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).with(env).once
|
228
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).once
|
229
|
+
logger = subject.instance_variable_get(:@logger)
|
230
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::validate called")
|
231
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::validate: validating Puppetfile at puppetfile/path")
|
232
|
+
expect(pf_dbl).to receive(:load).once
|
233
|
+
# negative assertions
|
234
|
+
expect(app).to_not receive(:call)
|
235
|
+
# run
|
236
|
+
expect { subject.call(env) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vagrant-r10k/helpers'
|
4
|
+
|
5
|
+
describe Log4r::Logger do
|
6
|
+
subject { described_class.new('testlogger') }
|
7
|
+
describe '#debug1' do
|
8
|
+
it 'should pass through to debug' do
|
9
|
+
expect(subject).to receive(:debug).with('a message').once
|
10
|
+
subject.debug1('a message')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
describe '#debug2' do
|
14
|
+
it 'should pass through to debug' do
|
15
|
+
expect(subject).to receive(:debug).with('different message').once
|
16
|
+
subject.debug2('different message')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe R10K::TaskRunner do
|
22
|
+
subject { described_class.new([]) }
|
23
|
+
describe '#get_errors' do
|
24
|
+
it 'returns @errors' do
|
25
|
+
subject.instance_variable_set(:@errors, ['foo'])
|
26
|
+
expect(subject).to receive(:get_errors).once.and_call_original
|
27
|
+
foo = subject.get_errors
|
28
|
+
expect(foo).to eq(['foo'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe VagrantPlugins::R10k::Helpers::ErrorWrapper do
|
34
|
+
describe '#initialize' do
|
35
|
+
it 'sets instance variable' do
|
36
|
+
foo = double
|
37
|
+
klass = described_class.new(foo)
|
38
|
+
expect(klass.instance_variable_get(:@original)).to eq(foo)
|
39
|
+
end
|
40
|
+
it 'has attr_reader' do
|
41
|
+
foo = double
|
42
|
+
klass = described_class.new(foo)
|
43
|
+
expect(klass.original).to eq(foo)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe '#to_s' do
|
47
|
+
it 'returns the proper string' do
|
48
|
+
foo = double
|
49
|
+
allow(foo).to receive(:class).and_return('foo')
|
50
|
+
allow(foo).to receive(:to_s).and_return('foostr')
|
51
|
+
klass = described_class.new(foo)
|
52
|
+
expect(klass.to_s).to eq('foo: foostr')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
describe '#method_missind' do
|
56
|
+
it 'sends to foo' do
|
57
|
+
foo = double
|
58
|
+
allow(foo).to receive(:bar).and_return('baz')
|
59
|
+
foo.should_receive(:bar).once
|
60
|
+
klass = described_class.new(foo)
|
61
|
+
expect(klass.bar).to eq('baz')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe VagrantPlugins::R10k::Helpers do
|
67
|
+
include VagrantPlugins::R10k::Helpers
|
68
|
+
|
69
|
+
describe '#r10k_enabled?' do
|
70
|
+
context 'puppet_dir unset' do
|
71
|
+
it 'returns false' do
|
72
|
+
env = {:machine => double}
|
73
|
+
env[:machine].stub_chain(:config, :r10k, :puppet_dir).and_return(Vagrant::Plugin::V2::Config::UNSET_VALUE)
|
74
|
+
env[:machine].stub_chain(:config, :r10k, :puppetfile_path).and_return('/puppetfile/path')
|
75
|
+
expect(r10k_enabled?(env)).to be_falsey
|
76
|
+
end
|
77
|
+
end
|
78
|
+
context 'puppetfile_path unset' do
|
79
|
+
it 'returns false' do
|
80
|
+
env = {:machine => double}
|
81
|
+
env[:machine].stub_chain(:config, :r10k, :puppet_dir).and_return('/puppet/dir')
|
82
|
+
env[:machine].stub_chain(:config, :r10k, :puppetfile_path).and_return(Vagrant::Plugin::V2::Config::UNSET_VALUE)
|
83
|
+
expect(r10k_enabled?(env)).to be_falsey
|
84
|
+
end
|
85
|
+
end
|
86
|
+
context 'puppet_dir unset' do
|
87
|
+
it 'returns false' do
|
88
|
+
env = {:machine => double}
|
89
|
+
env[:machine].stub_chain(:config, :r10k, :puppet_dir).and_return('/puppet/dir')
|
90
|
+
env[:machine].stub_chain(:config, :r10k, :puppetfile_path).and_return('/puppetfile/path')
|
91
|
+
expect(r10k_enabled?(env)).to be_truthy
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#provision_enabled?' do
|
97
|
+
context 'env not set' do
|
98
|
+
it 'returns true' do
|
99
|
+
env = {}
|
100
|
+
expect(provision_enabled?(env)).to be_truthy
|
101
|
+
end
|
102
|
+
end
|
103
|
+
context 'env set to true' do
|
104
|
+
it 'returns true' do
|
105
|
+
env = {:provision_enabled => true}
|
106
|
+
expect(provision_enabled?(env)).to be_truthy
|
107
|
+
end
|
108
|
+
end
|
109
|
+
context 'env set to false' do
|
110
|
+
it 'returns false' do
|
111
|
+
env = {:provision_enabled => false}
|
112
|
+
expect(provision_enabled?(env)).to be_falsey
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#env_dir' do
|
118
|
+
it 'returns root_path' do
|
119
|
+
env = {:root_path => '/foo'}
|
120
|
+
expect(env_dir(env)).to eq('/foo')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#puppetfile_path' do
|
125
|
+
before { allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:env_dir).and_return('/my/env/dir') }
|
126
|
+
it 'returns joined path' do
|
127
|
+
env = {:machine => double}
|
128
|
+
env[:machine].stub_chain(:config, :r10k, :puppetfile_path).and_return('path/to/puppetfile')
|
129
|
+
expect(puppetfile_path(env)).to eq('/my/env/dir/path/to/puppetfile')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#puppet_provisioner' do
|
134
|
+
context 'one puppet provisioner with :type' do
|
135
|
+
it 'returns that provisioner' do
|
136
|
+
# double for puppet provisioner
|
137
|
+
prov_dbl = double
|
138
|
+
allow(prov_dbl).to receive(:type).and_return(:puppet)
|
139
|
+
provisioners = [prov_dbl]
|
140
|
+
# double for env
|
141
|
+
env = {:machine => double}
|
142
|
+
env[:machine].stub_chain(:config, :vm, :provisioners).and_return(provisioners)
|
143
|
+
expect(puppet_provisioner(env)).to eq(prov_dbl)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
context 'one puppet provisioner with :name' do
|
147
|
+
it 'returns that provisioner' do
|
148
|
+
# double for puppet provisioner
|
149
|
+
prov_dbl = double
|
150
|
+
allow(prov_dbl).to receive(:name).and_return(:puppet)
|
151
|
+
provisioners = [prov_dbl]
|
152
|
+
# double for env
|
153
|
+
env = {:machine => double}
|
154
|
+
env[:machine].stub_chain(:config, :vm, :provisioners).and_return(provisioners)
|
155
|
+
expect(puppet_provisioner(env)).to eq(prov_dbl)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
context 'no puppet provisioners' do
|
159
|
+
it 'returns nil' do
|
160
|
+
# double for chef provisioner
|
161
|
+
prov_dbl = double
|
162
|
+
allow(prov_dbl).to receive(:name).and_return(:chef)
|
163
|
+
# double for 'soemthing' provisioner
|
164
|
+
prov2_dbl = double
|
165
|
+
allow(prov2_dbl).to receive(:name).and_return(:something)
|
166
|
+
provisioners = [prov_dbl, prov2_dbl]
|
167
|
+
# double for env
|
168
|
+
env = {:machine => double}
|
169
|
+
env[:machine].stub_chain(:config, :vm, :provisioners).and_return(provisioners)
|
170
|
+
expect(puppet_provisioner(env)).to be_nil
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context 'two puppet provisioners' do
|
174
|
+
it 'returns last provisioner' do
|
175
|
+
# double for puppet provisioner
|
176
|
+
prov_dbl = double
|
177
|
+
allow(prov_dbl).to receive(:type).and_return(:puppet)
|
178
|
+
# double for other puppet provisioner
|
179
|
+
prov2_dbl = double
|
180
|
+
allow(prov2_dbl).to receive(:name).and_return(:puppet)
|
181
|
+
provisioners = [prov_dbl, prov2_dbl]
|
182
|
+
# double for env
|
183
|
+
env = {:machine => double}
|
184
|
+
env[:machine].stub_chain(:config, :vm, :provisioners).and_return(provisioners)
|
185
|
+
expect(puppet_provisioner(env)).to eq(prov2_dbl)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '#r10k_config' do
|
191
|
+
context 'puppet_provisioner is nil' do
|
192
|
+
before do
|
193
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:env_dir).and_return('/my/env/dir')
|
194
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:puppetfile_path).and_return('puppet/file/path')
|
195
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:puppet_provisioner).and_return(nil)
|
196
|
+
end
|
197
|
+
it 'returns nil' do
|
198
|
+
env = double
|
199
|
+
expect(r10k_config(env)).to be_nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
context 'module_path is nil' do
|
203
|
+
before do
|
204
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:env_dir).and_return('/my/env/dir')
|
205
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:puppetfile_path).and_return('puppet/file/path')
|
206
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:puppet_provisioner).and_return(:pup_prov)
|
207
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:module_path).and_return(nil)
|
208
|
+
end
|
209
|
+
it 'returns nil' do
|
210
|
+
env = double
|
211
|
+
expect(r10k_config(env)).to be_nil
|
212
|
+
end
|
213
|
+
end
|
214
|
+
context 'no methods return nil' do
|
215
|
+
before do
|
216
|
+
prov_dbl = double
|
217
|
+
prov_dbl.stub_chain(:config, :manifest_file).and_return('manifest/file')
|
218
|
+
prov_dbl.stub_chain(:config, :manifests_path).and_return([0, 'manifests/path'])
|
219
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:env_dir).and_return('/my/env/dir')
|
220
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:puppetfile_path).and_return('puppet/file/path')
|
221
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:puppet_provisioner).and_return(prov_dbl)
|
222
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:module_path).and_return('module/path')
|
223
|
+
end
|
224
|
+
it 'returns config' do
|
225
|
+
env = {:machine => double}
|
226
|
+
env[:machine].stub_chain(:config, :r10k, :puppet_dir).and_return('puppet/dir')
|
227
|
+
expect(r10k_config(env)).to eq({
|
228
|
+
:env_dir_path => '/my/env/dir',
|
229
|
+
:puppetfile_path => 'puppet/file/path',
|
230
|
+
:module_path => 'module/path',
|
231
|
+
:manifest_file => '/my/env/dir/manifest/file',
|
232
|
+
:manifests => '/my/env/dir/manifests/path',
|
233
|
+
:puppet_dir => '/my/env/dir/puppet/dir',
|
234
|
+
})
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe '#module_path' do
|
240
|
+
context 'config.r10k.module_path unset and provisioner module_path nil' do
|
241
|
+
it 'returns nil' do
|
242
|
+
prov_dbl = double
|
243
|
+
prov_dbl.stub_chain(:config, :module_path).and_return(nil)
|
244
|
+
env = {:machine => double, :ui => double}
|
245
|
+
allow(env[:ui]).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"\". (if module_path is an array, first element is used)")
|
246
|
+
env[:machine].stub_chain(:config, :r10k, :module_path).and_return(Vagrant::Plugin::V2::Config::UNSET_VALUE)
|
247
|
+
expect(module_path(env, prov_dbl, '/env/dir/path')).to be_nil
|
248
|
+
end
|
249
|
+
end
|
250
|
+
context 'config.r10k.module_path unset and provisioner module_path string' do
|
251
|
+
it 'returns the joined module_path' do
|
252
|
+
prov_dbl = double
|
253
|
+
prov_dbl.stub_chain(:config, :module_path).and_return('module/path')
|
254
|
+
env = {:machine => double, :ui => double}
|
255
|
+
allow(env[:ui]).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"module/path\". (if module_path is an array, first element is used)")
|
256
|
+
env[:machine].stub_chain(:config, :r10k, :module_path).and_return('module/path')
|
257
|
+
expect(module_path(env, prov_dbl, '/env/dir/path')).to eq('/env/dir/path/module/path')
|
258
|
+
end
|
259
|
+
end
|
260
|
+
context 'config.r10k.module_path unset and provisioner module_path array' do
|
261
|
+
it 'returns the joined first module_path' do
|
262
|
+
prov_dbl = double
|
263
|
+
prov_dbl.stub_chain(:config, :module_path).and_return(['module/path', 'foo'])
|
264
|
+
env = {:machine => double, :ui => double}
|
265
|
+
allow(env[:ui]).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"module/path\". (if module_path is an array, first element is used)")
|
266
|
+
env[:machine].stub_chain(:config, :r10k, :module_path).and_return('module/path')
|
267
|
+
expect(module_path(env, prov_dbl, '/env/dir/path')).to eq('/env/dir/path/module/path')
|
268
|
+
end
|
269
|
+
end
|
270
|
+
context 'provisioner module_path array doesnt include r10k module_path' do
|
271
|
+
it 'raises ErrorWrapper' do
|
272
|
+
prov_dbl = double
|
273
|
+
prov_dbl.stub_chain(:config, :module_path).and_return(['module/path', 'foo'])
|
274
|
+
env = {:machine => double, :ui => double}
|
275
|
+
allow(env[:ui]).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"\". (if module_path is an array, first element is used)")
|
276
|
+
env[:machine].stub_chain(:config, :r10k, :module_path).and_return('r10kmodule/path')
|
277
|
+
expect { module_path(env, prov_dbl, '/env/dir/path') }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /module_path "r10kmodule\/path" is not within the ones defined in puppet provisioner; please correct this condition/)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
context 'provisioner module_path string doesnt match r10k module_path' do
|
281
|
+
it 'raises ErrorWrapper' do
|
282
|
+
prov_dbl = double
|
283
|
+
prov_dbl.stub_chain(:config, :module_path).and_return('module/path')
|
284
|
+
env = {:machine => double, :ui => double}
|
285
|
+
allow(env[:ui]).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"\". (if module_path is an array, first element is used)")
|
286
|
+
env[:machine].stub_chain(:config, :r10k, :module_path).and_return('r10kmodule/path')
|
287
|
+
expect { module_path(env, prov_dbl, '/env/dir/path') }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /module_path "r10kmodule\/path" is not the same as in puppet provisioner; please correct this condition/)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
describe '#get_puppetfile' do
|
293
|
+
it 'returns a Puppetfile' do
|
294
|
+
config = {
|
295
|
+
:puppet_dir => 'puppet/dir',
|
296
|
+
:module_path => 'module/path',
|
297
|
+
:puppetfile_path => 'puppetfile/path',
|
298
|
+
}
|
299
|
+
res = get_puppetfile(config)
|
300
|
+
expect(res).to be_a_kind_of(R10K::Puppetfile)
|
301
|
+
expect(res.instance_variable_get(:@basedir)).to eq('puppet/dir')
|
302
|
+
expect(res.instance_variable_get(:@moduledir)).to eq('module/path')
|
303
|
+
expect(res.instance_variable_get(:@puppetfile_path)).to eq('puppetfile/path')
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'sharedcontext'
|
3
|
+
require_relative 'shared_expectations'
|
4
|
+
require 'vagrant-r10k/plugin'
|
5
|
+
require 'vagrant-r10k/action/base'
|
6
|
+
|
7
|
+
include SharedExpectations
|
8
|
+
|
9
|
+
describe VagrantPlugins::R10k::Plugin do
|
10
|
+
include_context 'vagrant-unit'
|
11
|
+
context 'action hooks' do
|
12
|
+
let(:hook) { double(append: true, prepend: true) }
|
13
|
+
it 'should set hooks' do
|
14
|
+
# I had lots of problems with this, but found an example at:
|
15
|
+
# https://github.com/petems/vagrant-puppet-install/blob/60b26f8d4f4d82b687bc527b239cba2baaf95731/test/unit/vagrant-puppet-install/plugin_spec.rb
|
16
|
+
[:machine_action_up, :machine_action_reload, :machine_action_provision].each do |action|
|
17
|
+
hook_proc = described_class.components.action_hooks[action][0]
|
18
|
+
hook = double
|
19
|
+
VagrantPlugins::R10k::Action::Base.stub(:validate => 'foo', :deploy => 'bar')
|
20
|
+
expect(hook).to receive(:after).with(Vagrant::Action::Builtin::ConfigValidate, 'foo')
|
21
|
+
expect(hook).to receive(:before).with(Vagrant::Action::Builtin::Provision, 'bar')
|
22
|
+
hook_proc.call(hook)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context 'config' do
|
27
|
+
it 'registers itself' do
|
28
|
+
expect(described_class.components.configs[:top].get(:r10k)).to_not be_nil
|
29
|
+
end
|
30
|
+
it 'uses the Config class' do
|
31
|
+
cfg = described_class.components.configs[:top].get(:r10k)
|
32
|
+
expect(cfg).to eq(VagrantPlugins::R10k::Config)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context 'attributes' do
|
36
|
+
it 'should have the proper name' do
|
37
|
+
expect(described_class.name).to eq('vagrant-r10k')
|
38
|
+
end
|
39
|
+
it 'should have the proper description' do
|
40
|
+
expect(described_class.description).to eq('Retrieve puppet modules based on a Puppetfile')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
context 'instantiation' do
|
44
|
+
it 'is a vagrant v2 plugin' do
|
45
|
+
x = described_class.new
|
46
|
+
expect(x).to be_a_kind_of(Vagrant::Plugin::V2::Plugin)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|