puppetfile-resolver 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/puppetfile-resolver/data/ruby_ca_certs.pem +732 -851
  4. data/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb +8 -2
  5. data/lib/puppetfile-resolver/resolution_provider.rb +15 -8
  6. data/lib/puppetfile-resolver/resolution_result.rb +1 -1
  7. data/lib/puppetfile-resolver/resolver.rb +3 -2
  8. data/lib/puppetfile-resolver/spec_searchers/configuration.rb +21 -0
  9. data/lib/puppetfile-resolver/spec_searchers/forge.rb +17 -19
  10. data/lib/puppetfile-resolver/spec_searchers/forge_configuration.rb +17 -0
  11. data/lib/puppetfile-resolver/spec_searchers/git/gclone.rb +82 -0
  12. data/lib/puppetfile-resolver/spec_searchers/git/github.rb +53 -0
  13. data/lib/puppetfile-resolver/spec_searchers/git/gitlab.rb +55 -0
  14. data/lib/puppetfile-resolver/spec_searchers/git.rb +16 -34
  15. data/lib/puppetfile-resolver/spec_searchers/git_configuration.rb +9 -0
  16. data/lib/puppetfile-resolver/spec_searchers/local.rb +3 -2
  17. data/lib/puppetfile-resolver/spec_searchers/local_configuration.rb +13 -0
  18. data/lib/puppetfile-resolver/util.rb +43 -0
  19. data/lib/puppetfile-resolver/version.rb +1 -1
  20. data/puppetfile-cli.rb +14 -1
  21. data/spec/fixtures/modulepath/test_module/README.md +1 -0
  22. data/spec/fixtures/modulepath/test_module/metadata.json +9 -0
  23. data/spec/fixtures/proxy.rb +9 -0
  24. data/spec/integration/deprecation_spec.rb +32 -0
  25. data/spec/integration/kitchensink_spec.rb +49 -0
  26. data/spec/integration/proxy_spec.rb +91 -0
  27. data/spec/spec_helper.rb +2 -0
  28. data/spec/unit/puppetfile-resolver/puppetfile/parser/r10k_eval_spec.rb +19 -4
  29. data/spec/unit/puppetfile-resolver/resolver_spec.rb +44 -1
  30. data/spec/unit/puppetfile-resolver/spec_searchers/git/gclone_spec.rb +50 -0
  31. metadata +29 -8
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "testfixture-test_module",
3
+ "version": "0.1.0",
4
+ "author": "testfixture",
5
+ "summary": "Skeleton module test fixture",
6
+ "license": "Apache-2.0",
7
+ "source": "http://localhost",
8
+ "dependencies": []
9
+ }
@@ -0,0 +1,9 @@
1
+ require 'webrick'
2
+ require 'webrick/httpproxy'
3
+
4
+ proxy = WEBrick::HTTPProxyServer.new Port: (ARGV[0].nil? ? 32768 : ARGV[0])
5
+
6
+ trap 'INT' do proxy.shutdown end
7
+ trap 'TERM' do proxy.shutdown end
8
+
9
+ proxy.start
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ require 'puppetfile-resolver/resolver'
4
+ require 'puppetfile-resolver/puppetfile'
5
+
6
+
7
+ describe 'Depreaction Tests' do
8
+ context 'With module_paths option' do
9
+ it 'should resolve a complete Puppetfile' do
10
+
11
+ content = <<-PUPFILE
12
+ forge 'https://forge.puppet.com'
13
+
14
+ # Local module path module
15
+ mod 'testfixture/test_module', :latest
16
+ PUPFILE
17
+
18
+ puppetfile = ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)
19
+ resolver = PuppetfileResolver::Resolver.new(puppetfile)
20
+
21
+ expect(Warning).to receive(:warn).with(/module_paths/).and_return(nil)
22
+
23
+ result = resolver.resolve({
24
+ allow_missing_modules: false,
25
+ module_paths: [File.join(FIXTURES_DIR, 'modulepath')]
26
+ })
27
+
28
+ expect(result.specifications).to include('test_module')
29
+ expect(result.specifications['test_module'].version.to_s).to eq('0.1.0')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ require 'puppetfile-resolver/resolver'
4
+ require 'puppetfile-resolver/puppetfile'
5
+
6
+ describe 'KitchenSink Tests' do
7
+ it 'should resolve a complete Puppetfile' do
8
+ content = <<-PUPFILE
9
+ forge 'https://forge.puppet.com'
10
+
11
+ mod 'powershell',
12
+ :git => 'https://github.com/puppetlabs/puppetlabs-powershell',
13
+ :tag => 'v4.0.0'
14
+
15
+ mod 'simpkv',
16
+ :git => 'https://gitlab.com/simp/pupmod-simp-simpkv.git',
17
+ :tag => '0.7.1'
18
+
19
+ mod 'puppetlabs/stdlib', '6.3.0'
20
+
21
+ # Local module path module
22
+ mod 'testfixture/test_module', :latest
23
+
24
+ PUPFILE
25
+
26
+ puppetfile = ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)
27
+
28
+ config = PuppetfileResolver::SpecSearchers::Configuration.new
29
+ config.local.puppet_module_paths = [File.join(FIXTURES_DIR, 'modulepath')]
30
+
31
+ resolver = PuppetfileResolver::Resolver.new(puppetfile)
32
+ result = resolver.resolve({
33
+ allow_missing_modules: false,
34
+ spec_searcher_configuration: config,
35
+ })
36
+
37
+ expect(result.specifications).to include('powershell')
38
+ expect(result.specifications['powershell'].version.to_s).to eq('4.0.0')
39
+
40
+ expect(result.specifications).to include('simpkv')
41
+ expect(result.specifications['simpkv'].version.to_s).to eq('0.7.1')
42
+
43
+ expect(result.specifications).to include('stdlib')
44
+ expect(result.specifications['stdlib'].version.to_s).to eq('6.3.0')
45
+
46
+ expect(result.specifications).to include('test_module')
47
+ expect(result.specifications['test_module'].version.to_s).to eq('0.1.0')
48
+ end
49
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'open3'
3
+ require 'puppetfile-resolver/resolver'
4
+ require 'puppetfile-resolver/puppetfile'
5
+
6
+ describe 'Proxy Tests' do
7
+ let(:content) do <<-PUPFILE
8
+ forge 'https://forge.puppet.com'
9
+
10
+ mod 'powershell',
11
+ :git => 'https://github.com/puppetlabs/puppetlabs-powershell',
12
+ :tag => 'v4.0.0'
13
+
14
+ mod 'puppetlabs/stdlib', '6.3.0'
15
+ PUPFILE
16
+ end
17
+ let(:puppetfile) { ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content) }
18
+ let(:resolver_config) do
19
+ PuppetfileResolver::SpecSearchers::Configuration.new.tap do |obj|
20
+ obj.git.proxy = 'http://localhost:32768'
21
+ obj.forge.proxy = 'http://localhost:32768'
22
+ end
23
+ end
24
+
25
+ context 'with an invalid proxy server' do
26
+ it 'should not resolve a complete Puppetfile' do
27
+ resolver = PuppetfileResolver::Resolver.new(puppetfile)
28
+ result = resolver.resolve({
29
+ allow_missing_modules: true,
30
+ spec_searcher_configuration: resolver_config,
31
+ })
32
+
33
+ expect(result.specifications).to include('powershell')
34
+ expect(result.specifications['powershell']).to be_a(PuppetfileResolver::Models::MissingModuleSpecification)
35
+
36
+ expect(result.specifications).to include('stdlib')
37
+ expect(result.specifications['stdlib']).to be_a(PuppetfileResolver::Models::MissingModuleSpecification)
38
+ end
39
+ end
40
+
41
+ context 'with a valid proxy server' do
42
+ def start_proxy_server(start_options = ['--timeout=5'])
43
+ cmd = "ruby \"#{File.join(FIXTURES_DIR, 'proxy.rb')}\" 32768"
44
+
45
+ stdin, stdout, stderr, wait_thr = Open3.popen3(cmd)
46
+ # Wait for the Proxy server to indicate it started
47
+ line = nil
48
+ begin
49
+ line = stderr.readline
50
+ end until line =~ /#start/
51
+ stdout.close
52
+ stdin.close
53
+ [wait_thr, stderr]
54
+ end
55
+
56
+ before(:each) do
57
+ @server_thr, @server_pipe = start_proxy_server
58
+ end
59
+
60
+ after(:each) do
61
+ begin
62
+ Process.kill("KILL", @server_thr[:pid])
63
+ Process.wait(@server_thr[:pid])
64
+ rescue
65
+ # The server process may not exist and checking in a cross platform way in ruby is difficult
66
+ # Instead just swallow any errors
67
+ end
68
+
69
+ begin
70
+ @server_pipe.close
71
+ rescue
72
+ # The server process may not exist and checking in a cross platform way in ruby is difficult
73
+ # Instead just swallow any errors
74
+ end
75
+ end
76
+
77
+ it 'should resolve a complete Puppetfile' do
78
+ resolver = PuppetfileResolver::Resolver.new(puppetfile)
79
+ result = resolver.resolve({
80
+ allow_missing_modules: false,
81
+ spec_searcher_configuration: resolver_config,
82
+ })
83
+
84
+ expect(result.specifications).to include('powershell')
85
+ expect(result.specifications['powershell'].version.to_s).to eq('4.0.0')
86
+
87
+ expect(result.specifications).to include('stdlib')
88
+ expect(result.specifications['stdlib'].version.to_s).to eq('6.3.0')
89
+ end
90
+ end
91
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,8 @@ root = File.join(__dir__,'..',)
4
4
  # Add the language server into the load path
5
5
  $LOAD_PATH.unshift(File.join(root,'lib'))
6
6
 
7
+ FIXTURES_DIR = File.join(__dir__,'fixtures')
8
+
7
9
  # A cache which we can preload for the purposes of testing, mimicing
8
10
  # Local modules
9
11
  require 'puppetfile-resolver/cache/base'
@@ -29,6 +29,8 @@ RSpec.shared_examples "a puppetfile parser with valid content" do
29
29
  mod 'local', :local => 'some/path'
30
30
 
31
31
  mod 'svn_min', :svn => 'some-svn-repo'
32
+
33
+ mod 'puppetlabs-forge_missing'
32
34
  EOT
33
35
  end
34
36
 
@@ -47,7 +49,7 @@ RSpec.shared_examples "a puppetfile parser with valid content" do
47
49
  end
48
50
 
49
51
  it "should detect all of the modules" do
50
- expect(puppetfile.modules.count).to eq(8)
52
+ expect(puppetfile.modules.count).to eq(9)
51
53
  end
52
54
 
53
55
  it "should not set any resolver flags" do
@@ -62,7 +64,7 @@ RSpec.shared_examples "a puppetfile parser with valid content" do
62
64
  expect(mod.title).to eq('puppetlabs-forge_fixed_ver')
63
65
  expect(mod.owner).to eq('puppetlabs')
64
66
  expect(mod.name).to eq('forge_fixed_ver')
65
- expect(mod.version).to eq('1.0.0')
67
+ expect(mod.version).to eq('=1.0.0')
66
68
  expect(mod.location.start_line).to eq(2)
67
69
  expect(mod.location.start_char).to be_nil
68
70
  expect(mod.location.end_line).to eq(2)
@@ -82,6 +84,20 @@ RSpec.shared_examples "a puppetfile parser with valid content" do
82
84
  expect(mod.location.end_line).to eq(3)
83
85
  expect(mod.location.end_char).to be_nil
84
86
  end
87
+
88
+ it 'should detect missing latest version modules as latest' do
89
+ mod = get_module(puppetfile, 'puppetlabs-forge_missing')
90
+
91
+ expect(mod.module_type).to eq(PuppetfileResolver::Puppetfile::FORGE_MODULE)
92
+ expect(mod.title).to eq('puppetlabs-forge_missing')
93
+ expect(mod.owner).to eq('puppetlabs')
94
+ expect(mod.name).to eq('forge_missing')
95
+ expect(mod.version).to eq(:latest)
96
+ expect(mod.location.start_line).to eq(25)
97
+ expect(mod.location.start_char).to be_nil
98
+ expect(mod.location.end_line).to eq(25)
99
+ expect(mod.location.end_char).to be_nil
100
+ end
85
101
  end
86
102
 
87
103
  context 'with Git modules' do
@@ -379,7 +395,6 @@ RSpec.shared_examples "a puppetfile parser with invalid content" do
379
395
  forge 'https://fake-forge.puppetlabs.com/'
380
396
 
381
397
  mod 'puppetlabs-bad_version', 'b.c.d'
382
- mod 'puppetlabs-missing_version'
383
398
 
384
399
  mod 'bad_args',
385
400
  :gitx => 'git@github.com:puppetlabs/puppetlabs-git_ref.git'
@@ -393,7 +408,7 @@ RSpec.shared_examples "a puppetfile parser with invalid content" do
393
408
  end
394
409
 
395
410
  it "should detect all of the invalid modules" do
396
- expect(puppetfile.modules.count).to eq(3)
411
+ expect(puppetfile.modules.count).to eq(2)
397
412
 
398
413
  puppetfile.modules.each do |mod|
399
414
  expect(mod).to have_attributes(:module_type => PuppetfileResolver::Puppetfile::INVALID_MODULE)
@@ -7,7 +7,7 @@ describe PuppetfileResolver::Resolver do
7
7
  let(:puppet_version) { nil }
8
8
  let(:subject) { PuppetfileResolver::Resolver.new(puppetfile_document, puppet_version) }
9
9
  let(:cache) { MockLocalModuleCache.new }
10
- let(:default_resolve_options) { { cache: cache, module_paths: ['??does/not/exist'] } }
10
+ let(:default_resolve_options) { { cache: cache } }
11
11
  let(:resolve_options) { default_resolve_options }
12
12
 
13
13
  RSpec.shared_examples 'a resolver flag' do |flag|
@@ -245,6 +245,49 @@ describe PuppetfileResolver::Resolver do
245
245
  end
246
246
  end
247
247
 
248
+ context "Given a document with resolvable version range dependencies" do
249
+ [
250
+ { range: '> 1.0.0 < 3.0.0', expected_version: '2.0.0' },
251
+ { range: '< 2.5.0', expected_version: '2.0.0' },
252
+ { range: '<= 2.0.0', expected_version: '2.0.0' },
253
+ { range: '>= 2.0.0', expected_version: '3.0.0' },
254
+ { range: '= 1.0.0', expected_version: '1.0.0' },
255
+ { range: :latest, expected_version: '3.0.0' },
256
+ { range: nil, expected_version: '3.0.0' }
257
+ ].each do |range_testcase|
258
+ describe "With a range of '#{range_testcase[:range]}'" do
259
+ let(:puppetfile_document) do
260
+ doc = valid_document('foo')
261
+ doc.add_module(PuppetfileResolver::Puppetfile::LocalModule.new('module1').tap { |o| o.version = range_testcase[:range] })
262
+ doc
263
+ end
264
+
265
+ before(:each) do
266
+ cache.add_local_module_spec('module1', [], nil, '1.0.0')
267
+ cache.add_local_module_spec('module1', [], nil, '2.0.0')
268
+ cache.add_local_module_spec('module1', [], nil, '3.0.0')
269
+ end
270
+
271
+ [true, false].each do |testcase|
272
+ context "and Allow Missing Modules option is #{testcase}" do
273
+ let(:resolve_options) { default_resolve_options.merge(allow_missing_modules: testcase) }
274
+
275
+ it 'should resolve without error' do
276
+ expect{ subject.resolve(resolve_options) }.to_not raise_error
277
+ end
278
+
279
+ it 'should resolve with found module specifications' do
280
+ result = subject.resolve(resolve_options)
281
+
282
+ expect(result.specifications).to include('module1')
283
+ expect(result.specifications['module1'].version.to_s).to eq(range_testcase[:expected_version])
284
+ end
285
+ end
286
+ end
287
+ end
288
+ end
289
+ end
290
+
248
291
  context "Given a document with a resolvable Puppet requirement" do
249
292
  let(:puppet_version) { '3.0.0' }
250
293
  let(:puppetfile_document) do
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'puppetfile-resolver/spec_searchers/git/gclone'
3
+ require 'puppetfile-resolver/spec_searchers/git_configuration'
4
+ require 'logger'
5
+ require 'json'
6
+
7
+ describe PuppetfileResolver::SpecSearchers::Git::GClone do
8
+ PuppetfileModule = Struct.new(:remote, :ref, :branch, :commit, :tag, keyword_init: true)
9
+ config = PuppetfileResolver::SpecSearchers::Configuration.new
10
+ config.local.puppet_module_paths = [File.join(FIXTURES_DIR, 'modulepath')]
11
+
12
+ let(:url) do
13
+ 'https://github.com/puppetlabs/puppetlabs-powershell'
14
+ end
15
+
16
+ let(:puppetfile_module) do
17
+ PuppetfileModule.new(remote: url)
18
+ end
19
+
20
+
21
+ context 'valid url' do
22
+ it 'reads metadata' do
23
+ content = subject.metadata(puppetfile_module, Logger.new(STDERR), config)
24
+ expect(JSON.parse(content)['name']).to eq('puppetlabs-powershell')
25
+ end
26
+
27
+ context 'with ref' do
28
+
29
+ let(:puppetfile_module) do
30
+ PuppetfileModule.new(remote: url, ref: '2.1.2')
31
+ end
32
+
33
+ it 'reads metadata' do
34
+ content = subject.metadata(puppetfile_module, Logger.new(STDERR), config)
35
+ expect(JSON.parse(content)['name']).to eq('puppetlabs-powershell')
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'invalid url' do
41
+ let(:url) do
42
+ 'https://github.com/puppetlabs/puppetlabs-powershellbad'
43
+ end
44
+
45
+ it 'throws exception' do
46
+ expect{subject.metadata(puppetfile_module, Logger.new(STDERR), config)}
47
+ .to raise_exception(RuntimeError)
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetfile-resolver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Sarti
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-11 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: molinillo
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  description: Resolves the Puppet Modules in a Puppetfile with a full dependency graph,
42
- including Puppet version checkspec.
42
+ including Puppet version checks.
43
43
  email:
44
44
  - glennsarti@users.noreply.github.com
45
45
  executables: []
@@ -81,23 +81,37 @@ files:
81
81
  - lib/puppetfile-resolver/resolution_result.rb
82
82
  - lib/puppetfile-resolver/resolver.rb
83
83
  - lib/puppetfile-resolver/spec_searchers/common.rb
84
+ - lib/puppetfile-resolver/spec_searchers/configuration.rb
84
85
  - lib/puppetfile-resolver/spec_searchers/forge.rb
86
+ - lib/puppetfile-resolver/spec_searchers/forge_configuration.rb
85
87
  - lib/puppetfile-resolver/spec_searchers/git.rb
88
+ - lib/puppetfile-resolver/spec_searchers/git/gclone.rb
89
+ - lib/puppetfile-resolver/spec_searchers/git/github.rb
90
+ - lib/puppetfile-resolver/spec_searchers/git/gitlab.rb
91
+ - lib/puppetfile-resolver/spec_searchers/git_configuration.rb
86
92
  - lib/puppetfile-resolver/spec_searchers/local.rb
93
+ - lib/puppetfile-resolver/spec_searchers/local_configuration.rb
87
94
  - lib/puppetfile-resolver/ui/debug_ui.rb
88
95
  - lib/puppetfile-resolver/ui/null_ui.rb
89
96
  - lib/puppetfile-resolver/util.rb
90
97
  - lib/puppetfile-resolver/version.rb
91
98
  - puppetfile-cli.rb
99
+ - spec/fixtures/modulepath/test_module/README.md
100
+ - spec/fixtures/modulepath/test_module/metadata.json
101
+ - spec/fixtures/proxy.rb
102
+ - spec/integration/deprecation_spec.rb
103
+ - spec/integration/kitchensink_spec.rb
104
+ - spec/integration/proxy_spec.rb
92
105
  - spec/spec_helper.rb
93
106
  - spec/unit/puppetfile-resolver/puppetfile/document_spec.rb
94
107
  - spec/unit/puppetfile-resolver/puppetfile/parser/r10k_eval_spec.rb
95
108
  - spec/unit/puppetfile-resolver/resolver_spec.rb
109
+ - spec/unit/puppetfile-resolver/spec_searchers/git/gclone_spec.rb
96
110
  homepage: https://glennsarti.github.io/puppetfile-resolver/
97
111
  licenses:
98
112
  - Apache-2.0
99
113
  metadata: {}
100
- post_install_message:
114
+ post_install_message:
101
115
  rdoc_options: []
102
116
  require_paths:
103
117
  - lib
@@ -105,19 +119,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
119
  requirements:
106
120
  - - ">="
107
121
  - !ruby/object:Gem::Version
108
- version: 2.1.9
122
+ version: 2.5.3
109
123
  required_rubygems_version: !ruby/object:Gem::Requirement
110
124
  requirements:
111
125
  - - ">="
112
126
  - !ruby/object:Gem::Version
113
127
  version: '0'
114
128
  requirements: []
115
- rubygems_version: 3.1.2
116
- signing_key:
129
+ rubygems_version: 3.1.4
130
+ signing_key:
117
131
  specification_version: 4
118
132
  summary: Dependency resolver for Puppetfiles
119
133
  test_files:
134
+ - spec/fixtures/modulepath/test_module/metadata.json
135
+ - spec/fixtures/modulepath/test_module/README.md
136
+ - spec/fixtures/proxy.rb
137
+ - spec/integration/deprecation_spec.rb
138
+ - spec/integration/kitchensink_spec.rb
139
+ - spec/integration/proxy_spec.rb
120
140
  - spec/spec_helper.rb
121
141
  - spec/unit/puppetfile-resolver/puppetfile/document_spec.rb
122
142
  - spec/unit/puppetfile-resolver/puppetfile/parser/r10k_eval_spec.rb
123
143
  - spec/unit/puppetfile-resolver/resolver_spec.rb
144
+ - spec/unit/puppetfile-resolver/spec_searchers/git/gclone_spec.rb