r10k 3.15.0 → 3.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.mkd +5 -0
- data/CODEOWNERS +2 -2
- data/doc/dynamic-environments/configuration.mkd +65 -1
- data/lib/r10k/version.rb +1 -1
- data/r10k.gemspec +1 -1
- metadata +2 -151
- data/spec/fixtures/empty/.empty +0 -0
- data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
- data/spec/fixtures/module/forge/bad_module/metadata.json +0 -1
- data/spec/fixtures/module/forge/eight_hundred/Modulefile +0 -8
- data/spec/fixtures/module/forge/eight_hundred/metadata.json +0 -19
- data/spec/fixtures/tarball/tarball.tar.gz +0 -0
- data/spec/fixtures/unit/action/r10k.yaml +0 -5
- data/spec/fixtures/unit/action/r10k_cachedir.yaml +0 -2
- data/spec/fixtures/unit/action/r10k_creds.yaml +0 -9
- data/spec/fixtures/unit/action/r10k_forge_auth.yaml +0 -4
- data/spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml +0 -3
- data/spec/fixtures/unit/action/r10k_generate_types.yaml +0 -3
- data/spec/fixtures/unit/action/r10k_logging.yaml +0 -12
- data/spec/fixtures/unit/action/r10k_puppet_path.yaml +0 -3
- data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +0 -1
- data/spec/fixtures/unit/puppetfile/default-branch-override/Puppetfile +0 -5
- data/spec/fixtures/unit/puppetfile/duplicate-module-error/Puppetfile +0 -10
- data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +0 -8
- data/spec/fixtures/unit/puppetfile/invalid-syntax/Puppetfile +0 -1
- data/spec/fixtures/unit/puppetfile/load-error/Puppetfile +0 -1
- data/spec/fixtures/unit/puppetfile/name-error/Puppetfile +0 -1
- data/spec/fixtures/unit/puppetfile/valid-forge-with-version/Puppetfile +0 -1
- data/spec/fixtures/unit/puppetfile/valid-forge-without-version/Puppetfile +0 -1
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +0 -10
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +0 -10
- data/spec/fixtures/unit/puppetfile/various-modules/modules/apt/.gitkeep +0 -1
- data/spec/fixtures/unit/puppetfile/various-modules/modules/baz/.gitkeep +0 -1
- data/spec/fixtures/unit/puppetfile/various-modules/modules/buzz/.gitkeep +0 -1
- data/spec/fixtures/unit/puppetfile/various-modules/modules/canary/.gitkeep +0 -1
- data/spec/fixtures/unit/puppetfile/various-modules/modules/fizz/.gitkeep +0 -1
- data/spec/fixtures/unit/puppetfile/various-modules/modules/rpm/.gitkeep +0 -1
- data/spec/fixtures/unit/util/purgeable/managed_one/expected_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +0 -1
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_allowlisted_2/ignored_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_unmanaged_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +0 -1
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +0 -1
- data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +0 -1
- data/spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/expected_2 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/unmanaged_2 +0 -0
- data/spec/fixtures/unit/util/subprocess/runner/no-execute.sh +0 -3
- data/spec/integration/git/rugged/bare_repository_spec.rb +0 -13
- data/spec/integration/git/rugged/cache_spec.rb +0 -33
- data/spec/integration/git/rugged/thin_repository_spec.rb +0 -14
- data/spec/integration/git/rugged/working_repository_spec.rb +0 -48
- data/spec/integration/git/shellgit/bare_repository_spec.rb +0 -13
- data/spec/integration/git/shellgit/thin_repository_spec.rb +0 -14
- data/spec/integration/git/shellgit/working_repository_spec.rb +0 -13
- data/spec/integration/git/stateful_repository_spec.rb +0 -175
- data/spec/integration/util/purageable_spec.rb +0 -41
- data/spec/matchers/exit_with.rb +0 -28
- data/spec/matchers/match_realpath.rb +0 -18
- data/spec/r10k-mocks/mock_config.rb +0 -33
- data/spec/r10k-mocks/mock_env.rb +0 -18
- data/spec/r10k-mocks/mock_source.rb +0 -17
- data/spec/r10k-mocks.rb +0 -3
- data/spec/shared-contexts/git-fixtures.rb +0 -55
- data/spec/shared-contexts/tarball.rb +0 -32
- data/spec/shared-examples/deploy-actions.rb +0 -69
- data/spec/shared-examples/git/bare_repository.rb +0 -132
- data/spec/shared-examples/git/thin_repository.rb +0 -26
- data/spec/shared-examples/git/working_repository.rb +0 -207
- data/spec/shared-examples/git-repository.rb +0 -38
- data/spec/shared-examples/puppetfile-action.rb +0 -39
- data/spec/shared-examples/settings/ancestry.rb +0 -44
- data/spec/shared-examples/subprocess-runner.rb +0 -89
- data/spec/spec_helper.rb +0 -41
- data/spec/unit/action/cri_runner_spec.rb +0 -72
- data/spec/unit/action/deploy/deploy_helpers_spec.rb +0 -38
- data/spec/unit/action/deploy/display_spec.rb +0 -61
- data/spec/unit/action/deploy/environment_spec.rb +0 -640
- data/spec/unit/action/deploy/module_spec.rb +0 -476
- data/spec/unit/action/puppetfile/check_spec.rb +0 -53
- data/spec/unit/action/puppetfile/cri_runner_spec.rb +0 -47
- data/spec/unit/action/puppetfile/install_spec.rb +0 -112
- data/spec/unit/action/puppetfile/purge_spec.rb +0 -60
- data/spec/unit/action/runner_spec.rb +0 -407
- data/spec/unit/action/visitor_spec.rb +0 -39
- data/spec/unit/cli_spec.rb +0 -9
- data/spec/unit/deployment/config_spec.rb +0 -33
- data/spec/unit/deployment_spec.rb +0 -162
- data/spec/unit/environment/bare_spec.rb +0 -13
- data/spec/unit/environment/base_spec.rb +0 -122
- data/spec/unit/environment/git_spec.rb +0 -114
- data/spec/unit/environment/name_spec.rb +0 -181
- data/spec/unit/environment/plain_spec.rb +0 -8
- data/spec/unit/environment/svn_spec.rb +0 -146
- data/spec/unit/environment/tarball_spec.rb +0 -45
- data/spec/unit/environment/with_modules_spec.rb +0 -122
- data/spec/unit/errors/formatting_spec.rb +0 -84
- data/spec/unit/feature_spec.rb +0 -50
- data/spec/unit/forge/module_release_spec.rb +0 -213
- data/spec/unit/git/alternates_spec.rb +0 -116
- data/spec/unit/git/cache_spec.rb +0 -66
- data/spec/unit/git/rugged/cache_spec.rb +0 -48
- data/spec/unit/git/rugged/credentials_spec.rb +0 -215
- data/spec/unit/git/shellgit/cache_spec.rb +0 -27
- data/spec/unit/git/stateful_repository_spec.rb +0 -45
- data/spec/unit/git_spec.rb +0 -102
- data/spec/unit/initializers_spec.rb +0 -68
- data/spec/unit/instance_cache_spec.rb +0 -78
- data/spec/unit/keyed_factory_spec.rb +0 -51
- data/spec/unit/logging/terminaloutputter_spec.rb +0 -53
- data/spec/unit/logging_spec.rb +0 -68
- data/spec/unit/module/base_spec.rb +0 -118
- data/spec/unit/module/forge_spec.rb +0 -271
- data/spec/unit/module/git_spec.rb +0 -387
- data/spec/unit/module/metadata_file_spec.rb +0 -68
- data/spec/unit/module/svn_spec.rb +0 -208
- data/spec/unit/module/tarball_spec.rb +0 -70
- data/spec/unit/module_loader/puppetfile_spec.rb +0 -421
- data/spec/unit/module_spec.rb +0 -114
- data/spec/unit/puppetfile_spec.rb +0 -304
- data/spec/unit/settings/collection_spec.rb +0 -123
- data/spec/unit/settings/container_spec.rb +0 -92
- data/spec/unit/settings/definition_spec.rb +0 -79
- data/spec/unit/settings/enum_definition_spec.rb +0 -20
- data/spec/unit/settings/inheritance_spec.rb +0 -38
- data/spec/unit/settings/list_spec.rb +0 -88
- data/spec/unit/settings/loader_spec.rb +0 -110
- data/spec/unit/settings/uri_definition_spec.rb +0 -23
- data/spec/unit/settings_spec.rb +0 -303
- data/spec/unit/source/base_spec.rb +0 -31
- data/spec/unit/source/exec_spec.rb +0 -81
- data/spec/unit/source/git_spec.rb +0 -233
- data/spec/unit/source/hash_spec.rb +0 -54
- data/spec/unit/source/svn_spec.rb +0 -196
- data/spec/unit/source/yaml_spec.rb +0 -42
- data/spec/unit/source_spec.rb +0 -10
- data/spec/unit/svn/remote_spec.rb +0 -21
- data/spec/unit/svn/working_dir_spec.rb +0 -56
- data/spec/unit/tarball_spec.rb +0 -57
- data/spec/unit/util/attempt_spec.rb +0 -82
- data/spec/unit/util/cacheable_spec.rb +0 -23
- data/spec/unit/util/commands_spec.rb +0 -61
- data/spec/unit/util/downloader_spec.rb +0 -98
- data/spec/unit/util/exec_env_spec.rb +0 -56
- data/spec/unit/util/purgeable_spec.rb +0 -267
- data/spec/unit/util/setopts_spec.rb +0 -83
- data/spec/unit/util/subprocess/result_spec.rb +0 -36
- data/spec/unit/util/subprocess/runner/posix_spec.rb +0 -7
- data/spec/unit/util/subprocess/runner/pump_spec.rb +0 -79
- data/spec/unit/util/subprocess/runner/windows_spec.rb +0 -7
- data/spec/unit/util/subprocess/subprocess_error_spec.rb +0 -26
- data/spec/unit/util/subprocess_spec.rb +0 -65
- data/spec/unit/util/symbolize_keys_spec.rb +0 -67
@@ -1,421 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'r10k/module_loader/puppetfile'
|
3
|
-
require 'tmpdir'
|
4
|
-
|
5
|
-
describe R10K::ModuleLoader::Puppetfile do
|
6
|
-
describe 'initial parameters' do
|
7
|
-
describe 'honor' do
|
8
|
-
let(:options) do
|
9
|
-
{
|
10
|
-
basedir: '/test/basedir/env',
|
11
|
-
overrides: { modules: { deploy_modules: true } },
|
12
|
-
environment: R10K::Environment::Git.new('env',
|
13
|
-
'/test/basedir/',
|
14
|
-
'env',
|
15
|
-
{ remote: 'https://foo/remote',
|
16
|
-
ref: 'env' })
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
subject { R10K::ModuleLoader::Puppetfile.new(**options) }
|
21
|
-
|
22
|
-
describe 'the moduledir' do
|
23
|
-
it 'respects absolute paths' do
|
24
|
-
absolute_options = options.merge({moduledir: '/opt/puppetlabs/special/modules'})
|
25
|
-
puppetfile = R10K::ModuleLoader::Puppetfile.new(**absolute_options)
|
26
|
-
expect(puppetfile.instance_variable_get(:@moduledir)).to eq('/opt/puppetlabs/special/modules')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'roots the moduledir in the basepath if a relative path is specified' do
|
30
|
-
relative_options = options.merge({moduledir: 'my/special/modules'})
|
31
|
-
puppetfile = R10K::ModuleLoader::Puppetfile.new(**relative_options)
|
32
|
-
expect(puppetfile.instance_variable_get(:@moduledir)).to eq('/test/basedir/env/my/special/modules')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe 'the Puppetfile' do
|
37
|
-
it 'respects absolute paths' do
|
38
|
-
absolute_options = options.merge({puppetfile: '/opt/puppetlabs/special/Puppetfile'})
|
39
|
-
puppetfile = R10K::ModuleLoader::Puppetfile.new(**absolute_options)
|
40
|
-
expect(puppetfile.instance_variable_get(:@puppetfile_path)).to eq('/opt/puppetlabs/special/Puppetfile')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'roots the Puppetfile in the basepath if a relative path is specified' do
|
44
|
-
relative_options = options.merge({puppetfile: 'Puppetfile.global'})
|
45
|
-
puppetfile = R10K::ModuleLoader::Puppetfile.new(**relative_options)
|
46
|
-
expect(puppetfile.instance_variable_get(:@puppetfile_path)).to eq('/test/basedir/env/Puppetfile.global')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'the overrides' do
|
51
|
-
expect(subject.instance_variable_get(:@overrides)).to eq({ modules: { deploy_modules: true }})
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'the environment' do
|
55
|
-
expect(subject.instance_variable_get(:@environment).name).to eq('env')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'sane defaults' do
|
60
|
-
subject { R10K::ModuleLoader::Puppetfile.new(basedir: '/test/basedir') }
|
61
|
-
|
62
|
-
it 'has a moduledir rooted in the basedir' do
|
63
|
-
expect(subject.instance_variable_get(:@moduledir)).to eq('/test/basedir/modules')
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'has a Puppetfile rooted in the basedir' do
|
67
|
-
expect(subject.instance_variable_get(:@puppetfile_path)).to eq('/test/basedir/Puppetfile')
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'creates an empty overrides' do
|
71
|
-
expect(subject.instance_variable_get(:@overrides)).to eq({})
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'does not require an environment' do
|
75
|
-
expect(subject.instance_variable_get(:@environment)).to eq(nil)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'adding modules' do
|
81
|
-
let(:basedir) { '/test/basedir' }
|
82
|
-
|
83
|
-
subject { R10K::ModuleLoader::Puppetfile.new(basedir: basedir,
|
84
|
-
overrides: {modules: {exclude_spec: true}}) }
|
85
|
-
|
86
|
-
it 'should transform Forge modules with a string arg to have a version key' do
|
87
|
-
expect(R10K::Module).to receive(:from_metadata).with('puppet/test_module', subject.moduledir, hash_including(version: '1.2.3'), anything).and_call_original
|
88
|
-
|
89
|
-
expect { subject.add_module('puppet/test_module', '1.2.3') }.to change { subject.modules }
|
90
|
-
expect(subject.modules.collect(&:name)).to include('test_module')
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should not accept Forge modules with a version comparison' do
|
94
|
-
expect(R10K::Module).to receive(:from_metadata).with('puppet/test_module', subject.moduledir, hash_including(version: '< 1.2.0'), anything).and_call_original
|
95
|
-
|
96
|
-
expect {
|
97
|
-
subject.add_module('puppet/test_module', '< 1.2.0')
|
98
|
-
}.to raise_error(ArgumentError, /module version .* is not a valid forge module version/i)
|
99
|
-
|
100
|
-
expect(subject.modules.collect(&:name)).not_to include('test_module')
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should not modify the overrides when adding modules' do
|
104
|
-
module_opts = { git: 'git@example.com:puppet/test_module.git' }
|
105
|
-
subject.add_module('puppet/test_module', module_opts)
|
106
|
-
expect(subject.instance_variable_get("@overrides")[:modules]).to eq({exclude_spec: true})
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should read the `exclude_spec` setting in the module definition and override the overrides' do
|
110
|
-
module_opts = { git: 'git@example.com:puppet/test_module.git', exclude_spec: false }
|
111
|
-
subject.add_module('puppet/test_module', module_opts)
|
112
|
-
expect(subject.modules[0].instance_variable_get("@exclude_spec")).to be false
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'should set :spec_deletable to true for modules in the basedir' do
|
116
|
-
module_opts = { git: 'git@example.com:puppet/test_module.git' }
|
117
|
-
subject.add_module('puppet/test_module', module_opts)
|
118
|
-
expect(subject.modules[0].spec_deletable).to be true
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should set :spec_deletable to false for modules outside the basedir' do
|
122
|
-
module_opts = { git: 'git@example.com:puppet/test_module.git', install_path: 'some/path' }
|
123
|
-
subject.add_module('puppet/test_module', module_opts)
|
124
|
-
expect(subject.modules[0].spec_deletable).to be false
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'should accept non-Forge modules with a hash arg' do
|
128
|
-
module_opts = { git: 'git@example.com:puppet/test_module.git' }
|
129
|
-
|
130
|
-
expect(R10K::Module).to receive(:from_metadata).with('puppet/test_module', subject.moduledir, module_opts, anything).and_call_original
|
131
|
-
|
132
|
-
expect { subject.add_module('puppet/test_module', module_opts) }.to change { subject.modules }
|
133
|
-
expect(subject.modules.collect(&:name)).to include('test_module')
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'should accept non-Forge modules with a valid relative :install_path option' do
|
137
|
-
module_opts = {
|
138
|
-
install_path: 'vendor',
|
139
|
-
git: 'git@example.com:puppet/test_module.git',
|
140
|
-
}
|
141
|
-
|
142
|
-
expect(R10K::Module).to receive(:from_metadata).with('puppet/test_module', File.join(basedir, 'vendor'), module_opts, anything).and_call_original
|
143
|
-
|
144
|
-
expect { subject.add_module('puppet/test_module', module_opts) }.to change { subject.modules }
|
145
|
-
expect(subject.modules.collect(&:name)).to include('test_module')
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should accept non-Forge modules with a valid absolute :install_path option' do
|
149
|
-
install_path = File.join(basedir, 'vendor')
|
150
|
-
|
151
|
-
module_opts = {
|
152
|
-
install_path: install_path,
|
153
|
-
git: 'git@example.com:puppet/test_module.git',
|
154
|
-
}
|
155
|
-
|
156
|
-
expect(R10K::Module).to receive(:from_metadata).with('puppet/test_module', install_path, module_opts, anything).and_call_original
|
157
|
-
|
158
|
-
expect { subject.add_module('puppet/test_module', module_opts) }.to change { subject.modules }
|
159
|
-
expect(subject.modules.collect(&:name)).to include('test_module')
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should reject non-Forge modules with an invalid relative :install_path option' do
|
163
|
-
module_opts = {
|
164
|
-
install_path: '../../vendor',
|
165
|
-
git: 'git@example.com:puppet/test_module.git',
|
166
|
-
}
|
167
|
-
|
168
|
-
expect { subject.add_module('puppet/test_module', module_opts) }.to raise_error(R10K::Error, /cannot manage content.*is not within/i).and not_change { subject.modules }
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'should reject non-Forge modules with an invalid absolute :install_path option' do
|
172
|
-
module_opts = {
|
173
|
-
install_path: '/tmp/mydata/vendor',
|
174
|
-
git: 'git@example.com:puppet/test_module.git',
|
175
|
-
}
|
176
|
-
|
177
|
-
expect { subject.add_module('puppet/test_module', module_opts) }.to raise_error(R10K::Error, /cannot manage content.*is not within/i).and not_change { subject.modules }
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'should disable and not add modules that conflict with the environment' do
|
181
|
-
env = instance_double('R10K::Environment::Base')
|
182
|
-
mod = instance_double('R10K::Module::Base', name: 'conflict', origin: :puppetfile, 'origin=': nil)
|
183
|
-
allow(env).to receive(:name).and_return('conflict')
|
184
|
-
loader = R10K::ModuleLoader::Puppetfile.new(basedir: basedir, environment: env)
|
185
|
-
allow(env).to receive(:'module_conflicts?').with(mod).and_return(true)
|
186
|
-
allow(mod).to receive(:spec_deletable=)
|
187
|
-
|
188
|
-
expect(R10K::Module).to receive(:from_metadata).with('conflict', anything, anything, anything).and_return(mod)
|
189
|
-
expect { loader.add_module('conflict', {}) }.not_to change { loader.modules }
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe '#purge_exclusions' do
|
194
|
-
let(:managed_dirs) { ['dir1', 'dir2'] }
|
195
|
-
subject { R10K::ModuleLoader::Puppetfile.new(basedir: '/test/basedir') }
|
196
|
-
|
197
|
-
it 'includes managed_directories' do
|
198
|
-
expect(subject.send(:determine_purge_exclusions, managed_dirs)).to match_array(managed_dirs)
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'when belonging to an environment' do
|
202
|
-
let(:env_contents) { ['env1', 'env2' ] }
|
203
|
-
let(:env) { double(:environment, desired_contents: env_contents) }
|
204
|
-
before {
|
205
|
-
allow(env).to receive(:name).and_return('env1')
|
206
|
-
}
|
207
|
-
subject { R10K::ModuleLoader::Puppetfile.new(basedir: '/test/basedir', environment: env) }
|
208
|
-
|
209
|
-
it "includes environment's desired_contents" do
|
210
|
-
expect(subject.send(:determine_purge_exclusions, managed_dirs)).to match_array(managed_dirs + env_contents)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe '#managed_directories' do
|
216
|
-
|
217
|
-
let(:basedir) { '/test/basedir' }
|
218
|
-
subject { R10K::ModuleLoader::Puppetfile.new(basedir: basedir) }
|
219
|
-
|
220
|
-
before do
|
221
|
-
allow(subject).to receive(:puppetfile_content).and_return('')
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'returns an array of paths that #purge! will operate within' do
|
225
|
-
expect(R10K::Module).to receive(:from_metadata).with('puppet/test_module', subject.moduledir, hash_including(version: '1.2.3'), anything).and_call_original
|
226
|
-
subject.add_module('puppet/test_module', '1.2.3')
|
227
|
-
subject.load!
|
228
|
-
|
229
|
-
expect(subject.modules.length).to be 1
|
230
|
-
expect(subject.managed_directories).to match_array([subject.moduledir])
|
231
|
-
end
|
232
|
-
|
233
|
-
context "with a module with install_path == ''" do
|
234
|
-
it "basedir isn't in the list of paths to purge" do
|
235
|
-
module_opts = { install_path: '', git: 'git@example.com:puppet/test_module.git' }
|
236
|
-
|
237
|
-
expect(R10K::Module).to receive(:from_metadata).with('puppet/test_module', basedir, module_opts, anything).and_call_original
|
238
|
-
subject.add_module('puppet/test_module', module_opts)
|
239
|
-
subject.load!
|
240
|
-
|
241
|
-
expect(subject.modules.length).to be 1
|
242
|
-
expect(subject.managed_directories).to be_empty
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
describe 'evaluating a Puppetfile' do
|
248
|
-
def expect_wrapped_error(error, pf_path, error_type)
|
249
|
-
expect(error).to be_a_kind_of(R10K::Error)
|
250
|
-
expect(error.message).to eq("Failed to evaluate #{pf_path}")
|
251
|
-
expect(error.original).to be_a_kind_of(error_type)
|
252
|
-
end
|
253
|
-
|
254
|
-
subject { described_class.new(basedir: @path) }
|
255
|
-
|
256
|
-
it 'wraps and re-raises syntax errors' do
|
257
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'invalid-syntax')
|
258
|
-
pf_path = File.join(@path, 'Puppetfile')
|
259
|
-
expect {
|
260
|
-
subject.load!
|
261
|
-
}.to raise_error do |e|
|
262
|
-
expect_wrapped_error(e, pf_path, SyntaxError)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'wraps and re-raises load errors' do
|
267
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'load-error')
|
268
|
-
pf_path = File.join(@path, 'Puppetfile')
|
269
|
-
expect {
|
270
|
-
subject.load!
|
271
|
-
}.to raise_error do |e|
|
272
|
-
expect_wrapped_error(e, pf_path, LoadError)
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'wraps and re-raises argument errors' do
|
277
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'argument-error')
|
278
|
-
pf_path = File.join(@path, 'Puppetfile')
|
279
|
-
expect {
|
280
|
-
subject.load!
|
281
|
-
}.to raise_error do |e|
|
282
|
-
expect_wrapped_error(e, pf_path, ArgumentError)
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
describe 'forge declaration' do
|
287
|
-
before(:each) do
|
288
|
-
PuppetForge.host = ""
|
289
|
-
end
|
290
|
-
|
291
|
-
it 'is respected if `allow_puppetfile_override` is true' do
|
292
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'forge-override')
|
293
|
-
puppetfile = R10K::ModuleLoader::Puppetfile.new(basedir: @path, overrides: { forge: { allow_puppetfile_override: true } })
|
294
|
-
puppetfile.load!
|
295
|
-
expect(PuppetForge.host).to eq("my.custom.forge.com/")
|
296
|
-
end
|
297
|
-
|
298
|
-
it 'is ignored if `allow_puppetfile_override` is false' do
|
299
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'forge-override')
|
300
|
-
puppetfile = R10K::ModuleLoader::Puppetfile.new(basedir: @path, overrides: { forge: { allow_puppetfile_override: false } })
|
301
|
-
expect(PuppetForge).not_to receive(:host=).with("my.custom.forge.com")
|
302
|
-
puppetfile.load!
|
303
|
-
expect(PuppetForge.host).to eq("/")
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'rejects Puppetfiles with duplicate module names' do
|
308
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'duplicate-module-error')
|
309
|
-
pf_path = File.join(@path, 'Puppetfile')
|
310
|
-
expect {
|
311
|
-
subject.load!
|
312
|
-
}.to raise_error(R10K::Error, /Puppetfiles cannot contain duplicate module names/i)
|
313
|
-
end
|
314
|
-
|
315
|
-
it 'wraps and re-raises name errors' do
|
316
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'name-error')
|
317
|
-
pf_path = File.join(@path, 'Puppetfile')
|
318
|
-
expect {
|
319
|
-
subject.load!
|
320
|
-
}.to raise_error do |e|
|
321
|
-
expect_wrapped_error(e, pf_path, NameError)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
it 'accepts a forge module with a version' do
|
326
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
|
327
|
-
pf_path = File.join(@path, 'Puppetfile')
|
328
|
-
expect { subject.load! }.not_to raise_error
|
329
|
-
end
|
330
|
-
|
331
|
-
describe 'setting a custom moduledir' do
|
332
|
-
it 'allows setting an absolute moduledir' do
|
333
|
-
@path = '/fake/basedir'
|
334
|
-
allow(subject).to receive(:puppetfile_content).and_return('moduledir "/fake/moduledir"')
|
335
|
-
subject.load!
|
336
|
-
expect(subject.instance_variable_get(:@moduledir)).to eq('/fake/moduledir')
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'roots relative moduledirs in the basedir' do
|
340
|
-
@path = '/fake/basedir'
|
341
|
-
allow(subject).to receive(:puppetfile_content).and_return('moduledir "my/moduledir"')
|
342
|
-
subject.load!
|
343
|
-
expect(subject.instance_variable_get(:@moduledir)).to eq(File.join(@path, 'my/moduledir'))
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
it 'accepts a forge module without a version' do
|
348
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-without-version')
|
349
|
-
pf_path = File.join(@path, 'Puppetfile')
|
350
|
-
expect { subject.load! }.not_to raise_error
|
351
|
-
end
|
352
|
-
|
353
|
-
it 'creates a git module and applies the default branch specified in the Puppetfile' do
|
354
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
|
355
|
-
pf_path = File.join(@path, 'Puppetfile')
|
356
|
-
expect { subject.load! }.not_to raise_error
|
357
|
-
git_module = subject.modules[0]
|
358
|
-
expect(git_module.default_ref).to eq 'here_lies_the_default_branch'
|
359
|
-
end
|
360
|
-
|
361
|
-
it 'creates a git module and applies the provided default_branch_override' do
|
362
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
|
363
|
-
pf_path = File.join(@path, 'Puppetfile')
|
364
|
-
default_branch_override = 'default_branch_override_name'
|
365
|
-
subject.default_branch_override = default_branch_override
|
366
|
-
expect { subject.load! }.not_to raise_error
|
367
|
-
git_module = subject.modules[0]
|
368
|
-
expect(git_module.default_override_ref).to eq default_branch_override
|
369
|
-
expect(git_module.default_ref).to eq 'here_lies_the_default_branch'
|
370
|
-
end
|
371
|
-
|
372
|
-
describe 'using module metadata' do
|
373
|
-
it 'properly loads module metadata' do
|
374
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'various-modules')
|
375
|
-
metadata = subject.load_metadata[:modules].map { |mod| [ mod.name, mod.version ] }.to_h
|
376
|
-
expect(metadata['apt']).to eq('2.1.1')
|
377
|
-
expect(metadata['stdlib']).to eq(nil)
|
378
|
-
expect(metadata['concat']).to eq(nil)
|
379
|
-
expect(metadata['rpm']).to eq('2.1.1-pre1')
|
380
|
-
expect(metadata['foo']).to eq(nil)
|
381
|
-
expect(metadata['bar']).to eq('v1.2.3')
|
382
|
-
expect(metadata['baz']).to eq('123abc456')
|
383
|
-
expect(metadata['fizz']).to eq('1234567890abcdef1234567890abcdef12345678')
|
384
|
-
expect(metadata['buzz']).to eq(nil)
|
385
|
-
expect(metadata['canary']).to eq('0.0.0')
|
386
|
-
end
|
387
|
-
|
388
|
-
it 'does not load module implementations for static versions unless the module install path does not exist on disk' do
|
389
|
-
@path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'various-modules')
|
390
|
-
subject.load_metadata
|
391
|
-
modules = subject.load[:modules].map { |mod| [ mod.name, mod ] }.to_h
|
392
|
-
expect(modules['apt']).to be_a_kind_of(R10K::Module::Definition)
|
393
|
-
expect(modules['stdlib']).to be_a_kind_of(R10K::Module::Forge)
|
394
|
-
expect(modules['concat']).to be_a_kind_of(R10K::Module::Forge)
|
395
|
-
expect(modules['rpm']).to be_a_kind_of(R10K::Module::Definition)
|
396
|
-
expect(modules['foo']).to be_a_kind_of(R10K::Module::Git)
|
397
|
-
expect(modules['bar']).to be_a_kind_of(R10K::Module::Git)
|
398
|
-
expect(modules['baz']).to be_a_kind_of(R10K::Module::Definition)
|
399
|
-
expect(modules['fizz']).to be_a_kind_of(R10K::Module::Definition)
|
400
|
-
expect(modules['buzz']).to be_a_kind_of(R10K::Module::Git)
|
401
|
-
expect(modules['canary']).to be_a_kind_of(R10K::Module::Definition)
|
402
|
-
end
|
403
|
-
|
404
|
-
it 'loads module implementations whose static versions are different' do
|
405
|
-
fixture_path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'various-modules')
|
406
|
-
@path = Dir.mktmpdir
|
407
|
-
unsynced_pf_path = File.join(fixture_path, 'Puppetfile')
|
408
|
-
FileUtils.cp(unsynced_pf_path, @path)
|
409
|
-
|
410
|
-
subject.load_metadata
|
411
|
-
|
412
|
-
synced_pf_path = File.join(fixture_path, 'Puppetfile.new')
|
413
|
-
FileUtils.cp(synced_pf_path, File.join(@path, 'Puppetfile'))
|
414
|
-
|
415
|
-
modules = subject.load[:modules].map { |mod| [ mod.name, mod ] }.to_h
|
416
|
-
|
417
|
-
expect(modules['apt']).to be_a_kind_of(R10K::Module::Forge)
|
418
|
-
end
|
419
|
-
end
|
420
|
-
end
|
421
|
-
end
|
data/spec/unit/module_spec.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'r10k/module'
|
3
|
-
|
4
|
-
describe R10K::Module do
|
5
|
-
describe 'delegating to R10K::Module::Git' do
|
6
|
-
[ {git: 'git url'},
|
7
|
-
{type: 'git', source: 'git url'},
|
8
|
-
].each do |scenario|
|
9
|
-
it "accepts a name matching 'test' and args #{scenario.inspect}" do
|
10
|
-
obj = R10K::Module.new('test', '/modulepath', scenario)
|
11
|
-
expect(obj).to be_a_kind_of(R10K::Module::Git)
|
12
|
-
expect(obj.send(:instance_variable_get, :'@remote')).to eq('git url')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'delegating to R10K::Module::Svn' do
|
18
|
-
[ {svn: 'svn url'},
|
19
|
-
{type: 'svn', source: 'svn url'},
|
20
|
-
].each do |scenario|
|
21
|
-
it "accepts a name matching 'test' and args #{scenario.inspect}" do
|
22
|
-
obj = R10K::Module.new('test', '/modulepath', scenario)
|
23
|
-
expect(obj).to be_a_kind_of(R10K::Module::SVN)
|
24
|
-
expect(obj.send(:instance_variable_get, :'@url')).to eq('svn url')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'delegating to R10K::Module::Forge' do
|
30
|
-
[ 'bar/quux',
|
31
|
-
'bar-quux',
|
32
|
-
].each do |scenario|
|
33
|
-
it "accepts a name matching #{scenario} and version nil" do
|
34
|
-
obj = R10K::Module.new(scenario, '/modulepath', { type: 'forge', version: nil })
|
35
|
-
expect(obj).to be_a_kind_of(R10K::Module::Forge)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
[ {type: 'forge', version: '8.0.0'},
|
39
|
-
].each do |scenario|
|
40
|
-
it "accepts a name matching bar-quux and args #{scenario.inspect}" do
|
41
|
-
obj = R10K::Module.new('bar-quux', '/modulepath', scenario)
|
42
|
-
expect(obj).to be_a_kind_of(R10K::Module::Forge)
|
43
|
-
expect(obj.send(:instance_variable_get, :'@expected_version')).to eq('8.0.0')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'when the module is ostensibly on disk' do
|
48
|
-
before do
|
49
|
-
owner = 'theowner'
|
50
|
-
module_name = 'themodulename'
|
51
|
-
@title = "#{owner}-#{module_name}"
|
52
|
-
metadata = <<~METADATA
|
53
|
-
{
|
54
|
-
"name": "#{@title}",
|
55
|
-
"version": "1.2.0"
|
56
|
-
}
|
57
|
-
METADATA
|
58
|
-
@dirname = Dir.mktmpdir
|
59
|
-
module_path = File.join(@dirname, module_name)
|
60
|
-
FileUtils.mkdir(module_path)
|
61
|
-
File.open("#{module_path}/metadata.json", 'w') do |file|
|
62
|
-
file.write(metadata)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'sets the expected version to what is found in the metadata' do
|
67
|
-
obj = R10K::Module.new(@title, @dirname, {type: 'forge', version: nil})
|
68
|
-
expect(obj.send(:instance_variable_get, :'@expected_version')).to eq('1.2.0')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it "raises an error if delegation fails" do
|
74
|
-
expect {
|
75
|
-
R10K::Module.new('bar!quux', '/modulepath', {version: ["NOPE NOPE NOPE NOPE!"]})
|
76
|
-
}.to raise_error RuntimeError, /doesn't have an implementation/
|
77
|
-
end
|
78
|
-
|
79
|
-
describe 'Given a set of initialization parameters for R10K::Module' do
|
80
|
-
[ ['name', {git: 'git url'}],
|
81
|
-
['name', {type: 'git', source: 'git url'}],
|
82
|
-
['name', {svn: 'svn url'}],
|
83
|
-
['name', {type: 'svn', source: 'svn url'}],
|
84
|
-
['namespace-name', {type: 'forge', version: '8.0.0'}]
|
85
|
-
].each do |(name, options)|
|
86
|
-
it 'can handle the default_branch_override option' do
|
87
|
-
expect {
|
88
|
-
obj = R10K::Module.new(name, '/modulepath', options.merge({default_branch_override: 'foo'}))
|
89
|
-
expect(obj).to be_a_kind_of(R10K::Module::Base)
|
90
|
-
}.not_to raise_error
|
91
|
-
end
|
92
|
-
describe 'the exclude_spec setting' do
|
93
|
-
it 'sets the exclude_spec instance variable to false by default' do
|
94
|
-
obj = R10K::Module.new(name, '/modulepath', options)
|
95
|
-
expect(obj.instance_variable_get("@exclude_spec")).to eq(false)
|
96
|
-
end
|
97
|
-
it 'sets the exclude_spec instance variable' do
|
98
|
-
obj = R10K::Module.new(name, '/modulepath', options.merge({exclude_spec: true}))
|
99
|
-
expect(obj.instance_variable_get("@exclude_spec")).to eq(true)
|
100
|
-
end
|
101
|
-
it 'cannot be overridden by the settings from the cli, r10k.yaml, or settings default' do
|
102
|
-
options = options.merge({exclude_spec: true, overrides: {modules: {exclude_spec: false}}})
|
103
|
-
obj = R10K::Module.new(name, '/modulepath', options)
|
104
|
-
expect(obj.instance_variable_get("@exclude_spec")).to eq(true)
|
105
|
-
end
|
106
|
-
it 'reads the setting from the cli, r10k.yaml, or settings default when not provided directly' do
|
107
|
-
options = options.merge({overrides: {modules: {exclude_spec: true}}})
|
108
|
-
obj = R10K::Module.new(name, '/modulepath', options)
|
109
|
-
expect(obj.instance_variable_get("@exclude_spec")).to eq(true)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|