r10k 3.9.2 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_tests.yml +1 -1
- data/.travis.yml +0 -10
- data/CHANGELOG.mkd +33 -0
- data/README.mkd +6 -0
- data/doc/dynamic-environments/configuration.mkd +25 -0
- data/doc/dynamic-environments/usage.mkd +26 -0
- data/doc/puppetfile.mkd +18 -5
- data/integration/Rakefile +3 -1
- data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +3 -9
- data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +21 -25
- data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -3
- data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +3 -3
- data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -3
- data/lib/r10k/action/deploy/environment.rb +17 -2
- data/lib/r10k/action/deploy/module.rb +38 -7
- data/lib/r10k/action/puppetfile/check.rb +7 -5
- data/lib/r10k/action/puppetfile/install.rb +22 -16
- data/lib/r10k/action/puppetfile/purge.rb +12 -9
- data/lib/r10k/action/runner.rb +45 -10
- data/lib/r10k/cli/deploy.rb +5 -0
- data/lib/r10k/cli/puppetfile.rb +0 -1
- data/lib/r10k/content_synchronizer.rb +16 -4
- data/lib/r10k/environment/base.rb +64 -11
- data/lib/r10k/environment/with_modules.rb +6 -10
- data/lib/r10k/git/cache.rb +1 -1
- data/lib/r10k/git/rugged/credentials.rb +77 -0
- data/lib/r10k/git/stateful_repository.rb +8 -0
- data/lib/r10k/git.rb +3 -0
- data/lib/r10k/initializers.rb +4 -0
- data/lib/r10k/module/base.rb +42 -1
- data/lib/r10k/module/definition.rb +64 -0
- data/lib/r10k/module/forge.rb +17 -4
- data/lib/r10k/module/git.rb +24 -2
- data/lib/r10k/module/local.rb +2 -3
- data/lib/r10k/module/svn.rb +12 -1
- data/lib/r10k/module.rb +20 -2
- data/lib/r10k/module_loader/puppetfile/dsl.rb +42 -0
- data/lib/r10k/module_loader/puppetfile.rb +272 -0
- data/lib/r10k/puppetfile.rb +82 -160
- data/lib/r10k/settings/definition.rb +1 -1
- data/lib/r10k/settings.rb +58 -2
- data/lib/r10k/source/base.rb +10 -0
- data/lib/r10k/source/git.rb +5 -0
- data/lib/r10k/source/svn.rb +4 -0
- data/lib/r10k/util/purgeable.rb +70 -8
- data/lib/r10k/version.rb +1 -1
- data/locales/r10k.pot +165 -65
- data/r10k.gemspec +2 -0
- data/spec/fixtures/unit/action/r10k_forge_auth.yaml +4 -0
- data/spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml +3 -0
- data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +9 -0
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +9 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_subdir_2/ignored_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3 +0 -0
- data/spec/r10k-mocks/mock_env.rb +3 -0
- data/spec/r10k-mocks/mock_source.rb +7 -3
- data/spec/unit/action/deploy/environment_spec.rb +105 -30
- data/spec/unit/action/deploy/module_spec.rb +232 -42
- data/spec/unit/action/puppetfile/check_spec.rb +17 -5
- data/spec/unit/action/puppetfile/install_spec.rb +42 -36
- data/spec/unit/action/puppetfile/purge_spec.rb +15 -17
- data/spec/unit/action/runner_spec.rb +122 -26
- data/spec/unit/environment/base_spec.rb +30 -17
- data/spec/unit/environment/git_spec.rb +2 -2
- data/spec/unit/environment/svn_spec.rb +4 -3
- data/spec/unit/environment/with_modules_spec.rb +2 -1
- data/spec/unit/git/cache_spec.rb +14 -0
- data/spec/unit/git/rugged/credentials_spec.rb +29 -0
- data/spec/unit/git/stateful_repository_spec.rb +5 -0
- data/spec/unit/module/base_spec.rb +54 -8
- data/spec/unit/module/forge_spec.rb +59 -5
- data/spec/unit/module/git_spec.rb +67 -17
- data/spec/unit/module/svn_spec.rb +35 -5
- data/spec/unit/module_loader/puppetfile_spec.rb +403 -0
- data/spec/unit/module_spec.rb +28 -0
- data/spec/unit/puppetfile_spec.rb +125 -189
- data/spec/unit/settings_spec.rb +47 -2
- data/spec/unit/util/purgeable_spec.rb +38 -6
- metadata +28 -2
@@ -78,9 +78,9 @@ describe R10K::Environment::Git do
|
|
78
78
|
|
79
79
|
describe "enumerating modules" do
|
80
80
|
it "loads the Puppetfile and returns modules in that puppetfile" do
|
81
|
+
loaded = { desired_contents: [], managed_directories: [], purge_exclusions: [] }
|
81
82
|
mod = double('A module', :name => 'dbl')
|
82
|
-
expect(subject.
|
83
|
-
expect(subject.puppetfile).to receive(:modules).and_return [mod]
|
83
|
+
expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [mod]))
|
84
84
|
expect(subject.modules).to eq([mod])
|
85
85
|
end
|
86
86
|
end
|
@@ -78,9 +78,10 @@ describe R10K::Environment::SVN do
|
|
78
78
|
|
79
79
|
describe "enumerating modules" do
|
80
80
|
it "loads the Puppetfile and returns modules in that puppetfile" do
|
81
|
-
|
82
|
-
|
83
|
-
expect(subject.
|
81
|
+
loaded = { managed_directories: [], desired_contents: [], purge_exclusions: [] }
|
82
|
+
mod = double('A module', :name => 'dbl')
|
83
|
+
expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [mod]))
|
84
|
+
expect(subject.modules).to eq([mod])
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
@@ -65,8 +65,9 @@ describe R10K::Environment::WithModules do
|
|
65
65
|
|
66
66
|
describe "modules method" do
|
67
67
|
it "returns the configured modules, and Puppetfile modules" do
|
68
|
+
loaded = { managed_directories: [], desired_contents: [], purge_exclusions: [] }
|
68
69
|
puppetfile_mod = instance_double('R10K::Module::Base', name: 'zebra')
|
69
|
-
expect(subject.
|
70
|
+
expect(subject.loader).to receive(:load).and_return(loaded.merge(modules: [puppetfile_mod]))
|
70
71
|
returned_modules = subject.modules
|
71
72
|
expect(returned_modules.map(&:name).sort).to eq(%w[concat exec stdlib zebra])
|
72
73
|
end
|
data/spec/unit/git/cache_spec.rb
CHANGED
@@ -62,4 +62,18 @@ describe R10K::Git::Cache do
|
|
62
62
|
subject.cached?
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
describe "dirname sanitization" do
|
67
|
+
it 'sanitizes cache directory name' do
|
68
|
+
expect(subject.sanitized_dirname).to eq('git---some-git-remote')
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with username and password' do
|
72
|
+
subject { subclass.new('https://"user:pa$$w0rd:@some/git/remote') }
|
73
|
+
|
74
|
+
it 'sanitizes cache directory name' do
|
75
|
+
expect(subject.sanitized_dirname).to eq('https---some-git-remote')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
65
79
|
end
|
@@ -79,6 +79,35 @@ describe R10K::Git::Rugged::Credentials, :unless => R10K::Util::Platform.jruby?
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
describe "generating github app tokens" do
|
83
|
+
it 'errors if app id has invalid characters' do
|
84
|
+
expect { subject.github_app_token("123A567890", "fake", "300")
|
85
|
+
}.to raise_error(R10K::Git::GitError, /App id contains invalid characters/)
|
86
|
+
end
|
87
|
+
it 'errors if app ttl has invalid characters' do
|
88
|
+
expect { subject.github_app_token("123456", "fake", "abc")
|
89
|
+
}.to raise_error(R10K::Git::GitError, /Github App token ttl contains/)
|
90
|
+
end
|
91
|
+
it 'errors if private file does not exist' do
|
92
|
+
R10K::Git.settings[:github_app_key] = "/missing/token/file"
|
93
|
+
expect(File).to receive(:readable?).with(R10K::Git.settings[:github_app_key]).and_return false
|
94
|
+
expect {
|
95
|
+
subject.github_app_token("123456", R10K::Git.settings[:github_app_key], "300")
|
96
|
+
}.to raise_error(R10K::Git::GitError, /App key is missing or unreadable/)
|
97
|
+
end
|
98
|
+
it 'errors if file is not a valid SSL key' do
|
99
|
+
token_file = Tempfile.new('token')
|
100
|
+
token_file.write('my_token')
|
101
|
+
token_file.close
|
102
|
+
R10K::Git.settings[:github_app_key] = token_file.path
|
103
|
+
expect(File).to receive(:readable?).with(token_file.path).and_return true
|
104
|
+
expect {
|
105
|
+
subject.github_app_token("123456", R10K::Git.settings[:github_app_key], "300")
|
106
|
+
}.to raise_error(R10K::Git::GitError, /App key is not a valid SSL key/)
|
107
|
+
token_file.unlink
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
82
111
|
describe "generating token credentials" do
|
83
112
|
it 'errors if token file does not exist' do
|
84
113
|
R10K::Git.settings[:oauth_token] = "/missing/token/file"
|
@@ -19,6 +19,11 @@ describe R10K::Git::StatefulRepository do
|
|
19
19
|
expect(subject.sync_cache?(ref)).to eq true
|
20
20
|
end
|
21
21
|
|
22
|
+
it "is true if the ref is HEAD" do
|
23
|
+
expect(cache).to receive(:exist?).and_return true
|
24
|
+
expect(subject.sync_cache?('HEAD')).to eq true
|
25
|
+
end
|
26
|
+
|
22
27
|
it "is true if the ref is unresolvable" do
|
23
28
|
expect(cache).to receive(:exist?).and_return true
|
24
29
|
expect(cache).to receive(:ref_type).with('0.9.x').and_return(:unknown)
|
@@ -4,39 +4,85 @@ require 'r10k/module/base'
|
|
4
4
|
describe R10K::Module::Base do
|
5
5
|
describe "parsing the title" do
|
6
6
|
it "parses titles with no owner" do
|
7
|
-
m = described_class.new('eight_hundred', '/moduledir',
|
7
|
+
m = described_class.new('eight_hundred', '/moduledir', {})
|
8
8
|
expect(m.name).to eq 'eight_hundred'
|
9
9
|
expect(m.owner).to be_nil
|
10
10
|
end
|
11
11
|
|
12
12
|
it "parses forward slash separated titles" do
|
13
|
-
m = described_class.new('branan/eight_hundred', '/moduledir',
|
13
|
+
m = described_class.new('branan/eight_hundred', '/moduledir', {})
|
14
14
|
expect(m.name).to eq 'eight_hundred'
|
15
15
|
expect(m.owner).to eq 'branan'
|
16
16
|
end
|
17
17
|
|
18
18
|
it "parses hyphen separated titles" do
|
19
|
-
m = described_class.new('branan-eight_hundred', '/moduledir',
|
19
|
+
m = described_class.new('branan-eight_hundred', '/moduledir', {})
|
20
20
|
expect(m.name).to eq 'eight_hundred'
|
21
21
|
expect(m.owner).to eq 'branan'
|
22
22
|
end
|
23
23
|
|
24
24
|
it "raises an error when the title is not correctly formatted" do
|
25
25
|
expect {
|
26
|
-
described_class.new('branan!eight_hundred', '/moduledir',
|
26
|
+
described_class.new('branan!eight_hundred', '/moduledir', {})
|
27
27
|
}.to raise_error(ArgumentError, "Module name (branan!eight_hundred) must match either 'modulename' or 'owner/modulename'")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
describe 'deleting the spec dir' do
|
32
|
+
let(:module_org) { "coolorg" }
|
33
|
+
let(:module_name) { "coolmod" }
|
34
|
+
let(:title) { "#{module_org}-#{module_name}" }
|
35
|
+
let(:dirname) { Pathname.new(Dir.mktmpdir) }
|
36
|
+
let(:spec_path) { dirname + module_name + 'spec' }
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
logger = double("logger")
|
40
|
+
allow_any_instance_of(described_class).to receive(:logger).and_return(logger)
|
41
|
+
allow(logger).to receive(:debug2).with(any_args)
|
42
|
+
allow(logger).to receive(:info).with(any_args)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does not remove the spec directory by default' do
|
46
|
+
FileUtils.mkdir_p(spec_path)
|
47
|
+
m = described_class.new(title, dirname, {})
|
48
|
+
m.maybe_delete_spec_dir
|
49
|
+
expect(Dir.exist?(spec_path)).to eq true
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'detects a symlink and deletes the target' do
|
53
|
+
Dir.mkdir(dirname + module_name)
|
54
|
+
target_dir = Dir.mktmpdir
|
55
|
+
FileUtils.ln_s(target_dir, spec_path)
|
56
|
+
m = described_class.new(title, dirname, {exclude_spec: true})
|
57
|
+
m.maybe_delete_spec_dir
|
58
|
+
expect(Dir.exist?(target_dir)).to eq false
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'removes the spec directory if exclude_spec is set' do
|
62
|
+
FileUtils.mkdir_p(spec_path)
|
63
|
+
m = described_class.new(title, dirname, {exclude_spec: true})
|
64
|
+
m.maybe_delete_spec_dir
|
65
|
+
expect(Dir.exist?(spec_path)).to eq false
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'does not remove the spec directory if spec_deletable is false' do
|
69
|
+
FileUtils.mkdir_p(spec_path)
|
70
|
+
m = described_class.new(title, dirname, {})
|
71
|
+
m.spec_deletable = false
|
72
|
+
m.maybe_delete_spec_dir
|
73
|
+
expect(Dir.exist?(spec_path)).to eq true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
31
77
|
describe "path variables" do
|
32
78
|
it "uses the module name as the name" do
|
33
|
-
m = described_class.new('eight_hundred', '/moduledir',
|
79
|
+
m = described_class.new('eight_hundred', '/moduledir', {})
|
34
80
|
expect(m.dirname).to eq '/moduledir'
|
35
81
|
expect(m.path).to eq(Pathname.new('/moduledir/eight_hundred'))
|
36
82
|
end
|
37
83
|
|
38
84
|
it "does not include the owner in the path" do
|
39
|
-
m = described_class.new('branan/eight_hundred', '/moduledir',
|
85
|
+
m = described_class.new('branan/eight_hundred', '/moduledir', {})
|
40
86
|
expect(m.dirname).to eq '/moduledir'
|
41
87
|
expect(m.path).to eq(Pathname.new('/moduledir/eight_hundred'))
|
42
88
|
end
|
@@ -44,7 +90,7 @@ describe R10K::Module::Base do
|
|
44
90
|
|
45
91
|
describe "with alternate variable names" do
|
46
92
|
subject do
|
47
|
-
described_class.new('branan/eight_hundred', '/moduledir',
|
93
|
+
described_class.new('branan/eight_hundred', '/moduledir', {})
|
48
94
|
end
|
49
95
|
|
50
96
|
it "aliases full_name to title" do
|
@@ -61,7 +107,7 @@ describe R10K::Module::Base do
|
|
61
107
|
end
|
62
108
|
|
63
109
|
describe "accepting a visitor" do
|
64
|
-
subject { described_class.new('branan-eight_hundred', '/moduledir',
|
110
|
+
subject { described_class.new('branan-eight_hundred', '/moduledir', {}) }
|
65
111
|
|
66
112
|
it "passes itself to the visitor" do
|
67
113
|
visitor = spy('visitor')
|
@@ -9,6 +9,28 @@ describe R10K::Module::Forge do
|
|
9
9
|
let(:fixture_modulepath) { File.expand_path('spec/fixtures/module/forge', PROJECT_ROOT) }
|
10
10
|
let(:empty_modulepath) { File.expand_path('spec/fixtures/empty', PROJECT_ROOT) }
|
11
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
|
+
|
12
34
|
describe "implementing the Puppetfile spec" do
|
13
35
|
it "should implement 'branan/eight_hundred', '8.0.0'" do
|
14
36
|
expect(described_class).to be_implement('branan/eight_hundred', { version: '8.0.0' })
|
@@ -78,6 +100,7 @@ describe R10K::Module::Forge do
|
|
78
100
|
allow_any_instance_of(described_class).to receive(:logger).and_return(logger_dbl)
|
79
101
|
|
80
102
|
allow(logger_dbl).to receive(:info).with(/Deploying module to.*/)
|
103
|
+
allow(logger_dbl).to receive(:debug2).with(/No spec dir detected/)
|
81
104
|
expect(logger_dbl).to receive(:warn).with(/puppet forge module.*puppetlabs-corosync.*has been deprecated/i)
|
82
105
|
|
83
106
|
subject.sync
|
@@ -90,6 +113,7 @@ describe R10K::Module::Forge do
|
|
90
113
|
allow_any_instance_of(described_class).to receive(:logger).and_return(logger_dbl)
|
91
114
|
|
92
115
|
allow(logger_dbl).to receive(:info).with(/Deploying module to.*/)
|
116
|
+
allow(logger_dbl).to receive(:debug2).with(/No spec dir detected/)
|
93
117
|
expect(logger_dbl).to_not receive(:warn).with(/puppet forge module.*puppetlabs-corosync.*has been deprecated/i)
|
94
118
|
|
95
119
|
subject.sync
|
@@ -104,9 +128,16 @@ describe R10K::Module::Forge do
|
|
104
128
|
|
105
129
|
it "uses the latest version from the forge when the version is :latest" do
|
106
130
|
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: :latest })
|
107
|
-
|
131
|
+
release = double("Module Release", version: '8.8.8')
|
132
|
+
expect(subject.v3_module).to receive(:current_release).and_return(release).twice
|
108
133
|
expect(subject.expected_version).to eq '8.8.8'
|
109
134
|
end
|
135
|
+
|
136
|
+
it "throws when there are no available versions" do
|
137
|
+
subject = described_class.new('branan/eight_hundred', fixture_modulepath, { version: :latest })
|
138
|
+
expect(subject.v3_module).to receive(:current_release).and_return(nil)
|
139
|
+
expect { subject.expected_version }.to raise_error(PuppetForge::ReleaseNotFound)
|
140
|
+
end
|
110
141
|
end
|
111
142
|
|
112
143
|
describe "determining the status" do
|
@@ -158,31 +189,54 @@ describe R10K::Module::Forge do
|
|
158
189
|
describe "#sync" do
|
159
190
|
subject { described_class.new('branan/eight_hundred', fixture_modulepath, { version: '8.0.0' }) }
|
160
191
|
|
192
|
+
context "syncing the repo" do
|
193
|
+
let(:module_org) { "coolorg" }
|
194
|
+
let(:module_name) { "coolmod" }
|
195
|
+
let(:title) { "#{module_org}-#{module_name}" }
|
196
|
+
let(:dirname) { Pathname.new(Dir.mktmpdir) }
|
197
|
+
let(:spec_path) { dirname + module_name + 'spec' }
|
198
|
+
subject { described_class.new(title, dirname, {}) }
|
199
|
+
|
200
|
+
it 'defaults to keeping the spec dir' do
|
201
|
+
FileUtils.mkdir_p(spec_path)
|
202
|
+
expect(subject).to receive(:status).and_return(:absent)
|
203
|
+
expect(subject).to receive(:install)
|
204
|
+
subject.sync
|
205
|
+
expect(Dir.exist?(spec_path)).to eq true
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
161
209
|
it 'does nothing when the module is in sync' do
|
162
210
|
allow(subject).to receive(:status).and_return :insync
|
163
211
|
|
164
212
|
expect(subject).to receive(:install).never
|
165
213
|
expect(subject).to receive(:upgrade).never
|
166
214
|
expect(subject).to receive(:reinstall).never
|
167
|
-
subject.sync
|
215
|
+
expect(subject.sync).to be false
|
168
216
|
end
|
169
217
|
|
170
218
|
it 'reinstalls the module when it is mismatched' do
|
171
219
|
allow(subject).to receive(:status).and_return :mismatched
|
172
220
|
expect(subject).to receive(:reinstall)
|
173
|
-
subject.sync
|
221
|
+
expect(subject.sync).to be true
|
174
222
|
end
|
175
223
|
|
176
224
|
it 'upgrades the module when it is outdated' do
|
177
225
|
allow(subject).to receive(:status).and_return :outdated
|
178
226
|
expect(subject).to receive(:upgrade)
|
179
|
-
subject.sync
|
227
|
+
expect(subject.sync).to be true
|
180
228
|
end
|
181
229
|
|
182
230
|
it 'installs the module when it is absent' do
|
183
231
|
allow(subject).to receive(:status).and_return :absent
|
184
232
|
expect(subject).to receive(:install)
|
185
|
-
subject.sync
|
233
|
+
expect(subject.sync).to be true
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'returns false if `should_sync?` is false' do
|
237
|
+
# modules do not sync if they are not requested
|
238
|
+
mod = described_class.new('my_org/my_mod', '/path/to/mod', { overrides: { modules: { requested_modules: ['other_mod'] } } })
|
239
|
+
expect(mod.sync).to be false
|
186
240
|
end
|
187
241
|
end
|
188
242
|
|
@@ -10,15 +10,41 @@ describe R10K::Module::Git do
|
|
10
10
|
allow(R10K::Git::StatefulRepository).to receive(:new).and_return(mock_repo)
|
11
11
|
end
|
12
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
|
+
|
13
41
|
describe "setting the owner and name" do
|
14
42
|
describe "with a title of 'branan/eight_hundred'" do
|
15
43
|
subject do
|
16
44
|
described_class.new(
|
17
45
|
'branan/eight_hundred',
|
18
46
|
'/moduledir',
|
19
|
-
{
|
20
|
-
:git => 'git://git-server.site/branan/puppet-eight_hundred',
|
21
|
-
}
|
47
|
+
{ :git => 'git://git-server.site/branan/puppet-eight_hundred' }
|
22
48
|
)
|
23
49
|
end
|
24
50
|
|
@@ -40,9 +66,7 @@ describe R10K::Module::Git do
|
|
40
66
|
described_class.new(
|
41
67
|
'eight_hundred',
|
42
68
|
'/moduledir',
|
43
|
-
{
|
44
|
-
:git => 'git://git-server.site/branan/puppet-eight_hundred',
|
45
|
-
}
|
69
|
+
{ :git => 'git://git-server.site/branan/puppet-eight_hundred' }
|
46
70
|
)
|
47
71
|
end
|
48
72
|
|
@@ -89,14 +113,48 @@ describe R10K::Module::Git do
|
|
89
113
|
end
|
90
114
|
end
|
91
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
|
+
|
92
152
|
describe "determining the status" do
|
93
153
|
subject do
|
94
154
|
described_class.new(
|
95
155
|
'boolean',
|
96
156
|
'/moduledir',
|
97
|
-
{
|
98
|
-
:git => 'git://git.example.com/adrienthebo/puppet-boolean'
|
99
|
-
}
|
157
|
+
{ :git => 'git://git.example.com/adrienthebo/puppet-boolean' }
|
100
158
|
)
|
101
159
|
end
|
102
160
|
|
@@ -119,14 +177,6 @@ describe R10K::Module::Git do
|
|
119
177
|
allow(mock_repo).to receive(:head).and_return('abc123')
|
120
178
|
end
|
121
179
|
|
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, /cannot handle option 'unrecognized'/)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
180
|
describe "desired ref" do
|
131
181
|
context "when no desired ref is given" do
|
132
182
|
it "defaults to master" do
|