|
| 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 |
0 commit comments