r10k 3.15.0 → 3.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.mkd +5 -0
  3. data/CODEOWNERS +2 -2
  4. data/doc/dynamic-environments/configuration.mkd +65 -1
  5. data/lib/r10k/version.rb +1 -1
  6. data/r10k.gemspec +1 -1
  7. metadata +2 -151
  8. data/spec/fixtures/empty/.empty +0 -0
  9. data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
  10. data/spec/fixtures/module/forge/bad_module/metadata.json +0 -1
  11. data/spec/fixtures/module/forge/eight_hundred/Modulefile +0 -8
  12. data/spec/fixtures/module/forge/eight_hundred/metadata.json +0 -19
  13. data/spec/fixtures/tarball/tarball.tar.gz +0 -0
  14. data/spec/fixtures/unit/action/r10k.yaml +0 -5
  15. data/spec/fixtures/unit/action/r10k_cachedir.yaml +0 -2
  16. data/spec/fixtures/unit/action/r10k_creds.yaml +0 -9
  17. data/spec/fixtures/unit/action/r10k_forge_auth.yaml +0 -4
  18. data/spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml +0 -3
  19. data/spec/fixtures/unit/action/r10k_generate_types.yaml +0 -3
  20. data/spec/fixtures/unit/action/r10k_logging.yaml +0 -12
  21. data/spec/fixtures/unit/action/r10k_puppet_path.yaml +0 -3
  22. data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +0 -1
  23. data/spec/fixtures/unit/puppetfile/default-branch-override/Puppetfile +0 -5
  24. data/spec/fixtures/unit/puppetfile/duplicate-module-error/Puppetfile +0 -10
  25. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +0 -8
  26. data/spec/fixtures/unit/puppetfile/invalid-syntax/Puppetfile +0 -1
  27. data/spec/fixtures/unit/puppetfile/load-error/Puppetfile +0 -1
  28. data/spec/fixtures/unit/puppetfile/name-error/Puppetfile +0 -1
  29. data/spec/fixtures/unit/puppetfile/valid-forge-with-version/Puppetfile +0 -1
  30. data/spec/fixtures/unit/puppetfile/valid-forge-without-version/Puppetfile +0 -1
  31. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +0 -10
  32. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +0 -10
  33. data/spec/fixtures/unit/puppetfile/various-modules/modules/apt/.gitkeep +0 -1
  34. data/spec/fixtures/unit/puppetfile/various-modules/modules/baz/.gitkeep +0 -1
  35. data/spec/fixtures/unit/puppetfile/various-modules/modules/buzz/.gitkeep +0 -1
  36. data/spec/fixtures/unit/puppetfile/various-modules/modules/canary/.gitkeep +0 -1
  37. data/spec/fixtures/unit/puppetfile/various-modules/modules/fizz/.gitkeep +0 -1
  38. data/spec/fixtures/unit/puppetfile/various-modules/modules/rpm/.gitkeep +0 -1
  39. data/spec/fixtures/unit/util/purgeable/managed_one/expected_1 +0 -0
  40. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +0 -1
  41. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_allowlisted_2/ignored_1 +0 -0
  42. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1 +0 -0
  43. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_unmanaged_1 +0 -0
  44. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +0 -1
  45. data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +0 -1
  46. data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_1 +0 -0
  47. data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +0 -1
  48. data/spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3 +0 -0
  49. data/spec/fixtures/unit/util/purgeable/managed_two/expected_2 +0 -0
  50. data/spec/fixtures/unit/util/purgeable/managed_two/unmanaged_2 +0 -0
  51. data/spec/fixtures/unit/util/subprocess/runner/no-execute.sh +0 -3
  52. data/spec/integration/git/rugged/bare_repository_spec.rb +0 -13
  53. data/spec/integration/git/rugged/cache_spec.rb +0 -33
  54. data/spec/integration/git/rugged/thin_repository_spec.rb +0 -14
  55. data/spec/integration/git/rugged/working_repository_spec.rb +0 -48
  56. data/spec/integration/git/shellgit/bare_repository_spec.rb +0 -13
  57. data/spec/integration/git/shellgit/thin_repository_spec.rb +0 -14
  58. data/spec/integration/git/shellgit/working_repository_spec.rb +0 -13
  59. data/spec/integration/git/stateful_repository_spec.rb +0 -175
  60. data/spec/integration/util/purageable_spec.rb +0 -41
  61. data/spec/matchers/exit_with.rb +0 -28
  62. data/spec/matchers/match_realpath.rb +0 -18
  63. data/spec/r10k-mocks/mock_config.rb +0 -33
  64. data/spec/r10k-mocks/mock_env.rb +0 -18
  65. data/spec/r10k-mocks/mock_source.rb +0 -17
  66. data/spec/r10k-mocks.rb +0 -3
  67. data/spec/shared-contexts/git-fixtures.rb +0 -55
  68. data/spec/shared-contexts/tarball.rb +0 -32
  69. data/spec/shared-examples/deploy-actions.rb +0 -69
  70. data/spec/shared-examples/git/bare_repository.rb +0 -132
  71. data/spec/shared-examples/git/thin_repository.rb +0 -26
  72. data/spec/shared-examples/git/working_repository.rb +0 -207
  73. data/spec/shared-examples/git-repository.rb +0 -38
  74. data/spec/shared-examples/puppetfile-action.rb +0 -39
  75. data/spec/shared-examples/settings/ancestry.rb +0 -44
  76. data/spec/shared-examples/subprocess-runner.rb +0 -89
  77. data/spec/spec_helper.rb +0 -41
  78. data/spec/unit/action/cri_runner_spec.rb +0 -72
  79. data/spec/unit/action/deploy/deploy_helpers_spec.rb +0 -38
  80. data/spec/unit/action/deploy/display_spec.rb +0 -61
  81. data/spec/unit/action/deploy/environment_spec.rb +0 -640
  82. data/spec/unit/action/deploy/module_spec.rb +0 -476
  83. data/spec/unit/action/puppetfile/check_spec.rb +0 -53
  84. data/spec/unit/action/puppetfile/cri_runner_spec.rb +0 -47
  85. data/spec/unit/action/puppetfile/install_spec.rb +0 -112
  86. data/spec/unit/action/puppetfile/purge_spec.rb +0 -60
  87. data/spec/unit/action/runner_spec.rb +0 -407
  88. data/spec/unit/action/visitor_spec.rb +0 -39
  89. data/spec/unit/cli_spec.rb +0 -9
  90. data/spec/unit/deployment/config_spec.rb +0 -33
  91. data/spec/unit/deployment_spec.rb +0 -162
  92. data/spec/unit/environment/bare_spec.rb +0 -13
  93. data/spec/unit/environment/base_spec.rb +0 -122
  94. data/spec/unit/environment/git_spec.rb +0 -114
  95. data/spec/unit/environment/name_spec.rb +0 -181
  96. data/spec/unit/environment/plain_spec.rb +0 -8
  97. data/spec/unit/environment/svn_spec.rb +0 -146
  98. data/spec/unit/environment/tarball_spec.rb +0 -45
  99. data/spec/unit/environment/with_modules_spec.rb +0 -122
  100. data/spec/unit/errors/formatting_spec.rb +0 -84
  101. data/spec/unit/feature_spec.rb +0 -50
  102. data/spec/unit/forge/module_release_spec.rb +0 -213
  103. data/spec/unit/git/alternates_spec.rb +0 -116
  104. data/spec/unit/git/cache_spec.rb +0 -66
  105. data/spec/unit/git/rugged/cache_spec.rb +0 -48
  106. data/spec/unit/git/rugged/credentials_spec.rb +0 -215
  107. data/spec/unit/git/shellgit/cache_spec.rb +0 -27
  108. data/spec/unit/git/stateful_repository_spec.rb +0 -45
  109. data/spec/unit/git_spec.rb +0 -102
  110. data/spec/unit/initializers_spec.rb +0 -68
  111. data/spec/unit/instance_cache_spec.rb +0 -78
  112. data/spec/unit/keyed_factory_spec.rb +0 -51
  113. data/spec/unit/logging/terminaloutputter_spec.rb +0 -53
  114. data/spec/unit/logging_spec.rb +0 -68
  115. data/spec/unit/module/base_spec.rb +0 -118
  116. data/spec/unit/module/forge_spec.rb +0 -271
  117. data/spec/unit/module/git_spec.rb +0 -387
  118. data/spec/unit/module/metadata_file_spec.rb +0 -68
  119. data/spec/unit/module/svn_spec.rb +0 -208
  120. data/spec/unit/module/tarball_spec.rb +0 -70
  121. data/spec/unit/module_loader/puppetfile_spec.rb +0 -421
  122. data/spec/unit/module_spec.rb +0 -114
  123. data/spec/unit/puppetfile_spec.rb +0 -304
  124. data/spec/unit/settings/collection_spec.rb +0 -123
  125. data/spec/unit/settings/container_spec.rb +0 -92
  126. data/spec/unit/settings/definition_spec.rb +0 -79
  127. data/spec/unit/settings/enum_definition_spec.rb +0 -20
  128. data/spec/unit/settings/inheritance_spec.rb +0 -38
  129. data/spec/unit/settings/list_spec.rb +0 -88
  130. data/spec/unit/settings/loader_spec.rb +0 -110
  131. data/spec/unit/settings/uri_definition_spec.rb +0 -23
  132. data/spec/unit/settings_spec.rb +0 -303
  133. data/spec/unit/source/base_spec.rb +0 -31
  134. data/spec/unit/source/exec_spec.rb +0 -81
  135. data/spec/unit/source/git_spec.rb +0 -233
  136. data/spec/unit/source/hash_spec.rb +0 -54
  137. data/spec/unit/source/svn_spec.rb +0 -196
  138. data/spec/unit/source/yaml_spec.rb +0 -42
  139. data/spec/unit/source_spec.rb +0 -10
  140. data/spec/unit/svn/remote_spec.rb +0 -21
  141. data/spec/unit/svn/working_dir_spec.rb +0 -56
  142. data/spec/unit/tarball_spec.rb +0 -57
  143. data/spec/unit/util/attempt_spec.rb +0 -82
  144. data/spec/unit/util/cacheable_spec.rb +0 -23
  145. data/spec/unit/util/commands_spec.rb +0 -61
  146. data/spec/unit/util/downloader_spec.rb +0 -98
  147. data/spec/unit/util/exec_env_spec.rb +0 -56
  148. data/spec/unit/util/purgeable_spec.rb +0 -267
  149. data/spec/unit/util/setopts_spec.rb +0 -83
  150. data/spec/unit/util/subprocess/result_spec.rb +0 -36
  151. data/spec/unit/util/subprocess/runner/posix_spec.rb +0 -7
  152. data/spec/unit/util/subprocess/runner/pump_spec.rb +0 -79
  153. data/spec/unit/util/subprocess/runner/windows_spec.rb +0 -7
  154. data/spec/unit/util/subprocess/subprocess_error_spec.rb +0 -26
  155. data/spec/unit/util/subprocess_spec.rb +0 -65
  156. data/spec/unit/util/symbolize_keys_spec.rb +0 -67
@@ -1,304 +0,0 @@
1
- require 'spec_helper'
2
- require 'r10k/puppetfile'
3
-
4
- describe R10K::Puppetfile do
5
-
6
- subject do
7
- described_class.new(
8
- '/some/nonexistent/basedir',
9
- {puppetfile_name: 'Puppetfile.r10k'}
10
- )
11
- end
12
-
13
- describe "a custom puppetfile_name" do
14
- it "is the basedir joined with '/Puppetfile.r10k' path" do
15
- expect(subject.puppetfile_path).to eq '/some/nonexistent/basedir/Puppetfile.r10k'
16
- end
17
- end
18
-
19
- end
20
-
21
- describe R10K::Puppetfile do
22
-
23
- describe "a custom relative puppetfile_path" do
24
- it "is the basedir joined with the puppetfile_path" do
25
- relative_subject = described_class.new('/some/nonexistent/basedir',
26
- {puppetfile_path: 'relative/Puppetfile'})
27
- expect(relative_subject.puppetfile_path).to eq '/some/nonexistent/basedir/relative/Puppetfile'
28
- end
29
- end
30
-
31
- describe "a custom absolute puppetfile_path" do
32
- it "is the puppetfile_path as given" do
33
- absolute_subject = described_class.new('/some/nonexistent/basedir',
34
- {puppetfile_path: '/some/absolute/custom/Puppetfile'})
35
- expect(absolute_subject.puppetfile_path).to eq '/some/absolute/custom/Puppetfile'
36
- end
37
- end
38
- end
39
-
40
- describe R10K::Puppetfile do
41
-
42
- subject do
43
- described_class.new( '/some/nonexistent/basedir', {})
44
- end
45
-
46
- describe "backwards compatibility with older calling conventions" do
47
- it "honors all arguments correctly" do
48
- puppetfile = described_class.new('/some/nonexistant/basedir', '/some/nonexistant/basedir/site-modules', nil, 'Pupupupetfile', true)
49
- expect(puppetfile.force).to eq(true)
50
- expect(puppetfile.moduledir).to eq('/some/nonexistant/basedir/site-modules')
51
- expect(puppetfile.puppetfile_path).to eq('/some/nonexistant/basedir/Pupupupetfile')
52
- expect(puppetfile.overrides).to eq({})
53
- end
54
-
55
- it "handles defaults correctly" do
56
- puppetfile = described_class.new('/some/nonexistant/basedir', nil, nil, nil)
57
- expect(puppetfile.force).to eq(false)
58
- expect(puppetfile.moduledir).to eq('/some/nonexistant/basedir/modules')
59
- expect(puppetfile.puppetfile_path).to eq('/some/nonexistant/basedir/Puppetfile')
60
- expect(puppetfile.overrides).to eq({})
61
- end
62
- end
63
-
64
- describe "the default moduledir" do
65
- it "is the basedir joined with '/modules' path" do
66
- expect(subject.moduledir).to eq '/some/nonexistent/basedir/modules'
67
- end
68
- end
69
-
70
- describe "the default puppetfile" do
71
- it "is the basedir joined with '/Puppetfile' path" do
72
- expect(subject.puppetfile_path).to eq '/some/nonexistent/basedir/Puppetfile'
73
- end
74
- end
75
-
76
-
77
- describe "setting moduledir" do
78
- it "changes to given moduledir if it is an absolute path" do
79
- subject.set_moduledir('/absolute/path/moduledir')
80
- expect(subject.moduledir).to eq '/absolute/path/moduledir'
81
- end
82
-
83
- it "joins the basedir with the given moduledir if it is a relative path" do
84
- subject.set_moduledir('relative/moduledir')
85
- expect(subject.moduledir).to eq '/some/nonexistent/basedir/relative/moduledir'
86
- end
87
- end
88
-
89
- describe "loading a Puppetfile" do
90
- context 'using load' do
91
- it "returns the loaded content" do
92
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
93
- subject = described_class.new(path, {})
94
-
95
- loaded_content = subject.load
96
- expect(loaded_content).to be_an_instance_of(Hash)
97
-
98
- has_some_data = loaded_content.values.none?(&:empty?)
99
- expect(has_some_data).to be true
100
- end
101
-
102
- it "handles a relative basedir" do
103
- path = File.join('spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
104
- subject = described_class.new(path, {})
105
-
106
- loaded_content = subject.load
107
- expect(loaded_content).to be_an_instance_of(Hash)
108
-
109
- has_some_data = loaded_content.values.none?(&:empty?)
110
- expect(has_some_data).to be true
111
- end
112
-
113
- it "is idempotent" do
114
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
115
- subject = described_class.new(path, {})
116
-
117
- expect(subject.loader).to receive(:load!).and_call_original.once
118
-
119
- loaded_content1 = subject.load
120
- expect(subject.loaded?).to be true
121
- loaded_content2 = subject.load
122
-
123
- expect(loaded_content2).to eq(loaded_content1)
124
- end
125
-
126
- it "returns nil if Puppetfile doesn't exist" do
127
- path = '/rando/path/that/wont/exist'
128
- subject = described_class.new(path, {})
129
- expect(subject.load).to eq nil
130
- end
131
- end
132
-
133
- context 'using load!' do
134
- it "returns the loaded content" do
135
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
136
- subject = described_class.new(path, {})
137
-
138
- loaded_content = subject.load!
139
- expect(loaded_content).to be_an_instance_of(Hash)
140
-
141
- has_some_data = loaded_content.values.none?(&:empty?)
142
- expect(has_some_data).to be true
143
- end
144
-
145
- it "raises if Puppetfile doesn't exist" do
146
- path = '/rando/path/that/wont/exist'
147
- subject = described_class.new(path, {})
148
- expect {
149
- subject.load!
150
- }.to raise_error(/No such file or directory.*\/rando\/path\/.*/)
151
- end
152
- end
153
- end
154
-
155
- describe 'default_branch_override' do
156
- it 'is passed correctly to module loader init' do
157
- # This path doesn't matter so long as it has a Puppetfile within it
158
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
159
- subject = described_class.new(path, {overrides: {environments: {default_branch_override: 'foo'}}})
160
-
161
- repo = instance_double('R10K::Git::StatefulRepository')
162
- allow(repo).to receive(:resolve).with('foo').and_return(true)
163
- allow(R10K::Git::StatefulRepository).to receive(:new).and_return(repo)
164
-
165
- allow(subject.loader).to receive(:puppetfile_content).and_return <<-EOPF
166
- # Track control branch and fall-back to main if no matching branch.
167
- mod 'hieradata',
168
- :git => 'git@git.example.com:organization/hieradata.git',
169
- :branch => :control_branch,
170
- :default_branch => 'main'
171
- EOPF
172
-
173
- expect(subject.logger).not_to receive(:warn).
174
- with(/Mismatch between passed and initialized.*preferring passed value/)
175
-
176
- subject.load
177
-
178
- loaded_module = subject.modules.first
179
- expect(loaded_module.version).to eq('foo')
180
- end
181
-
182
- it 'overrides module loader init if needed' do
183
- # This path doesn't matter so long as it has a Puppetfile within it
184
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
185
- subject = described_class.new(path, {overrides: {environments: {default_branch_override: 'foo'}}})
186
-
187
- repo = instance_double('R10K::Git::StatefulRepository')
188
- allow(repo).to receive(:resolve).with('bar').and_return(true)
189
- allow(R10K::Git::StatefulRepository).to receive(:new).and_return(repo)
190
-
191
- allow(subject.loader).to receive(:puppetfile_content).and_return <<-EOPF
192
- # Track control branch and fall-back to main if no matching branch.
193
- mod 'hieradata',
194
- :git => 'git@git.example.com:organization/hieradata.git',
195
- :branch => :control_branch,
196
- :default_branch => 'main'
197
- EOPF
198
-
199
- expect(subject.logger).to receive(:warn).
200
- with(/Mismatch between passed and initialized.*preferring passed value/)
201
-
202
- subject.load('bar')
203
- loaded_module = subject.modules.first
204
- expect(loaded_module.version).to eq('bar')
205
- end
206
-
207
- it 'does not warn if passed and initialized default_branch_overrides match' do
208
- # This path doesn't matter so long as it has a Puppetfile within it
209
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
210
- subject = described_class.new(path, {overrides: {environments: {default_branch_override: 'foo'}}})
211
-
212
- repo = instance_double('R10K::Git::StatefulRepository')
213
- allow(repo).to receive(:resolve).with('foo').and_return(true)
214
- allow(R10K::Git::StatefulRepository).to receive(:new).and_return(repo)
215
-
216
- allow(subject.loader).to receive(:puppetfile_content).and_return <<-EOPF
217
- # Track control branch and fall-back to main if no matching branch.
218
- mod 'hieradata',
219
- :git => 'git@git.example.com:organization/hieradata.git',
220
- :branch => :control_branch,
221
- :default_branch => 'main'
222
- EOPF
223
-
224
- expect(subject.logger).not_to receive(:warn).
225
- with(/Mismatch between passed and initialized.*preferring passed value/)
226
-
227
- subject.load('foo')
228
- loaded_module = subject.modules.first
229
- expect(loaded_module.version).to eq('foo')
230
- end
231
- end
232
-
233
- describe "accepting a visitor" do
234
- it "passes itself to the visitor" do
235
- visitor = spy('visitor')
236
- expect(visitor).to receive(:visit).with(:puppetfile, subject)
237
- subject.accept(visitor)
238
- end
239
-
240
- it "synchronizes each module if the visitor yields" do
241
- visitor = spy('visitor')
242
- expect(visitor).to receive(:visit) do |type, other, &block|
243
- expect(type).to eq :puppetfile
244
- expect(other).to eq subject
245
- block.call
246
- end
247
-
248
- mod1 = instance_double('R10K::Module::Base', :cachedir => :none)
249
- mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
250
- expect(mod1).to receive(:sync)
251
- expect(mod2).to receive(:sync)
252
- expect(subject).to receive(:modules).and_return([mod1, mod2])
253
-
254
- subject.accept(visitor)
255
- end
256
-
257
- it "creates a thread pool to visit concurrently if pool_size setting is greater than one" do
258
- pool_size = 3
259
-
260
- subject.settings[:pool_size] = pool_size
261
-
262
- visitor = spy('visitor')
263
- expect(visitor).to receive(:visit) do |type, other, &block|
264
- expect(type).to eq :puppetfile
265
- expect(other).to eq subject
266
- block.call
267
- end
268
-
269
- mod1 = instance_double('R10K::Module::Base', :cachedir => :none)
270
- mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
271
- expect(mod1).to receive(:sync)
272
- expect(mod2).to receive(:sync)
273
- expect(subject).to receive(:modules).and_return([mod1, mod2])
274
-
275
- expect(Thread).to receive(:new).exactly(pool_size).and_call_original
276
- expect(Queue).to receive(:new).and_call_original.twice
277
-
278
- subject.accept(visitor)
279
- end
280
-
281
- it "Creates queues of modules grouped by cachedir" do
282
- visitor = spy('visitor')
283
- expect(visitor).to receive(:visit) do |type, other, &block|
284
- expect(type).to eq :puppetfile
285
- expect(other).to eq subject
286
- block.call
287
- end
288
-
289
- m1 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/A')
290
- m2 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/B')
291
- m3 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
292
- m4 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
293
- m5 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
294
- m6 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
295
-
296
- modules = [m1, m2, m3, m4, m5, m6]
297
-
298
- queue = R10K::ContentSynchronizer.modules_visit_queue(modules, visitor, subject)
299
- expect(queue.length).to be 4
300
- queue_array = 4.times.map { queue.pop }
301
- expect(queue_array).to match_array([[m1], [m2], [m3, m4], [m5, m6]])
302
- end
303
- end
304
- end
@@ -1,123 +0,0 @@
1
- require 'spec_helper'
2
- require 'r10k/settings/collection'
3
- require 'r10k/settings/definition'
4
-
5
- describe R10K::Settings::Collection do
6
-
7
- let(:symbol_defn) { R10K::Settings::Definition.new(:symbol_defn, :validate => lambda { |x| raise TypeError unless x.is_a?(Symbol) }) }
8
- let(:default_defn) { R10K::Settings::Definition.new(:default_defn, :default => lambda { "Defaults are fun" }) }
9
-
10
- subject do
11
- described_class.new(:collection, [symbol_defn, default_defn])
12
- end
13
-
14
- it_behaves_like "a setting with ancestors"
15
-
16
- describe "#evaluate" do
17
- it "assigns values, validates them, and resolves a final value" do
18
- expect(subject).to receive(:assign).with({:default_defn => :squid})
19
- expect(subject).to receive(:validate)
20
- expect(subject).to receive(:resolve)
21
- subject.evaluate({:default_defn => :squid})
22
- end
23
- end
24
-
25
- describe '#assign' do
26
- it "assigns values to the appropriate setting" do
27
- subject.assign({:symbol_defn => :hello})
28
- expect(symbol_defn.value).to eq :hello
29
- end
30
-
31
- it "can accept invalid settings" do
32
- subject.assign({:hardly_a_setting => "nope nope nope"})
33
- end
34
-
35
- it "silently ignores attempts to assign nil" do
36
- subject.assign(nil)
37
- end
38
- end
39
-
40
- describe '#validate' do
41
- it "raises an error containing a hash of nested validation errors" do
42
- subject.assign({:symbol_defn => "Definitely not a symbol"})
43
- expect {
44
- errors = subject.validate
45
- }.to raise_error do |error|
46
- expect(error).to be_a_kind_of(R10K::Settings::Collection::ValidationError)
47
- errors = error.errors
48
- expect(errors.size).to eq 1
49
- expect(errors[:symbol_defn]).to be_a_kind_of(TypeError)
50
- end
51
- end
52
-
53
- it "it does not raise an error if no errors were found" do
54
- subject.assign({:default_defn => "yep"})
55
- expect(subject.validate).to be_nil
56
- end
57
- end
58
-
59
- describe '#resolve' do
60
- it "returns a frozen hash of all settings" do
61
- subject.assign({:symbol_defn => :some_value})
62
- rv = subject.resolve
63
- expect(rv).to be_frozen
64
- expect(rv).to eq({:symbol_defn => :some_value, :default_defn => "Defaults are fun"})
65
- end
66
- end
67
- end
68
-
69
- describe R10K::Settings::Collection::ValidationError do
70
-
71
-
72
- let(:flat_errors) do
73
- described_class.new("Validation failures for some group", errors: {
74
- some_defn: ArgumentError.new("some_defn is wrong, somehow."),
75
- uri_setting: ArgumentError.new("uri_setting NOTAURI is not a URI.")
76
- })
77
- end
78
-
79
- let(:flat_error_text) do
80
- [
81
- "Validation failures for some group:",
82
- " some_defn:",
83
- " some_defn is wrong, somehow.",
84
- " uri_setting:",
85
- " uri_setting NOTAURI is not a URI."]
86
- .join("\n")
87
- end
88
-
89
- let(:nested_errors) do
90
- described_class.new("Validation failures for some nesting group", errors: {
91
- file_setting: ArgumentError.new("file_setting is a potato, not a file."),
92
- nested: flat_errors
93
- })
94
- end
95
-
96
- let(:nested_error_text) do
97
- [
98
- "Validation failures for some nesting group:",
99
- " file_setting:",
100
- " file_setting is a potato, not a file.",
101
- " nested:",
102
- " Validation failures for some group:",
103
- " some_defn:",
104
- " some_defn is wrong, somehow.",
105
- " uri_setting:",
106
- " uri_setting NOTAURI is not a URI."
107
- ].join("\n")
108
- end
109
-
110
- describe "formatting a human readable error message" do
111
- describe "no with no nested validation errors" do
112
- it "generates a human readable set of validation errors." do
113
- expect(flat_errors.format).to eq flat_error_text
114
- end
115
- end
116
-
117
- describe "with nested validation errors" do
118
- it "generates a human readable set of validation errors." do
119
- expect(nested_errors.format).to eq nested_error_text
120
- end
121
- end
122
- end
123
- end
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'r10k/settings'
4
-
5
- describe R10K::Settings::Container do
6
-
7
- describe 'validating keys' do
8
- it 'can add new valid keys' do
9
- subject.add_valid_key(:v)
10
- subject[:v]
11
- end
12
-
13
- it 'can check if a key is valid' do
14
- subject.add_valid_key(:v)
15
- expect(subject.valid_key?(:v)).to be_truthy
16
- end
17
-
18
- it 'can list all valid keys' do
19
- subject.add_valid_key(:v)
20
- subject.add_valid_key(:w)
21
-
22
- expect(subject.valid_keys).to include :v
23
- expect(subject.valid_keys).to include :w
24
- end
25
- end
26
-
27
- describe 'specifying settings' do
28
- it 'fails if a setting application uses an invalid key' do
29
- expect { subject[:invalid] = 'fail' }.to raise_error R10K::Settings::Container::InvalidKey
30
- end
31
-
32
- it 'can look up values that it sets' do
33
- subject.add_valid_key :v
34
- subject[:v] = 'set'
35
- expect(subject[:v]).to eq 'set'
36
- end
37
- end
38
-
39
- describe 'looking up settings' do
40
- before do
41
- subject.add_valid_key :v
42
- end
43
-
44
- it 'fails if a setting lookup uses an invalid key' do
45
- expect { subject[:invalid] }.to raise_error R10K::Settings::Container::InvalidKey
46
- end
47
-
48
- it 'returns nil if a key is valid but no setting is present' do
49
- expect(subject[:v]).to be_nil
50
- end
51
-
52
- describe 'with a parent container' do
53
- let(:parent) { described_class.new.tap { |p| p.add_valid_key :v } }
54
- subject { described_class.new(parent) }
55
-
56
- it 'uses its setting over a parent value' do
57
- subject[:v] = 'child'
58
- parent[:v] = 'parent'
59
- expect(subject[:v]).to eq 'child'
60
- end
61
-
62
- it 'duplicates and stores the parent object to avoid modifying the parent object' do
63
- parent[:v] = {}
64
- subject[:v][:hello] = "world"
65
- expect(subject[:v]).to eq({hello: "world"})
66
- expect(parent[:v]).to eq({})
67
- end
68
-
69
- it 'falls back to the parent value if it does not have a value' do
70
- parent[:v] = 'parent'
71
- expect(subject[:v]).to eq 'parent'
72
- end
73
- end
74
- end
75
-
76
- describe "resetting" do
77
- before do
78
- subject.add_valid_key :v
79
- end
80
-
81
- it "unsets all settings" do
82
- subject[:v] = "hi"
83
- subject.reset!
84
- expect(subject[:v]).to be_nil
85
- end
86
-
87
- it "doesn't remove valid values" do
88
- subject.reset!
89
- expect(subject.valid_key?(:v)).to be_truthy
90
- end
91
- end
92
- end
@@ -1,79 +0,0 @@
1
- require 'spec_helper'
2
- require 'r10k/settings/definition'
3
- require 'r10k/settings/collection'
4
- require 'r10k/settings/list'
5
-
6
- describe R10K::Settings::Definition do
7
- subject { described_class.new(:setting) }
8
-
9
- it_behaves_like "a setting with ancestors"
10
-
11
- describe "#evaluate" do
12
- it "assigns a value, validates it, and resolves a final value" do
13
- expect(subject).to receive(:assign).with("myvalue")
14
- expect(subject).to receive(:validate)
15
- expect(subject).to receive(:resolve)
16
- subject.evaluate("myvalue")
17
- end
18
- end
19
-
20
- describe "#assign" do
21
- it 'stores the provided value' do
22
- subject.assign("I'm the value")
23
- expect(subject.value).to eq "I'm the value"
24
- end
25
-
26
- it "normalizes the stored value when a normalize hook is set" do
27
- subject = described_class.new(:setting, :normalize => lambda { |input| input.to_sym })
28
- subject.assign("symbolizeme")
29
- expect(subject.value).to eq :symbolizeme
30
- end
31
- end
32
-
33
- describe "#validate" do
34
- it "does nothing if a value has not been assigned" do
35
- subject = described_class.new(:setting, :validate => lambda { |_| raise "Shouldn't be called" })
36
- subject.validate
37
- end
38
-
39
- it "does nothing if a validate hook has not been assigned" do
40
- subject.assign("I'm the value")
41
- subject.validate
42
- end
43
-
44
- it "raises up errors raised from the validate hook" do
45
- subject = described_class.new(:satellite, :validate => lambda { |input| raise ArgumentError, "Invalid value #{input}: that's no moon!" })
46
- subject.assign("Alderaan")
47
- expect {
48
- subject.validate
49
- }.to raise_error(ArgumentError, "Invalid value Alderaan: that's no moon!")
50
- end
51
-
52
- it "returns if the validate hook did not raise an error" do
53
- subject = described_class.new(:setting, :validate => lambda { |_| "That's a moon" })
54
- subject.assign("Mun")
55
- subject.validate
56
- end
57
- end
58
-
59
- describe "#resolve" do
60
- it "returns the value when the value has been given" do
61
- subject.assign("Mun")
62
- expect(subject.resolve).to eq "Mun"
63
- end
64
-
65
- it "resolves the default when the default is a proc" do
66
- subject = described_class.new(:setting, :default => lambda { "Minmus" })
67
- expect(subject.resolve).to eq "Minmus"
68
- end
69
-
70
- it "returns the default when the default is not a proc" do
71
- subject = described_class.new(:setting, :default => "Ike")
72
- expect(subject.resolve).to eq "Ike"
73
- end
74
-
75
- it "returns nil when there is no value nor default" do
76
- expect(subject.resolve).to be_nil
77
- end
78
- end
79
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'r10k/settings/enum_definition'
3
-
4
- describe R10K::Settings::EnumDefinition do
5
-
6
- subject { described_class.new(:enum, :enum => %w[one two three]) }
7
-
8
- describe '#validate' do
9
- it "doesn't raise an error when given an expected value" do
10
- subject.assign('two')
11
- subject.validate
12
- end
13
- it "raises an error when given a value outside the enum" do
14
- subject.assign('dos')
15
- expect {
16
- subject.validate
17
- }.to raise_error(ArgumentError, "Setting enum should be one of #{%w[one two three].inspect}, not 'dos'")
18
- end
19
- end
20
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'r10k/settings/collection'
3
- require 'r10k/settings/definition'
4
-
5
- RSpec.describe 'R10K::Settings inheritance' do
6
- subject do
7
- R10K::Settings::Collection.new(:parent_settings, [
8
- R10K::Settings::Definition.new(:banana, {
9
- :default => 'cavendish',
10
- }),
11
-
12
- R10K::Settings::Collection.new(:child_settings, [
13
- R10K::Settings::Definition.new(:banana, {
14
- :default => :inherit,
15
- }),
16
- ]),
17
- ])
18
- end
19
-
20
- describe "child settings" do
21
- let(:setting) { subject[:child_settings][:banana] }
22
-
23
- context "when child value is not set" do
24
- it "should resolve to default value from parent" do
25
- expect(setting.value).to be_nil
26
- expect(setting.resolve).to eq 'cavendish'
27
- end
28
- end
29
-
30
- context "when child value is set" do
31
- before(:each) { setting.assign('gros michel') }
32
-
33
- it "should resolve to child value" do
34
- expect(setting.resolve).to eq 'gros michel'
35
- end
36
- end
37
- end
38
- end