r10k 3.15.0 → 3.15.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.mkd +9 -0
- data/CODEOWNERS +2 -2
- data/README.mkd +11 -0
- data/doc/dynamic-environments/configuration.mkd +65 -1
- data/lib/r10k/action/puppetfile/install.rb +2 -1
- data/lib/r10k/cli/puppetfile.rb +1 -0
- data/lib/r10k/module_loader/puppetfile.rb +10 -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,271 +0,0 @@
|
|
1
|
-
require 'r10k/module/forge'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe R10K::Module::Forge do
|
5
|
-
# TODO: make these *unit* tests not depend on a real module on the real Forge :(
|
6
|
-
|
7
|
-
include_context 'fail on execution'
|
8
|
-
|
9
|
-
let(:fixture_modulepath) { File.expand_path('spec/fixtures/module/forge', PROJECT_ROOT) }
|
10
|
-
let(:empty_modulepath) { File.expand_path('spec/fixtures/empty', PROJECT_ROOT) }
|
11
|
-
|
12
|
-
describe "statically determined version support" do
|
13
|
-
it 'returns explicitly released forge versions' do
|
14
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { version: '8.0.0' })
|
15
|
-
expect(static_version).to eq('8.0.0')
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns explicit pre-released forge versions' do
|
19
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { version: '8.0.0-pre1' })
|
20
|
-
expect(static_version).to eq('8.0.0-pre1')
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'retuns nil for latest versions' do
|
24
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { version: :latest })
|
25
|
-
expect(static_version).to eq(nil)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'retuns nil for undefined versions' do
|
29
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { version: nil })
|
30
|
-
expect(static_version).to eq(nil)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "implementing the Puppetfile spec" do
|
35
|
-
it "should implement 'branan/eight_hundred', '8.0.0'" do
|
36
|
-
expect(described_class).to be_implement('branan/eight_hundred', { type: 'forge', version: '8.0.0' })
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should implement 'branan-eight_hundred', '8.0.0'" do
|
40
|
-
expect(described_class).to be_implement('branan-eight_hundred', { type: 'forge', version: '8.0.0' })
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "implementing the standard options interface" do
|
45
|
-
it "should implement {type: forge}" do
|
46
|
-
expect(described_class).to be_implement('branan-eight_hundred', { type: 'forge', version: '8.0.0', source: 'not implemented' })
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "setting attributes" do
|
51
|
-
subject { described_class.new('branan/eight_hundred', '/moduledir', { version: '8.0.0' }) }
|
52
|
-
|
53
|
-
it "sets the name" do
|
54
|
-
expect(subject.name).to eq 'eight_hundred'
|
55
|
-
end
|
56
|
-
|
57
|
-
it "sets the author" do
|
58
|
-
expect(subject.author).to eq 'branan'
|
59
|
-
end
|
60
|
-
|
61
|
-
it "sets the dirname" do
|
62
|
-
expect(subject.dirname).to eq '/moduledir'
|
63
|
-
end
|
64
|
-
|
65
|
-
it "sets the title" do
|
66
|
-
expect(subject.title).to eq 'branan-eight_hundred'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "invalid attributes" do
|
71
|
-
it "errors on invalid versions" do
|
72
|
-
expect { described_class.new('branan/eight_hundred', '/moduledir', { version: '_8.0.0_' }) }.to raise_error ArgumentError, /version/
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "properties" do
|
77
|
-
subject { described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' }) }
|
78
|
-
|
79
|
-
it "sets the module type to :forge" do
|
80
|
-
expect(subject.properties).to include(:type => :forge)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "sets the expected version" do
|
84
|
-
expect(subject.properties).to include(:expected => '8.0.0')
|
85
|
-
end
|
86
|
-
|
87
|
-
it "sets the actual version" do
|
88
|
-
expect(subject).to receive(:current_version).and_return('0.8.0')
|
89
|
-
expect(subject.properties).to include(:actual => '0.8.0')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context "when a module is deprecated" do
|
94
|
-
subject { described_class.new('puppetlabs/corosync', fixture_modulepath, { version: :latest }) }
|
95
|
-
|
96
|
-
it "warns on sync if module is not already insync" do
|
97
|
-
allow(subject).to receive(:status).and_return(:absent)
|
98
|
-
|
99
|
-
allow(R10K::Forge::ModuleRelease).to receive(:new).and_return(double('mod_release', install: true))
|
100
|
-
|
101
|
-
logger_dbl = double(Log4r::Logger)
|
102
|
-
allow_any_instance_of(described_class).to receive(:logger).and_return(logger_dbl)
|
103
|
-
|
104
|
-
allow(logger_dbl).to receive(:info).with(/Deploying module to.*/)
|
105
|
-
allow(logger_dbl).to receive(:debug2).with(/No spec dir detected/)
|
106
|
-
expect(logger_dbl).to receive(:warn).with(/puppet forge module.*puppetlabs-corosync.*has been deprecated/i)
|
107
|
-
|
108
|
-
subject.sync
|
109
|
-
end
|
110
|
-
|
111
|
-
it "does not warn on sync if module is already insync" do
|
112
|
-
allow(subject).to receive(:status).and_return(:insync)
|
113
|
-
|
114
|
-
logger_dbl = double(Log4r::Logger)
|
115
|
-
allow_any_instance_of(described_class).to receive(:logger).and_return(logger_dbl)
|
116
|
-
|
117
|
-
allow(logger_dbl).to receive(:info).with(/Deploying module to.*/)
|
118
|
-
allow(logger_dbl).to receive(:debug2).with(/No spec dir detected/)
|
119
|
-
expect(logger_dbl).to_not receive(:warn).with(/puppet forge module.*puppetlabs-corosync.*has been deprecated/i)
|
120
|
-
|
121
|
-
subject.sync
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe '#expected_version' do
|
126
|
-
it "returns an explicitly given expected version" do
|
127
|
-
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' })
|
128
|
-
expect(subject.expected_version).to eq '8.0.0'
|
129
|
-
end
|
130
|
-
|
131
|
-
it "uses the latest version from the forge when the version is :latest" do
|
132
|
-
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: :latest })
|
133
|
-
release = double("Module Release", version: '8.8.8')
|
134
|
-
expect(subject.v3_module).to receive(:current_release).and_return(release).twice
|
135
|
-
expect(subject.expected_version).to eq '8.8.8'
|
136
|
-
end
|
137
|
-
|
138
|
-
it "throws when there are no available versions" do
|
139
|
-
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: :latest })
|
140
|
-
expect(subject.v3_module).to receive(:current_release).and_return(nil)
|
141
|
-
expect { subject.expected_version }.to raise_error(PuppetForge::ReleaseNotFound)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe "determining the status" do
|
146
|
-
|
147
|
-
subject { described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' }) }
|
148
|
-
|
149
|
-
it "is :absent if the module directory is absent" do
|
150
|
-
allow(subject).to receive(:exist?).and_return false
|
151
|
-
expect(subject.status).to eq :absent
|
152
|
-
end
|
153
|
-
|
154
|
-
it "is :mismatched if there is no module metadata" do
|
155
|
-
allow(subject).to receive(:exist?).and_return true
|
156
|
-
allow(File).to receive(:exist?).and_return false
|
157
|
-
|
158
|
-
expect(subject.status).to eq :mismatched
|
159
|
-
end
|
160
|
-
|
161
|
-
it "is :mismatched if module was previously a git checkout" do
|
162
|
-
allow(File).to receive(:directory?).and_return true
|
163
|
-
|
164
|
-
expect(subject.status).to eq :mismatched
|
165
|
-
end
|
166
|
-
|
167
|
-
it "is :mismatched if the metadata author doesn't match the expected author" do
|
168
|
-
allow(subject).to receive(:exist?).and_return true
|
169
|
-
|
170
|
-
allow(subject.instance_variable_get(:@metadata_file)).to receive(:read).and_return subject.metadata
|
171
|
-
allow(subject.metadata).to receive(:full_module_name).and_return 'blargh-blargh'
|
172
|
-
|
173
|
-
expect(subject.status).to eq :mismatched
|
174
|
-
end
|
175
|
-
|
176
|
-
it "is :outdated if the metadata version doesn't match the expected version" do
|
177
|
-
allow(subject).to receive(:exist?).and_return true
|
178
|
-
|
179
|
-
allow(subject.instance_variable_get(:@metadata_file)).to receive(:read).and_return subject.metadata
|
180
|
-
allow(subject.metadata).to receive(:version).and_return '7.0.0'
|
181
|
-
expect(subject.status).to eq :outdated
|
182
|
-
end
|
183
|
-
|
184
|
-
it "is :insync if the version and the author are in sync" do
|
185
|
-
allow(subject).to receive(:exist?).and_return true
|
186
|
-
|
187
|
-
expect(subject.status).to eq :insync
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "#sync" do
|
192
|
-
subject { described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' }) }
|
193
|
-
|
194
|
-
context "syncing the repo" do
|
195
|
-
let(:module_org) { "coolorg" }
|
196
|
-
let(:module_name) { "coolmod" }
|
197
|
-
let(:title) { "#{module_org}-#{module_name}" }
|
198
|
-
let(:dirname) { Pathname.new(Dir.mktmpdir) }
|
199
|
-
let(:spec_path) { dirname + module_name + 'spec' }
|
200
|
-
subject { described_class.new(title, dirname, {}) }
|
201
|
-
|
202
|
-
it 'defaults to keeping the spec dir' do
|
203
|
-
FileUtils.mkdir_p(spec_path)
|
204
|
-
expect(subject).to receive(:status).and_return(:absent)
|
205
|
-
expect(subject).to receive(:install)
|
206
|
-
subject.sync
|
207
|
-
expect(Dir.exist?(spec_path)).to eq true
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'does nothing when the module is in sync' do
|
212
|
-
allow(subject).to receive(:status).and_return :insync
|
213
|
-
|
214
|
-
expect(subject).to receive(:install).never
|
215
|
-
expect(subject).to receive(:upgrade).never
|
216
|
-
expect(subject).to receive(:reinstall).never
|
217
|
-
expect(subject.sync).to be false
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'reinstalls the module when it is mismatched' do
|
221
|
-
allow(subject).to receive(:status).and_return :mismatched
|
222
|
-
expect(subject).to receive(:reinstall)
|
223
|
-
expect(subject.sync).to be true
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'upgrades the module when it is outdated' do
|
227
|
-
allow(subject).to receive(:status).and_return :outdated
|
228
|
-
expect(subject).to receive(:upgrade)
|
229
|
-
expect(subject.sync).to be true
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'installs the module when it is absent' do
|
233
|
-
allow(subject).to receive(:status).and_return :absent
|
234
|
-
expect(subject).to receive(:install)
|
235
|
-
expect(subject.sync).to be true
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'returns false if `should_sync?` is false' do
|
239
|
-
# modules do not sync if they are not requested
|
240
|
-
mod = described_class.new('my_org/my_mod', '/path/to/mod', { overrides: { modules: { requested_modules: ['other_mod'] } } })
|
241
|
-
expect(mod.sync).to be false
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
describe '#install' do
|
246
|
-
it 'installs the module from the forge' do
|
247
|
-
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' })
|
248
|
-
release = instance_double('R10K::Forge::ModuleRelease')
|
249
|
-
expect(R10K::Forge::ModuleRelease).to receive(:new).with('branan-eight_hundred', '8.0.0').and_return(release)
|
250
|
-
expect(release).to receive(:install).with(subject.path)
|
251
|
-
subject.install
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe '#uninstall' do
|
256
|
-
it 'removes the module path' do
|
257
|
-
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' })
|
258
|
-
expect(FileUtils).to receive(:rm_rf).with(subject.path.to_s)
|
259
|
-
subject.uninstall
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe '#reinstall' do
|
264
|
-
it 'uninstalls and then installs the module' do
|
265
|
-
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' })
|
266
|
-
expect(subject).to receive(:uninstall)
|
267
|
-
expect(subject).to receive(:install)
|
268
|
-
subject.reinstall
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
@@ -1,387 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'r10k/module/git'
|
3
|
-
|
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
|
12
|
-
|
13
|
-
|
14
|
-
describe "statically determined version support" do
|
15
|
-
it 'returns a given commit' do
|
16
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', commit: '123adf' })
|
17
|
-
expect(static_version).to eq('123adf')
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns a given tag' do
|
21
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', tag: 'v1.2.3' })
|
22
|
-
expect(static_version).to eq('v1.2.3')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'returns a ref if it looks like a full commit sha' do
|
26
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', ref: '1234567890abcdef1234567890abcdef12345678' })
|
27
|
-
expect(static_version).to eq('1234567890abcdef1234567890abcdef12345678')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'returns nil for any non-sha-like ref' do
|
31
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', ref: 'refs/heads/main' })
|
32
|
-
expect(static_version).to eq(nil)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns nil for branches' do
|
36
|
-
static_version = described_class.statically_defined_version('branan/eight_hundred', { git: 'my/remote', branch: 'main' })
|
37
|
-
expect(static_version).to eq(nil)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "setting the owner and name" do
|
42
|
-
describe "with a title of 'branan/eight_hundred'" do
|
43
|
-
subject do
|
44
|
-
described_class.new(
|
45
|
-
'branan/eight_hundred',
|
46
|
-
'/moduledir',
|
47
|
-
{ :git => 'https://git-server.site/branan/puppet-eight_hundred' }
|
48
|
-
)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "sets the owner to 'branan'" do
|
52
|
-
expect(subject.owner).to eq 'branan'
|
53
|
-
end
|
54
|
-
|
55
|
-
it "sets the name to 'eight_hundred'" do
|
56
|
-
expect(subject.name).to eq 'eight_hundred'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "sets the path to '/moduledir/eight_hundred'" do
|
60
|
-
expect(subject.path).to eq(Pathname.new('/moduledir/eight_hundred'))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "with a title of 'modulename'" do
|
65
|
-
subject do
|
66
|
-
described_class.new(
|
67
|
-
'eight_hundred',
|
68
|
-
'/moduledir',
|
69
|
-
{ :git => 'https://git-server.site/branan/puppet-eight_hundred' }
|
70
|
-
)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "sets the owner to nil" do
|
74
|
-
expect(subject.owner).to be_nil
|
75
|
-
end
|
76
|
-
|
77
|
-
it "sets the name to 'eight_hundred'" do
|
78
|
-
expect(subject.name).to eq 'eight_hundred'
|
79
|
-
end
|
80
|
-
|
81
|
-
it "sets the path to '/moduledir/eight_hundred'" do
|
82
|
-
expect(subject.path).to eq(Pathname.new('/moduledir/eight_hundred'))
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "properties" do
|
88
|
-
subject do
|
89
|
-
described_class.new('boolean', '/moduledir', {:git => 'https://git.example.com/adrienthebo/puppet-boolean'})
|
90
|
-
end
|
91
|
-
|
92
|
-
before(:each) do
|
93
|
-
allow(mock_repo).to receive(:resolve).with('master').and_return('abc123')
|
94
|
-
allow(mock_repo).to receive(:head).and_return('abc123')
|
95
|
-
end
|
96
|
-
|
97
|
-
it "sets the module type to :git" do
|
98
|
-
expect(subject.properties).to include(:type => :git)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "sets the expected version" do
|
102
|
-
expect(subject.properties).to include(:expected => 'master')
|
103
|
-
end
|
104
|
-
|
105
|
-
it "sets the actual version to the revision when the revision is available" do
|
106
|
-
expect(mock_repo).to receive(:head).and_return('35d3517e67ceeb4b485b56d4a14d38fb95516c92')
|
107
|
-
expect(subject.properties).to include(:actual => '35d3517e67ceeb4b485b56d4a14d38fb95516c92')
|
108
|
-
end
|
109
|
-
|
110
|
-
it "sets the actual version to (unresolvable) when the revision is unavailable" do
|
111
|
-
expect(mock_repo).to receive(:head).and_return(nil)
|
112
|
-
expect(subject.properties).to include(:actual => '(unresolvable)')
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe 'syncing the repo' do
|
117
|
-
let(:module_org) { "coolorg" }
|
118
|
-
let(:module_name) { "coolmod" }
|
119
|
-
let(:title) { "#{module_org}-#{module_name}" }
|
120
|
-
let(:dirname) { Pathname.new(Dir.mktmpdir) }
|
121
|
-
let(:spec_path) { dirname + module_name + 'spec' }
|
122
|
-
subject { described_class.new(title, dirname, {}) }
|
123
|
-
|
124
|
-
before(:each) do
|
125
|
-
allow(mock_repo).to receive(:resolve).with('master').and_return('abc123')
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'defaults to keeping the spec dir' do
|
129
|
-
FileUtils.mkdir_p(spec_path)
|
130
|
-
allow(mock_repo).to receive(:sync)
|
131
|
-
subject.sync
|
132
|
-
expect(Dir.exist?(spec_path)).to eq true
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'returns true if repo was updated' do
|
136
|
-
expect(mock_repo).to receive(:sync).and_return(true)
|
137
|
-
expect(subject.sync).to be true
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'returns false if repo was not updated (in-sync)' do
|
141
|
-
expect(mock_repo).to receive(:sync).and_return(false)
|
142
|
-
expect(subject.sync).to be false
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'returns false if `should_sync?` is false' do
|
146
|
-
# modules do not sync if they are not requested
|
147
|
-
mod = described_class.new(title, dirname, { overrides: { modules: { requested_modules: ['other_mod'] } } })
|
148
|
-
expect(mod.sync).to be false
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "determining the status" do
|
153
|
-
subject do
|
154
|
-
described_class.new(
|
155
|
-
'boolean',
|
156
|
-
'/moduledir',
|
157
|
-
{ :git => 'https://git.example.com/adrienthebo/puppet-boolean' }
|
158
|
-
)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "delegates to the repo" do
|
162
|
-
expect(subject).to receive(:version).and_return 'master'
|
163
|
-
expect(mock_repo).to receive(:status).with('master').and_return :some_status
|
164
|
-
|
165
|
-
expect(subject.status).to eq(:some_status)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "option parsing" do
|
170
|
-
def test_module(extra_opts, env=nil)
|
171
|
-
described_class.new('boolean', '/moduledir', base_opts.merge(extra_opts), env)
|
172
|
-
end
|
173
|
-
|
174
|
-
let(:base_opts) { { git: 'https://git.example.com/adrienthebo/puppet-boolean' } }
|
175
|
-
|
176
|
-
before(:each) do
|
177
|
-
allow(mock_repo).to receive(:head).and_return('abc123')
|
178
|
-
end
|
179
|
-
|
180
|
-
describe "desired ref" do
|
181
|
-
context "when no desired ref is given" do
|
182
|
-
it "defaults to master" do
|
183
|
-
expect(mock_repo).to receive(:resolve).with('master').and_return('abc123')
|
184
|
-
|
185
|
-
expect(test_module({}).properties).to include(expected: 'master')
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context "specifying a static desired branch" do
|
190
|
-
let(:opts) { { branch: 'banana' } }
|
191
|
-
|
192
|
-
it "sets expected to specified branch name" do
|
193
|
-
expect(mock_repo).to receive(:resolve).with('banana').and_return('def456')
|
194
|
-
|
195
|
-
mod = test_module(opts)
|
196
|
-
expect(mod.properties).to include(expected: 'banana')
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context "specifying a static desired tag" do
|
201
|
-
let(:opts) { { tag: '1.2.3' } }
|
202
|
-
|
203
|
-
it "sets expected to specified tag" do
|
204
|
-
expect(mock_repo).to receive(:resolve).with('1.2.3').and_return('def456')
|
205
|
-
|
206
|
-
mod = test_module(opts)
|
207
|
-
expect(mod.properties).to include(expected: '1.2.3')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context "specifying a static desired commit sha" do
|
212
|
-
let(:opts) { { commit: 'ace789' } }
|
213
|
-
|
214
|
-
it "sets expected to specified commit sha" do
|
215
|
-
expect(mock_repo).to receive(:resolve).with('ace789').and_return('ace789')
|
216
|
-
|
217
|
-
mod = test_module(opts)
|
218
|
-
expect(mod.properties).to include(expected: 'ace789')
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context "specifying a static desired ref" do
|
223
|
-
before(:each) do
|
224
|
-
expect(mock_repo).to receive(:resolve).and_return('abc123')
|
225
|
-
end
|
226
|
-
|
227
|
-
it "accepts a branch name" do
|
228
|
-
mod = test_module(ref: 'banana')
|
229
|
-
expect(mod.properties).to include(expected: 'banana')
|
230
|
-
end
|
231
|
-
|
232
|
-
it "accepts a tag name" do
|
233
|
-
mod = test_module(ref: '1.2.3')
|
234
|
-
expect(mod.properties).to include(expected: '1.2.3')
|
235
|
-
end
|
236
|
-
|
237
|
-
it "accepts a commit sha" do
|
238
|
-
mod = test_module(ref: 'abc123')
|
239
|
-
expect(mod.properties).to include(expected: 'abc123')
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
context "specifying branch to :control_branch" do
|
244
|
-
let(:mock_env) { instance_double("R10K::Environment::Git", ref: 'env_branch') }
|
245
|
-
|
246
|
-
context "when module belongs to an environment and matching branch is resolvable" do
|
247
|
-
before(:each) do
|
248
|
-
expect(mock_repo).to receive(:resolve).with(mock_env.ref).and_return('abc123')
|
249
|
-
end
|
250
|
-
|
251
|
-
it "tracks environment branch" do
|
252
|
-
mod = test_module({branch: :control_branch}, mock_env)
|
253
|
-
expect(mod.properties).to include(expected: mock_env.ref)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
context "when module does not belong to an environment" do
|
258
|
-
it "leaves desired_ref unchanged" do
|
259
|
-
mod = test_module(branch: :control_branch)
|
260
|
-
expect(mod.desired_ref).to eq(:control_branch)
|
261
|
-
end
|
262
|
-
|
263
|
-
it "warns control branch may be unresolvable" do
|
264
|
-
logger = double("logger")
|
265
|
-
allow_any_instance_of(described_class).to receive(:logger).and_return(logger)
|
266
|
-
expect(logger).to receive(:warn).with(/Cannot track control repo branch.*boolean.*/)
|
267
|
-
|
268
|
-
test_module(branch: :control_branch)
|
269
|
-
end
|
270
|
-
|
271
|
-
context "when default ref is provided and resolvable" do
|
272
|
-
it "uses default ref" do
|
273
|
-
expect(mock_repo).to receive(:resolve).with('default').and_return('abc123')
|
274
|
-
mod = test_module({branch: :control_branch, default_branch: 'default'})
|
275
|
-
|
276
|
-
expect(mod.properties).to include(expected: 'default')
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
context "when default ref is provided and not resolvable" do
|
281
|
-
it "raises appropriate error" do
|
282
|
-
expect(mock_repo).to receive(:resolve).with('default').and_return(nil)
|
283
|
-
mod = test_module({branch: :control_branch, default_branch: 'default'})
|
284
|
-
|
285
|
-
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*could not resolve control repo branch.*or resolve default/i)
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
context "when default ref is not provided" do
|
290
|
-
it "raises appropriate error" do
|
291
|
-
mod = test_module({branch: :control_branch})
|
292
|
-
|
293
|
-
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*could not resolve control repo branch.*no default provided/i)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context "when module does not have matching branch" do
|
299
|
-
before(:each) do
|
300
|
-
allow(mock_repo).to receive(:resolve).with(mock_env.ref).and_return(nil)
|
301
|
-
end
|
302
|
-
|
303
|
-
context "when default ref is provided and resolvable" do
|
304
|
-
it "uses default ref" do
|
305
|
-
expect(mock_repo).to receive(:resolve).with('default').and_return('abc123')
|
306
|
-
mod = test_module({branch: :control_branch, default_branch: 'default'}, mock_env)
|
307
|
-
|
308
|
-
expect(mod.properties).to include(expected: 'default')
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
context "when default ref is provided and not resolvable" do
|
313
|
-
it "raises appropriate error" do
|
314
|
-
expect(mock_repo).to receive(:resolve).with('default').and_return(nil)
|
315
|
-
mod = test_module({branch: :control_branch, default_branch: 'default'}, mock_env)
|
316
|
-
|
317
|
-
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*could not resolve desired.*or resolve default/i)
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
context "when default ref is not provided" do
|
322
|
-
it "raises appropriate error" do
|
323
|
-
mod = test_module({branch: :control_branch}, mock_env)
|
324
|
-
|
325
|
-
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*no default provided/i)
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
context "when using default_branch_override" do
|
331
|
-
before(:each) do
|
332
|
-
allow(mock_repo).to receive(:resolve).with(mock_env.ref).and_return(nil)
|
333
|
-
end
|
334
|
-
|
335
|
-
context "and the default branch override is resolvable" do
|
336
|
-
it "uses the override" do
|
337
|
-
expect(mock_repo).to receive(:resolve).with('default_override').and_return('5566aabb')
|
338
|
-
mod = test_module({branch: :control_branch,
|
339
|
-
default_branch: 'default',
|
340
|
-
default_branch_override: 'default_override'},
|
341
|
-
mock_env)
|
342
|
-
expect(mod.properties).to include(expected: 'default_override')
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
context "and the default branch override is not resolvable" do
|
347
|
-
context "and default branch is provided" do
|
348
|
-
it "falls back to the default" do
|
349
|
-
expect(mock_repo).to receive(:resolve).with('default_override').and_return(nil)
|
350
|
-
expect(mock_repo).to receive(:resolve).with('default').and_return('5566aabb')
|
351
|
-
mod = test_module({branch: :control_branch,
|
352
|
-
default_branch: 'default',
|
353
|
-
default_branch_override: 'default_override'},
|
354
|
-
mock_env)
|
355
|
-
expect(mod.properties).to include(expected: 'default')
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
context "and default branch is not provided" do
|
360
|
-
it "raises the appropriate error" do
|
361
|
-
expect(mock_repo).to receive(:resolve).with('default_override').and_return(nil)
|
362
|
-
mod = test_module({branch: :control_branch,
|
363
|
-
default_branch_override: 'default_override'},
|
364
|
-
mock_env)
|
365
|
-
|
366
|
-
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*or resolve the default branch override.*no default provided/i)
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
context "and default branch is not resolvable" do
|
371
|
-
it "raises the appropriate error" do
|
372
|
-
expect(mock_repo).to receive(:resolve).with('default_override').and_return(nil)
|
373
|
-
expect(mock_repo).to receive(:resolve).with('default').and_return(nil)
|
374
|
-
mod = test_module({branch: :control_branch,
|
375
|
-
default_branch: 'default',
|
376
|
-
default_branch_override: 'default_override'},
|
377
|
-
mock_env)
|
378
|
-
|
379
|
-
expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*or resolve the default branch override.*or resolve default/i)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
end
|
383
|
-
end
|
384
|
-
end
|
385
|
-
end
|
386
|
-
end
|
387
|
-
end
|