r10k 3.7.0 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,9 +62,10 @@ describe R10K::Environment::Git do
62
62
 
63
63
  describe "enumerating modules" do
64
64
  it "loads the Puppetfile and returns modules in that puppetfile" do
65
+ mod = double('A module', :name => 'dbl')
65
66
  expect(subject.puppetfile).to receive(:load)
66
- expect(subject.puppetfile).to receive(:modules).and_return [:modules]
67
- expect(subject.modules).to eq([:modules])
67
+ expect(subject.puppetfile).to receive(:modules).and_return [mod]
68
+ expect(subject.modules).to eq([mod])
68
69
  end
69
70
  end
70
71
 
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'r10k/environment'
3
+
4
+ describe R10K::Environment::WithModules do
5
+ subject do
6
+ described_class.new(
7
+ 'release42',
8
+ '/some/nonexistent/environmentdir',
9
+ 'prefix_release42',
10
+ {
11
+ :type => 'bare',
12
+ :modules => {
13
+ 'puppetlabs-stdlib' => { local: true },
14
+ 'puppetlabs-concat' => { local: true },
15
+ 'puppetlabs-exec' => { local: true },
16
+ }
17
+ }.merge(subject_params)
18
+ )
19
+ end
20
+
21
+ # Default no additional params
22
+ let(:subject_params) { {} }
23
+
24
+ describe "dealing with module conflicts" do
25
+ context "with no module conflicts" do
26
+ it "validates when there are no conflicts" do
27
+ mod = instance_double('R10K::Module::Base', name: 'nonconflict', origin: :puppetfile)
28
+ expect(subject.module_conflicts?(mod)).to eq false
29
+ end
30
+ end
31
+
32
+ context "with module conflicts and default behavior" do
33
+ it "does not raise an error" do
34
+ mod = instance_double('R10K::Module::Base', name: 'stdlib', origin: :puppetfile)
35
+ expect(subject.logger).to receive(:warn).with(/Puppetfile.*both define.*ignored/i)
36
+ expect(subject.module_conflicts?(mod)).to eq true
37
+ end
38
+ end
39
+
40
+ context "with module conflicts and 'error' behavior" do
41
+ let(:subject_params) {{ :module_conflicts => 'error' }}
42
+ it "raises an error" do
43
+ mod = instance_double('R10K::Module::Base', name: 'stdlib', origin: :puppetfile)
44
+ expect { subject.module_conflicts?(mod) }.to raise_error(R10K::Error, /Puppetfile.*both define.*/i)
45
+ end
46
+ end
47
+
48
+ context "with module conflicts and 'override' behavior" do
49
+ let(:subject_params) {{ :module_conflicts => 'override' }}
50
+ it "does not raise an error" do
51
+ mod = instance_double('R10K::Module::Base', name: 'stdlib', origin: :puppetfile)
52
+ expect(subject.logger).to receive(:debug).with(/Puppetfile.*both define.*ignored/i)
53
+ expect(subject.module_conflicts?(mod)).to eq true
54
+ end
55
+ end
56
+
57
+ context "with module conflicts and invalid configuration" do
58
+ let(:subject_params) {{ :module_conflicts => 'batman' }}
59
+ it "raises an error" do
60
+ mod = instance_double('R10K::Module::Base', name: 'stdlib', origin: :puppetfile)
61
+ expect { subject.module_conflicts?(mod) }.to raise_error(R10K::Error, /Unexpected value.*module_conflicts.*/i)
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "modules method" do
67
+ it "returns the configured modules, and Puppetfile modules" do
68
+ puppetfile_mod = instance_double('R10K::Module::Base', name: 'zebra')
69
+ expect(subject.puppetfile).to receive(:modules).and_return [puppetfile_mod]
70
+ returned_modules = subject.modules
71
+ expect(returned_modules.map(&:name).sort).to eq(%w[concat exec stdlib zebra])
72
+ end
73
+ end
74
+ end
@@ -10,7 +10,7 @@ describe R10K::Git::Rugged::Credentials, :unless => R10K::Util::Platform.jruby?
10
10
 
11
11
  subject { described_class.new(repo) }
12
12
 
13
- after(:all) { R10K::Git.settings.reset! }
13
+ after(:each) { R10K::Git.settings.reset! }
14
14
 
15
15
  describe "determining the username" do
16
16
  before { R10K::Git.settings[:username] = "moderns" }
@@ -39,6 +39,7 @@ describe R10K::Git::Rugged::Credentials, :unless => R10K::Util::Platform.jruby?
39
39
 
40
40
  it "prefers a per-repository SSH private key" do
41
41
  allow(File).to receive(:readable?).with("/etc/puppetlabs/r10k/ssh/tessier-ashpool-id_rsa").and_return true
42
+ R10K::Git.settings[:private_key] = "/etc/puppetlabs/r10k/ssh/id_rsa"
42
43
  R10K::Git.settings[:repositories] = [{ remote: "ssh://git@tessier-ashpool.freeside/repo.git",
43
44
  private_key: "/etc/puppetlabs/r10k/ssh/tessier-ashpool-id_rsa"}]
44
45
  creds = subject.get_ssh_key_credentials("ssh://git@tessier-ashpool.freeside/repo.git", nil)
@@ -78,6 +79,72 @@ describe R10K::Git::Rugged::Credentials, :unless => R10K::Util::Platform.jruby?
78
79
  end
79
80
  end
80
81
 
82
+ describe "generating token credentials" do
83
+ it 'errors if token file does not exist' do
84
+ R10K::Git.settings[:oauth_token] = "/missing/token/file"
85
+ expect(File).to receive(:readable?).with("/missing/token/file").and_return false
86
+ R10K::Git.settings[:repositories] = [{remote: "https://tessier-ashpool.freeside/repo.git"}]
87
+ expect {
88
+ subject.get_plaintext_credentials("https://tessier-ashpool.freeside/repo.git", nil)
89
+ }.to raise_error(R10K::Git::GitError, /cannot load OAuth token/)
90
+ end
91
+
92
+ it 'errors if the token on stdin is not a valid OAuth token' do
93
+ allow($stdin).to receive(:read).and_return("<bad>token")
94
+ R10K::Git.settings[:oauth_token] = "-"
95
+ R10K::Git.settings[:repositories] = [{remote: "https://tessier-ashpool.freeside/repo.git"}]
96
+ expect {
97
+ subject.get_plaintext_credentials("https://tessier-ashpool.freeside/repo.git", nil)
98
+ }.to raise_error(R10K::Git::GitError, /invalid characters/)
99
+ end
100
+
101
+ it 'errors if the token in the file is not a valid OAuth token' do
102
+ token_file = Tempfile.new('token')
103
+ token_file.write('my bad \ntoken')
104
+ token_file.close
105
+ R10K::Git.settings[:oauth_token] = token_file.path
106
+ R10K::Git.settings[:repositories] = [{remote: "https://tessier-ashpool.freeside/repo.git"}]
107
+ expect {
108
+ subject.get_plaintext_credentials("https://tessier-ashpool.freeside/repo.git", nil)
109
+ }.to raise_error(R10K::Git::GitError, /invalid characters/)
110
+ end
111
+
112
+ it 'prefers per-repo token file' do
113
+ token_file = Tempfile.new('token')
114
+ token_file.write('my_token')
115
+ token_file.close
116
+ R10K::Git.settings[:oauth_token] = "/do/not/use"
117
+ R10K::Git.settings[:repositories] = [{remote: "https://tessier-ashpool.freeside/repo.git",
118
+ oauth_token: token_file.path }]
119
+ creds = subject.get_plaintext_credentials("https://tessier-ashpool.freeside/repo.git", nil)
120
+ expect(creds).to be_a_kind_of(Rugged::Credentials::UserPassword)
121
+ expect(creds.instance_variable_get(:@password)).to eq("my_token")
122
+ expect(creds.instance_variable_get(:@username)).to eq("x-oauth-token")
123
+ end
124
+
125
+ it 'uses the token from a file as a password' do
126
+ token_file = Tempfile.new('token')
127
+ token_file.write('my_token')
128
+ token_file.close
129
+ R10K::Git.settings[:oauth_token] = token_file.path
130
+ R10K::Git.settings[:repositories] = [{remote: "https://tessier-ashpool.freeside/repo.git"}]
131
+ creds = subject.get_plaintext_credentials("https://tessier-ashpool.freeside/repo.git", nil)
132
+ expect(creds).to be_a_kind_of(Rugged::Credentials::UserPassword)
133
+ expect(creds.instance_variable_get(:@password)).to eq("my_token")
134
+ expect(creds.instance_variable_get(:@username)).to eq("x-oauth-token")
135
+ end
136
+
137
+ it 'uses the token from stdin as a password' do
138
+ allow($stdin).to receive(:read).and_return("my_token")
139
+ R10K::Git.settings[:oauth_token] = '-'
140
+ R10K::Git.settings[:repositories] = [{remote: "https://tessier-ashpool.freeside/repo.git"}]
141
+ creds = subject.get_plaintext_credentials("https://tessier-ashpool.freeside/repo.git", nil)
142
+ expect(creds).to be_a_kind_of(Rugged::Credentials::UserPassword)
143
+ expect(creds.instance_variable_get(:@password)).to eq("my_token")
144
+ expect(creds.instance_variable_get(:@username)).to eq("x-oauth-token")
145
+ end
146
+ end
147
+
81
148
  describe "generating default credentials" do
82
149
  it "generates the rugged default credential type" do
83
150
  creds = subject.get_default_credentials("https://azurediamond:hunter2@tessier-ashpool.freeside/repo.git", "azurediamond")
@@ -268,6 +268,61 @@ describe R10K::Module::Git do
268
268
  end
269
269
  end
270
270
  end
271
+
272
+ context "when using default_branch_override" do
273
+ before(:each) do
274
+ allow(mock_repo).to receive(:resolve).with(mock_env.ref).and_return(nil)
275
+ end
276
+
277
+ context "and the default branch override is resolvable" do
278
+ it "uses the override" do
279
+ expect(mock_repo).to receive(:resolve).with('default_override').and_return('5566aabb')
280
+ mod = test_module({branch: :control_branch,
281
+ default_branch: 'default',
282
+ default_branch_override: 'default_override'},
283
+ mock_env)
284
+ expect(mod.properties).to include(expected: 'default_override')
285
+ end
286
+ end
287
+
288
+ context "and the default branch override is not resolvable" do
289
+ context "and default branch is provided" do
290
+ it "falls back to the default" do
291
+ expect(mock_repo).to receive(:resolve).with('default_override').and_return(nil)
292
+ expect(mock_repo).to receive(:resolve).with('default').and_return('5566aabb')
293
+ mod = test_module({branch: :control_branch,
294
+ default_branch: 'default',
295
+ default_branch_override: 'default_override'},
296
+ mock_env)
297
+ expect(mod.properties).to include(expected: 'default')
298
+ end
299
+ end
300
+
301
+ context "and default branch is not provided" do
302
+ it "raises the appropriate error" do
303
+ expect(mock_repo).to receive(:resolve).with('default_override').and_return(nil)
304
+ mod = test_module({branch: :control_branch,
305
+ default_branch_override: 'default_override'},
306
+ mock_env)
307
+
308
+ expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*or resolve the default branch override.*no default provided/i)
309
+ end
310
+ end
311
+
312
+ context "and default branch is not resolvable" do
313
+ it "raises the appropriate error" do
314
+ expect(mock_repo).to receive(:resolve).with('default_override').and_return(nil)
315
+ expect(mock_repo).to receive(:resolve).with('default').and_return(nil)
316
+ mod = test_module({branch: :control_branch,
317
+ default_branch: 'default',
318
+ default_branch_override: 'default_override'},
319
+ mock_env)
320
+
321
+ expect { mod.properties }.to raise_error(ArgumentError, /unable to manage.*or resolve the default branch override.*or resolve default/i)
322
+ end
323
+ end
324
+ end
325
+ end
271
326
  end
272
327
  end
273
328
  end
@@ -128,23 +128,15 @@ describe R10K::Puppetfile do
128
128
  expect { subject.add_module('puppet/test_module', module_opts) }.to raise_error(R10K::Error, /cannot manage content.*is not within/i).and not_change { subject.modules }
129
129
  end
130
130
 
131
- it "groups modules by vcs cache location" do
132
- module_opts = { install_path: File.join(subject.basedir, 'vendor') }
133
- opts1 = module_opts.merge(git: 'git@example.com:puppet/test_module.git')
134
- opts2 = module_opts.merge(git: 'git@example.com:puppet/test_module_c.git')
135
- sanitized_name1 = "git@example.com-puppet-test_module.git"
136
- sanitized_name2 = "git@example.com-puppet-test_module_c.git"
131
+ it "should disable and not add modules that conflict with the environment" do
132
+ env = instance_double('R10K::Environment::Base')
133
+ mod = instance_double('R10K::Module::Base', name: 'conflict', origin: :puppetfile)
134
+ allow(mod).to receive(:origin=).and_return(nil)
135
+ allow(subject).to receive(:environment).and_return(env)
136
+ allow(env).to receive(:'module_conflicts?').with(mod).and_return(true)
137
137
 
138
- subject.add_module('puppet/test_module_a', opts1)
139
- subject.add_module('puppet/test_module_b', opts1)
140
- subject.add_module('puppet/test_module_c', opts2)
141
- subject.add_module('puppet/test_module_d', '1.2.3')
142
-
143
- mods_by_cachedir = subject.modules_by_vcs_cachedir
144
-
145
- expect(mods_by_cachedir[:none].length).to be 1
146
- expect(mods_by_cachedir[sanitized_name1].length).to be 2
147
- expect(mods_by_cachedir[sanitized_name2].length).to be 1
138
+ allow(R10K::Module).to receive(:new).with('test', anything, anything, anything).and_return(mod)
139
+ expect { subject.add_module('test', {}) }.not_to change { subject.modules }
148
140
  end
149
141
  end
150
142
 
@@ -283,7 +275,8 @@ describe R10K::Puppetfile do
283
275
  default_branch_override = 'default_branch_override_name'
284
276
  expect { subject.load!(default_branch_override) }.not_to raise_error
285
277
  git_module = subject.modules[0]
286
- expect(git_module.default_ref).to eq default_branch_override
278
+ expect(git_module.default_override_ref).to eq default_branch_override
279
+ expect(git_module.default_ref).to eq "here_lies_the_default_branch"
287
280
  end
288
281
  end
289
282
 
@@ -302,12 +295,12 @@ describe R10K::Puppetfile do
302
295
  block.call
303
296
  end
304
297
 
305
- mod1 = spy('module')
298
+ mod1 = instance_double('R10K::Module::Base', :cachedir => :none)
299
+ mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
306
300
  expect(mod1).to receive(:accept).with(visitor)
307
- mod2 = spy('module')
308
301
  expect(mod2).to receive(:accept).with(visitor)
302
+ expect(subject).to receive(:modules).and_return([mod1, mod2])
309
303
 
310
- expect(subject).to receive(:modules_by_vcs_cachedir).and_return({none: [mod1, mod2]})
311
304
  subject.accept(visitor)
312
305
  end
313
306
 
@@ -323,12 +316,11 @@ describe R10K::Puppetfile do
323
316
  block.call
324
317
  end
325
318
 
326
- mod1 = spy('module')
319
+ mod1 = instance_double('R10K::Module::Base', :cachedir => :none)
320
+ mod2 = instance_double('R10K::Module::Base', :cachedir => :none)
327
321
  expect(mod1).to receive(:accept).with(visitor)
328
- mod2 = spy('module')
329
322
  expect(mod2).to receive(:accept).with(visitor)
330
-
331
- expect(subject).to receive(:modules_by_vcs_cachedir).and_return({none: [mod1, mod2]})
323
+ expect(subject).to receive(:modules).and_return([mod1, mod2])
332
324
 
333
325
  expect(Thread).to receive(:new).exactly(pool_size).and_call_original
334
326
  expect(Queue).to receive(:new).and_call_original
@@ -344,22 +336,19 @@ describe R10K::Puppetfile do
344
336
  block.call
345
337
  end
346
338
 
347
- mod1 = spy('module1')
348
- mod2 = spy('module2')
349
- mod3 = spy('module3')
350
- mod4 = spy('module4')
351
- mod5 = spy('module5')
352
- mod6 = spy('module6')
339
+ m1 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/A')
340
+ m2 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/B')
341
+ m3 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
342
+ m4 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/C')
343
+ m5 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
344
+ m6 = instance_double('R10K::Module::Base', :cachedir => '/dev/null/D')
353
345
 
354
- expect(subject).to receive(:modules_by_vcs_cachedir)
355
- .and_return({:none => [mod1, mod2],
356
- "foo-cachedir" => [mod3, mod4],
357
- "bar-cachedir" => [mod5, mod6]})
346
+ expect(subject).to receive(:modules).and_return([m1, m2, m3, m4, m5, m6])
358
347
 
359
348
  queue = subject.modules_queue(visitor)
360
349
  expect(queue.length).to be 4
361
350
  queue_array = 4.times.map { queue.pop }
362
- expect(queue_array).to match_array([[mod1], [mod2], [mod3, mod4], [mod5, mod6]])
351
+ expect(queue_array).to match_array([[m1], [m2], [m3, m4], [m5, m6]])
363
352
  end
364
353
  end
365
354
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-13 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -448,6 +448,7 @@ files:
448
448
  - spec/fixtures/module/forge/eight_hundred/metadata.json
449
449
  - spec/fixtures/unit/action/r10k.yaml
450
450
  - spec/fixtures/unit/action/r10k_cachedir.yaml
451
+ - spec/fixtures/unit/action/r10k_creds.yaml
451
452
  - spec/fixtures/unit/action/r10k_generate_types.yaml
452
453
  - spec/fixtures/unit/action/r10k_puppet_path.yaml
453
454
  - spec/fixtures/unit/puppetfile/argument-error/Puppetfile
@@ -506,6 +507,7 @@ files:
506
507
  - spec/unit/environment/git_spec.rb
507
508
  - spec/unit/environment/name_spec.rb
508
509
  - spec/unit/environment/svn_spec.rb
510
+ - spec/unit/environment/with_modules_spec.rb
509
511
  - spec/unit/errors/formatting_spec.rb
510
512
  - spec/unit/feature_spec.rb
511
513
  - spec/unit/forge/module_release_spec.rb