r10k 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.mkd +40 -13
- data/Gemfile +1 -2
- data/README.mkd +25 -0
- data/Rakefile +3 -0
- data/doc/dynamic-environments/configuration.mkd +91 -14
- data/doc/dynamic-environments/workflow-guide.mkd +3 -3
- data/doc/puppetfile.mkd +89 -40
- data/integration/Gemfile +2 -0
- data/integration/Rakefile +41 -0
- data/integration/tests/purging/content_not_purged_at_root.rb +89 -0
- data/integration/tests/purging/default_purging.rb +125 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +1 -1
- data/lib/r10k.rb +8 -1
- data/lib/r10k/action/deploy/deploy_helpers.rb +3 -3
- data/lib/r10k/action/deploy/environment.rb +35 -14
- data/lib/r10k/action/deploy/module.rb +4 -4
- data/lib/r10k/action/puppetfile/check.rb +1 -1
- data/lib/r10k/action/puppetfile/install.rb +1 -1
- data/lib/r10k/action/runner.rb +3 -3
- data/lib/r10k/deployment.rb +8 -4
- data/lib/r10k/deployment/config.rb +1 -1
- data/lib/r10k/environment/base.rb +32 -3
- data/lib/r10k/environment/git.rb +19 -6
- data/lib/r10k/feature.rb +6 -6
- data/lib/r10k/forge/module_release.rb +4 -6
- data/lib/r10k/git.rb +7 -7
- data/lib/r10k/git/alternates.rb +1 -1
- data/lib/r10k/git/cache.rb +2 -2
- data/lib/r10k/git/rugged/bare_repository.rb +29 -9
- data/lib/r10k/git/rugged/credentials.rb +8 -8
- data/lib/r10k/git/rugged/thin_repository.rb +17 -3
- data/lib/r10k/git/rugged/working_repository.rb +12 -5
- data/lib/r10k/git/shellgit/thin_repository.rb +5 -1
- data/lib/r10k/git/shellgit/working_repository.rb +16 -2
- data/lib/r10k/git/stateful_repository.rb +33 -23
- data/lib/r10k/initializers.rb +1 -1
- data/lib/r10k/keyed_factory.rb +2 -2
- data/lib/r10k/logging.rb +1 -1
- data/lib/r10k/module.rb +4 -3
- data/lib/r10k/module/base.rb +3 -2
- data/lib/r10k/module/forge.rb +9 -4
- data/lib/r10k/module/git.rb +39 -22
- data/lib/r10k/module/local.rb +1 -1
- data/lib/r10k/module/metadata_file.rb +1 -1
- data/lib/r10k/module/svn.rb +3 -1
- data/lib/r10k/puppetfile.rb +72 -11
- data/lib/r10k/settings.rb +20 -0
- data/lib/r10k/settings/collection.rb +2 -2
- data/lib/r10k/settings/container.rb +1 -1
- data/lib/r10k/settings/enum_definition.rb +11 -3
- data/lib/r10k/settings/helpers.rb +2 -2
- data/lib/r10k/settings/list.rb +1 -1
- data/lib/r10k/settings/loader.rb +6 -6
- data/lib/r10k/settings/uri_definition.rb +1 -1
- data/lib/r10k/source/base.rb +2 -2
- data/lib/r10k/source/git.rb +4 -4
- data/lib/r10k/svn/working_dir.rb +1 -1
- data/lib/r10k/util/basedir.rb +9 -9
- data/lib/r10k/util/license.rb +3 -3
- data/lib/r10k/util/purgeable.rb +50 -24
- data/lib/r10k/util/setopts.rb +1 -1
- data/lib/r10k/util/subprocess.rb +3 -3
- data/lib/r10k/util/symbolize_keys.rb +1 -1
- data/lib/r10k/version.rb +1 -1
- data/locales/config.yaml +21 -0
- data/r10k.gemspec +3 -0
- data/spec/fixtures/unit/puppetfile/valid-forge-with-version/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/valid-forge-without-version/Puppetfile +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/expected_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/unmanaged_1 +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/integration/git/stateful_repository_spec.rb +39 -21
- data/spec/r10k-mocks/mock_config.rb +4 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/action/deploy/environment_spec.rb +71 -13
- data/spec/unit/environment/base_spec.rb +71 -0
- data/spec/unit/forge/module_release_spec.rb +7 -10
- data/spec/unit/git/stateful_repository_spec.rb +6 -6
- data/spec/unit/module/git_spec.rb +156 -5
- data/spec/unit/module_spec.rb +3 -3
- data/spec/unit/puppetfile_spec.rb +115 -0
- data/spec/unit/util/purgeable_spec.rb +230 -0
- metadata +45 -18
- data/integration/test_run_scripts/README.mkd +0 -5
- data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +0 -20
- data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +0 -20
@@ -5,38 +5,38 @@ require 'r10k/git/stateful_repository'
|
|
5
5
|
describe R10K::Git::StatefulRepository do
|
6
6
|
|
7
7
|
let(:remote) { 'git://some.site/some-repo.git' }
|
8
|
+
let(:ref) { '0.9.x' }
|
8
9
|
|
9
|
-
subject { described_class.new(
|
10
|
+
subject { described_class.new(remote, '/some/nonexistent/basedir', 'some-dirname') }
|
10
11
|
|
11
12
|
describe "determining if the cache needs to be synced" do
|
12
|
-
|
13
13
|
let(:cache) { double('cache') }
|
14
14
|
|
15
15
|
before { expect(R10K::Git.cache).to receive(:generate).with(remote).and_return(cache) }
|
16
16
|
|
17
17
|
it "is true if the cache is absent" do
|
18
18
|
expect(cache).to receive(:exist?).and_return false
|
19
|
-
expect(subject.sync_cache?).to eq true
|
19
|
+
expect(subject.sync_cache?(ref)).to eq true
|
20
20
|
end
|
21
21
|
|
22
22
|
it "is true if the ref is unresolvable" do
|
23
23
|
expect(cache).to receive(:exist?).and_return true
|
24
24
|
expect(cache).to receive(:resolve).with('0.9.x')
|
25
|
-
expect(subject.sync_cache?).to eq true
|
25
|
+
expect(subject.sync_cache?(ref)).to eq true
|
26
26
|
end
|
27
27
|
|
28
28
|
it "is true if the ref is not a tag or commit" do
|
29
29
|
expect(cache).to receive(:exist?).and_return true
|
30
30
|
expect(cache).to receive(:resolve).with('0.9.x').and_return('93456ec7dc0f6fd3ac193b4df64f6544615dfbc9')
|
31
31
|
expect(cache).to receive(:ref_type).with('0.9.x').and_return(:branch)
|
32
|
-
expect(subject.sync_cache?).to eq true
|
32
|
+
expect(subject.sync_cache?(ref)).to eq true
|
33
33
|
end
|
34
34
|
|
35
35
|
it "is false otherwise" do
|
36
36
|
expect(cache).to receive(:exist?).and_return true
|
37
37
|
expect(cache).to receive(:resolve).with('0.9.x').and_return('93456ec7dc0f6fd3ac193b4df64f6544615dfbc9')
|
38
38
|
expect(cache).to receive(:ref_type).with('0.9.x').and_return(:tag)
|
39
|
-
expect(subject.sync_cache?).to eq false
|
39
|
+
expect(subject.sync_cache?(ref)).to eq false
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -2,6 +2,13 @@ require 'spec_helper'
|
|
2
2
|
require 'r10k/module/git'
|
3
3
|
|
4
4
|
describe R10K::Module::Git do
|
5
|
+
let(:mock_repo) do
|
6
|
+
instance_double("R10K::Git::StatefulRepository")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
allow(R10K::Git::StatefulRepository).to receive(:new).and_return(mock_repo)
|
11
|
+
end
|
5
12
|
|
6
13
|
describe "setting the owner and name" do
|
7
14
|
describe "with a title of 'branan/eight_hundred'" do
|
@@ -55,7 +62,12 @@ describe R10K::Module::Git do
|
|
55
62
|
|
56
63
|
describe "properties" do
|
57
64
|
subject do
|
58
|
-
described_class.new('boolean', '/moduledir', {:git => 'git://
|
65
|
+
described_class.new('boolean', '/moduledir', {:git => 'git://git.example.com/adrienthebo/puppet-boolean'})
|
66
|
+
end
|
67
|
+
|
68
|
+
before(:each) do
|
69
|
+
allow(mock_repo).to receive(:resolve).with('master').and_return('abc123')
|
70
|
+
allow(mock_repo).to receive(:head).and_return('abc123')
|
59
71
|
end
|
60
72
|
|
61
73
|
it "sets the module type to :git" do
|
@@ -67,12 +79,12 @@ describe R10K::Module::Git do
|
|
67
79
|
end
|
68
80
|
|
69
81
|
it "sets the actual version to the revision when the revision is available" do
|
70
|
-
expect(
|
82
|
+
expect(mock_repo).to receive(:head).and_return('35d3517e67ceeb4b485b56d4a14d38fb95516c92')
|
71
83
|
expect(subject.properties).to include(:actual => '35d3517e67ceeb4b485b56d4a14d38fb95516c92')
|
72
84
|
end
|
73
85
|
|
74
86
|
it "sets the actual version to (unresolvable) when the revision is unavailable" do
|
75
|
-
expect(
|
87
|
+
expect(mock_repo).to receive(:head).and_return(nil)
|
76
88
|
expect(subject.properties).to include(:actual => '(unresolvable)')
|
77
89
|
end
|
78
90
|
end
|
@@ -83,14 +95,153 @@ describe R10K::Module::Git do
|
|
83
95
|
'boolean',
|
84
96
|
'/moduledir',
|
85
97
|
{
|
86
|
-
:git => 'git://
|
98
|
+
:git => 'git://git.example.com/adrienthebo/puppet-boolean'
|
87
99
|
}
|
88
100
|
)
|
89
101
|
end
|
90
102
|
|
91
103
|
it "delegates to the repo" do
|
92
|
-
expect(subject
|
104
|
+
expect(subject).to receive(:version).and_return 'master'
|
105
|
+
expect(mock_repo).to receive(:status).with('master').and_return :some_status
|
106
|
+
|
93
107
|
expect(subject.status).to eq(:some_status)
|
94
108
|
end
|
95
109
|
end
|
110
|
+
|
111
|
+
describe "option parsing" do
|
112
|
+
def test_module(extra_opts, env=nil)
|
113
|
+
described_class.new('boolean', '/moduledir', base_opts.merge(extra_opts), env)
|
114
|
+
end
|
115
|
+
|
116
|
+
let(:base_opts) { { git: 'git://git.example.com/adrienthebo/puppet-boolean' } }
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
allow(mock_repo).to receive(:head).and_return('abc123')
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when option is unrecognized" do
|
123
|
+
let(:opts) { { unrecognized: true } }
|
124
|
+
|
125
|
+
it "raises an error" do
|
126
|
+
expect { test_module(opts) }.to raise_error(ArgumentError, /unhandled options.*unrecognized/i)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "desired ref" do
|
131
|
+
context "when no desired ref is given" do
|
132
|
+
it "defaults to master" do
|
133
|
+
expect(mock_repo).to receive(:resolve).with('master').and_return('abc123')
|
134
|
+
|
135
|
+
expect(test_module({}).properties).to include(expected: 'master')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "specifying a static desired branch" do
|
140
|
+
let(:opts) { { branch: 'banana' } }
|
141
|
+
|
142
|
+
it "sets expected to specified branch name" do
|
143
|
+
expect(mock_repo).to receive(:resolve).with('banana').and_return('def456')
|
144
|
+
|
145
|
+
mod = test_module(opts)
|
146
|
+
expect(mod.properties).to include(expected: 'banana')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "specifying a static desired tag" do
|
151
|
+
let(:opts) { { tag: '1.2.3' } }
|
152
|
+
|
153
|
+
it "sets expected to specified tag" do
|
154
|
+
expect(mock_repo).to receive(:resolve).with('1.2.3').and_return('def456')
|
155
|
+
|
156
|
+
mod = test_module(opts)
|
157
|
+
expect(mod.properties).to include(expected: '1.2.3')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "specifying a static desired commit sha" do
|
162
|
+
let(:opts) { { commit: 'ace789' } }
|
163
|
+
|
164
|
+
it "sets expected to specified commit sha" do
|
165
|
+
expect(mock_repo).to receive(:resolve).with('ace789').and_return('ace789')
|
166
|
+
|
167
|
+
mod = test_module(opts)
|
168
|
+
expect(mod.properties).to include(expected: 'ace789')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "specifying a static desired ref" do
|
173
|
+
before(:each) do
|
174
|
+
expect(mock_repo).to receive(:resolve).and_return('abc123')
|
175
|
+
end
|
176
|
+
|
177
|
+
it "accepts a branch name" do
|
178
|
+
mod = test_module(ref: 'banana')
|
179
|
+
expect(mod.properties).to include(expected: 'banana')
|
180
|
+
end
|
181
|
+
|
182
|
+
it "accepts a tag name" do
|
183
|
+
mod = test_module(ref: '1.2.3')
|
184
|
+
expect(mod.properties).to include(expected: '1.2.3')
|
185
|
+
end
|
186
|
+
|
187
|
+
it "accepts a commit sha" do
|
188
|
+
mod = test_module(ref: 'abc123')
|
189
|
+
expect(mod.properties).to include(expected: 'abc123')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context "specifying branch to :control_branch" do
|
194
|
+
let(:mock_env) { instance_double("R10K::Environment::Git", ref: 'env_branch') }
|
195
|
+
|
196
|
+
context "when module belongs to an environment and matching branch is resolvable" do
|
197
|
+
before(:each) do
|
198
|
+
expect(mock_repo).to receive(:resolve).with(mock_env.ref).and_return('abc123')
|
199
|
+
end
|
200
|
+
|
201
|
+
it "tracks environment branch" do
|
202
|
+
mod = test_module({branch: :control_branch}, mock_env)
|
203
|
+
expect(mod.properties).to include(expected: mock_env.ref)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "when module does not belong to an environment" do
|
208
|
+
it "raises appropriate error" do
|
209
|
+
expect { test_module(branch: :control_branch) }.to raise_error(ArgumentError, /cannot track control.*environment is nil/i)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "when module does not have matching branch" do
|
214
|
+
before(:each) do
|
215
|
+
allow(mock_repo).to receive(:resolve).with(mock_env.ref).and_return(nil)
|
216
|
+
end
|
217
|
+
|
218
|
+
context "when default ref is provided and resolvable" do
|
219
|
+
it "uses default ref" do
|
220
|
+
expect(mock_repo).to receive(:resolve).with('default').and_return('abc123')
|
221
|
+
mod = test_module({branch: :control_branch, default_branch: 'default'}, mock_env)
|
222
|
+
|
223
|
+
expect(mod.properties).to include(expected: 'default')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "when default ref is provided and not resolvable" do
|
228
|
+
it "raises appropriate error" do
|
229
|
+
expect(mock_repo).to receive(:resolve).with('default').and_return(nil)
|
230
|
+
mod = test_module({branch: :control_branch, default_branch: 'default'}, mock_env)
|
231
|
+
|
232
|
+
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*could not resolve desired.*or default/i)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "when default ref is not provided" do
|
237
|
+
it "raises appropriate error" do
|
238
|
+
mod = test_module({branch: :control_branch}, mock_env)
|
239
|
+
|
240
|
+
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*no default given/i)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
96
247
|
end
|
data/spec/unit/module_spec.rb
CHANGED
@@ -11,9 +11,9 @@ describe R10K::Module do
|
|
11
11
|
|
12
12
|
describe 'delegating to R10K::Module::Forge' do
|
13
13
|
[
|
14
|
-
['bar/quux',
|
15
|
-
['bar-quux',
|
16
|
-
['bar/quux',
|
14
|
+
['bar/quux', nil],
|
15
|
+
['bar-quux', nil],
|
16
|
+
['bar/quux', '8.0.0'],
|
17
17
|
].each do |scenario|
|
18
18
|
it "accepts a name matching #{scenario[0]} and args #{scenario[1].inspect}" do
|
19
19
|
expect(R10K::Module.new(scenario[0], '/modulepath', scenario[1])).to be_a_kind_of(R10K::Module::Forge)
|
@@ -27,6 +27,107 @@ describe R10K::Puppetfile do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
describe "adding modules" do
|
31
|
+
it "should accept Forge modules with a string arg" do
|
32
|
+
allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '1.2.3', anything).and_call_original
|
33
|
+
|
34
|
+
expect { subject.add_module('puppet/test_module', '1.2.3') }.to change { subject.modules }
|
35
|
+
expect(subject.modules.collect(&:name)).to include('test_module')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not accept Forge modules with a version comparison" do
|
39
|
+
allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '< 1.2.0', anything).and_call_original
|
40
|
+
|
41
|
+
expect {
|
42
|
+
subject.add_module('puppet/test_module', '< 1.2.0')
|
43
|
+
}.to raise_error(RuntimeError, /module puppet\/test_module.*doesn't have an implementation/i)
|
44
|
+
|
45
|
+
expect(subject.modules.collect(&:name)).not_to include('test_module')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should accept non-Forge modules with a hash arg" do
|
49
|
+
module_opts = { git: 'git@example.com:puppet/test_module.git' }
|
50
|
+
|
51
|
+
allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, module_opts, anything).and_call_original
|
52
|
+
|
53
|
+
expect { subject.add_module('puppet/test_module', module_opts) }.to change { subject.modules }
|
54
|
+
expect(subject.modules.collect(&:name)).to include('test_module')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should accept non-Forge modules with a valid relative :install_path option" do
|
58
|
+
module_opts = {
|
59
|
+
install_path: 'vendor',
|
60
|
+
git: 'git@example.com:puppet/test_module.git',
|
61
|
+
}
|
62
|
+
|
63
|
+
allow(R10K::Module).to receive(:new).with('puppet/test_module', File.join(subject.basedir, 'vendor'), module_opts, anything).and_call_original
|
64
|
+
|
65
|
+
expect { subject.add_module('puppet/test_module', module_opts) }.to change { subject.modules }
|
66
|
+
expect(subject.modules.collect(&:name)).to include('test_module')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should accept non-Forge modules with a valid absolute :install_path option" do
|
70
|
+
install_path = File.join(subject.basedir, 'vendor')
|
71
|
+
|
72
|
+
module_opts = {
|
73
|
+
install_path: install_path,
|
74
|
+
git: 'git@example.com:puppet/test_module.git',
|
75
|
+
}
|
76
|
+
|
77
|
+
allow(R10K::Module).to receive(:new).with('puppet/test_module', install_path, module_opts, anything).and_call_original
|
78
|
+
|
79
|
+
expect { subject.add_module('puppet/test_module', module_opts) }.to change { subject.modules }
|
80
|
+
expect(subject.modules.collect(&:name)).to include('test_module')
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should reject non-Forge modules with an invalid relative :install_path option" do
|
84
|
+
module_opts = {
|
85
|
+
install_path: '../../vendor',
|
86
|
+
git: 'git@example.com:puppet/test_module.git',
|
87
|
+
}
|
88
|
+
|
89
|
+
allow(R10K::Module).to receive(:new).with('puppet/test_module', File.join(subject.basedir, 'vendor'), module_opts, anything).and_call_original
|
90
|
+
|
91
|
+
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 }
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should reject non-Forge modules with an invalid absolute :install_path option" do
|
95
|
+
module_opts = {
|
96
|
+
install_path: '/tmp/mydata/vendor',
|
97
|
+
git: 'git@example.com:puppet/test_module.git',
|
98
|
+
}
|
99
|
+
|
100
|
+
allow(R10K::Module).to receive(:new).with('puppet/test_module', File.join(subject.basedir, 'vendor'), module_opts, anything).and_call_original
|
101
|
+
|
102
|
+
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 }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#purge_exclusions" do
|
107
|
+
let(:managed_dirs) { ['dir1', 'dir2'] }
|
108
|
+
|
109
|
+
before(:each) do
|
110
|
+
allow(subject).to receive(:managed_directories).and_return(managed_dirs)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "includes managed_directories" do
|
114
|
+
expect(subject.purge_exclusions).to match_array(managed_dirs)
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when belonging to an environment" do
|
118
|
+
let(:env_contents) { ['env1', 'env2' ] }
|
119
|
+
|
120
|
+
before(:each) do
|
121
|
+
mock_env = double(:environment, desired_contents: env_contents)
|
122
|
+
allow(subject).to receive(:environment).and_return(mock_env)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "includes environment's desired_contents" do
|
126
|
+
expect(subject.purge_exclusions).to match_array(managed_dirs + env_contents)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
30
131
|
describe "evaluating a Puppetfile" do
|
31
132
|
def expect_wrapped_error(orig, pf_path, wrapped_error)
|
32
133
|
expect(orig).to be_a_kind_of(R10K::Error)
|
@@ -66,6 +167,20 @@ describe R10K::Puppetfile do
|
|
66
167
|
expect_wrapped_error(e, pf_path, ArgumentError)
|
67
168
|
end
|
68
169
|
end
|
170
|
+
|
171
|
+
it "accepts a forge module with a version" do
|
172
|
+
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
|
173
|
+
pf_path = File.join(path, 'Puppetfile')
|
174
|
+
subject = described_class.new(path)
|
175
|
+
expect { subject.load! }.not_to raise_error
|
176
|
+
end
|
177
|
+
|
178
|
+
it "accepts a forge module without a version" do
|
179
|
+
path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-without-version')
|
180
|
+
pf_path = File.join(path, 'Puppetfile')
|
181
|
+
subject = described_class.new(path)
|
182
|
+
expect { subject.load! }.not_to raise_error
|
183
|
+
end
|
69
184
|
end
|
70
185
|
|
71
186
|
describe "accepting a visitor" do
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'r10k/util/purgeable'
|
3
|
+
|
4
|
+
RSpec.describe R10K::Util::Purgeable do
|
5
|
+
let(:managed_directories) do
|
6
|
+
[
|
7
|
+
'spec/fixtures/unit/util/purgeable/managed_one',
|
8
|
+
'spec/fixtures/unit/util/purgeable/managed_two',
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:desired_contents) do
|
13
|
+
[
|
14
|
+
'spec/fixtures/unit/util/purgeable/managed_one/expected_1',
|
15
|
+
'spec/fixtures/unit/util/purgeable/managed_one/new_1',
|
16
|
+
'spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1',
|
17
|
+
'spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1',
|
18
|
+
'spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_new_1',
|
19
|
+
'spec/fixtures/unit/util/purgeable/managed_two/expected_2',
|
20
|
+
'spec/fixtures/unit/util/purgeable/managed_two/new_2',
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:test_class) do
|
25
|
+
Struct.new(:managed_directories, :desired_contents) do
|
26
|
+
include R10K::Util::Purgeable
|
27
|
+
include R10K::Logging
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
subject { test_class.new(managed_directories, desired_contents) }
|
32
|
+
|
33
|
+
context 'without recurse option' do
|
34
|
+
let(:recurse) { false }
|
35
|
+
|
36
|
+
describe '#current_contents' do
|
37
|
+
it 'collects direct contents of all managed directories' do
|
38
|
+
expect(subject.current_contents(recurse)).to contain_exactly(/\/expected_1/, /\/expected_2/, /\/unmanaged_1/, /\/unmanaged_2/, /\/managed_subdir_1/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#pending_contents' do
|
43
|
+
it 'collects desired_contents that do not yet exist' do
|
44
|
+
expect(subject.pending_contents(recurse)).to include(/\/new_1/, /\/new_2/)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#stale_contents' do
|
49
|
+
context 'with no whitelist or exclusions' do
|
50
|
+
let(:exclusions) { [] }
|
51
|
+
let(:whitelist) { [] }
|
52
|
+
|
53
|
+
it 'collects current_contents that should not exist' do
|
54
|
+
expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/, /\/unmanaged_2/)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with whitelisted items' do
|
59
|
+
let(:exclusions) { [] }
|
60
|
+
let(:whitelist) { ['**/unmanaged_1'] }
|
61
|
+
|
62
|
+
it 'collects current_contents that should not exist except whitelisted items' do
|
63
|
+
expect(subject.logger).to receive(:debug).with(/unmanaged_1.*whitelist match/i)
|
64
|
+
expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_2/)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with excluded items' do
|
69
|
+
let(:exclusions) { ['**/unmanaged_2'] }
|
70
|
+
let(:whitelist) { [] }
|
71
|
+
|
72
|
+
it 'collects current_contents that should not exist except excluded items' do
|
73
|
+
expect(subject.logger).to receive(:debug2).with(/unmanaged_2.*internal exclusion match/i)
|
74
|
+
expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#purge!' do
|
80
|
+
let(:exclusions) { [] }
|
81
|
+
let(:whitelist) { [] }
|
82
|
+
let(:purge_opts) { { recurse: recurse, whitelist: whitelist } }
|
83
|
+
|
84
|
+
it 'does nothing when there is no stale_contents' do
|
85
|
+
allow(subject).to receive(:stale_contents).and_return([])
|
86
|
+
|
87
|
+
expect(FileUtils).to_not receive(:rm_rf)
|
88
|
+
|
89
|
+
subject.purge!(purge_opts)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'recursively deletes all stale_contents' do
|
93
|
+
subject.stale_contents(recurse, exclusions, whitelist).each do |stale|
|
94
|
+
expect(FileUtils).to receive(:rm_r).with(stale, hash_including(secure: true))
|
95
|
+
end
|
96
|
+
|
97
|
+
subject.purge!(purge_opts)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with recurse option' do
|
103
|
+
let(:recurse) { true }
|
104
|
+
|
105
|
+
describe '#current_contents' do
|
106
|
+
it 'collects contents of all managed directories recursively' do
|
107
|
+
expect(subject.current_contents(recurse)).to contain_exactly(/\/expected_1/, /\/expected_2/, /\/unmanaged_1/, /\/unmanaged_2/, /\/managed_subdir_1/, /\/subdir_expected_1/, /\/subdir_unmanaged_1/)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#pending_contents' do
|
112
|
+
it 'collects desired_contents that do not yet exist recursively' do
|
113
|
+
expect(subject.pending_contents(recurse)).to include(/\/new_1/, /\/new_2/, /\/subdir_new_1/)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#stale_contents' do
|
118
|
+
context 'with no whitelist or exclusions' do
|
119
|
+
let(:exclusions) { [] }
|
120
|
+
let(:whitelist) { [] }
|
121
|
+
|
122
|
+
it 'collects current_contents that should not exist recursively' do
|
123
|
+
expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/, /\/unmanaged_2/, /\/subdir_unmanaged_1/)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'with whitelisted items' do
|
128
|
+
let(:exclusions) { [] }
|
129
|
+
let(:whitelist) { ['**/unmanaged_1'] }
|
130
|
+
|
131
|
+
it 'collects current_contents that should not exist except whitelisted items' do
|
132
|
+
expect(subject.logger).to receive(:debug).with(/unmanaged_1.*whitelist match/i)
|
133
|
+
expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_2/, /\/subdir_unmanaged_1/)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'with excluded items' do
|
138
|
+
let(:exclusions) { ['**/unmanaged_2'] }
|
139
|
+
let(:whitelist) { [] }
|
140
|
+
|
141
|
+
it 'collects current_contents that should not exist except excluded items' do
|
142
|
+
expect(subject.logger).to receive(:debug2).with(/unmanaged_2.*internal exclusion match/i)
|
143
|
+
expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/, /\/subdir_unmanaged_1/)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#purge!' do
|
149
|
+
let(:exclusions) { [] }
|
150
|
+
let(:whitelist) { [] }
|
151
|
+
let(:purge_opts) { { recurse: recurse, whitelist: whitelist } }
|
152
|
+
|
153
|
+
it 'does nothing when there is no stale_contents' do
|
154
|
+
allow(subject).to receive(:stale_contents).and_return([])
|
155
|
+
|
156
|
+
expect(FileUtils).to_not receive(:rm_r)
|
157
|
+
|
158
|
+
subject.purge!(purge_opts)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'recursively deletes all stale_contents' do
|
162
|
+
subject.stale_contents(recurse, exclusions, whitelist).each do |stale|
|
163
|
+
expect(FileUtils).to receive(:rm_r).with(stale, hash_including(secure: true))
|
164
|
+
end
|
165
|
+
|
166
|
+
subject.purge!(purge_opts)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "user whitelist functionality" do
|
172
|
+
context "non-recursive whitelist glob" do
|
173
|
+
let(:whitelist) { managed_directories.collect { |dir| File.join(dir, "*unmanaged*") } }
|
174
|
+
let(:purge_opts) { { recurse: true, whitelist: whitelist } }
|
175
|
+
|
176
|
+
describe '#purge!' do
|
177
|
+
it 'does not purge items matching glob at root level' do
|
178
|
+
allow(FileUtils).to receive(:rm_r)
|
179
|
+
expect(FileUtils).to_not receive(:rm_r).with(/\/unmanaged_[12]/, anything)
|
180
|
+
expect(subject.logger).to receive(:debug).with(/whitelist match/i).at_least(:once)
|
181
|
+
|
182
|
+
subject.purge!(purge_opts)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "recursive whitelist glob" do
|
188
|
+
let(:whitelist) { managed_directories.collect { |dir| File.join(dir, "**", "*unmanaged*") } }
|
189
|
+
let(:purge_opts) { { recurse: true, whitelist: whitelist } }
|
190
|
+
|
191
|
+
describe '#purge!' do
|
192
|
+
it 'does not purge items matching glob at any level' do
|
193
|
+
expect(FileUtils).to_not receive(:rm_r)
|
194
|
+
expect(subject.logger).to receive(:debug).with(/whitelist match/i).at_least(:once)
|
195
|
+
|
196
|
+
subject.purge!(purge_opts)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "internal exclusions functionality" do
|
203
|
+
let(:purge_opts) { { recurse: true, whitelist: [] } }
|
204
|
+
let(:exclusions) { [ File.join('**', 'unmanaged_1') ] }
|
205
|
+
|
206
|
+
context "when class implements #purge_exclusions" do
|
207
|
+
describe '#purge!' do
|
208
|
+
it 'does not purge items matching exclusion glob' do
|
209
|
+
expect(subject).to receive(:purge_exclusions).and_return(exclusions)
|
210
|
+
|
211
|
+
allow(FileUtils).to receive(:rm_r)
|
212
|
+
expect(FileUtils).to_not receive(:rm_r).with(/\/unmanaged_1/, anything)
|
213
|
+
expect(subject.logger).to receive(:debug2).with(/unmanaged_1.*internal exclusion match/i)
|
214
|
+
|
215
|
+
subject.purge!(purge_opts)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "when class does not implement #purge_exclusions" do
|
221
|
+
describe '#purge!' do
|
222
|
+
it 'purges normally' do
|
223
|
+
expect(FileUtils).to receive(:rm_r).at_least(3).times
|
224
|
+
|
225
|
+
subject.purge!(purge_opts)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|