3 wget_provider = Puppet::Type.type(:archive).provider(:wget)
5 RSpec.describe wget_provider do
6 it_behaves_like 'an archive provider', wget_provider
8 describe '#download' do
9 let(:name) { '/tmp/example.zip' }
10 let(:resource) { Puppet::Type::Archive.new(resource_properties) }
11 let(:provider) { wget_provider.new(resource) }
12 let(:execution) { Puppet::Util::Execution }
14 let(:default_options) do
17 'http://home.lan/example.zip',
25 allow(FileUtils).to receive(:mv)
26 allow(execution).to receive(:execute)
29 context 'no extra properties specified' do
30 let(:resource_properties) do
33 source: 'http://home.lan/example.zip'
37 it 'calls wget with input, output and --max-redirects=5' do
38 provider.download(name)
39 expect(execution).to have_received(:execute).with(default_options.join(' '))
43 context 'username specified' do
44 let(:resource_properties) do
47 source: 'http://home.lan/example.zip',
52 it 'calls wget with default options and username' do
53 provider.download(name)
54 expect(execution).to have_received(:execute).with([default_options, '--user=foo'].join(' '))
58 context 'password specified' do
59 let(:resource_properties) do
62 source: 'http://home.lan/example.zip',
67 it 'calls wget with default options and password' do
68 provider.download(name)
69 expect(execution).to have_received(:execute).with([default_options, '--password=foo'].join(' '))
73 context 'cookie specified' do
74 let(:resource_properties) do
77 source: 'http://home.lan/example.zip',
82 it 'calls wget with default options and header containing cookie' do
83 provider.download(name)
84 expect(execution).to have_received(:execute).with([default_options, '--header="Cookie: foo"'].join(' '))
88 context 'proxy specified' do
89 let(:resource_properties) do
92 source: 'http://home.lan/example.zip',
93 proxy_server: 'https://home.lan:8080'
97 it 'calls wget with default options and header containing cookie' do
98 provider.download(name)
99 expect(execution).to have_received(:execute).with([default_options, '-e use_proxy=yes', '-e https_proxy=https://home.lan:8080'].join(' '))
103 context 'allow_insecure true' do
104 let(:resource_properties) do
107 source: 'http://home.lan/example.zip',
112 it 'calls wget with default options and --no-check-certificate' do
113 provider.download(name)
114 expect(execution).to have_received(:execute).with([default_options, '--no-check-certificate'].join(' '))
118 describe '#checksum' do
119 subject { provider.checksum }
122 let(:resource_properties) do
125 source: 'http://home.lan/example.zip'
130 resource[:checksum_url] = url if url
133 context 'with a url' do
138 'http://example.com/checksum',
143 let(:url) { 'http://example.com/checksum' }
145 context 'responds with hash' do
146 let(:remote_hash) { 'a0c38e1aeb175201b0dacd65e2f37e187657050a' }
148 it 'parses checksum value' do
149 allow(Puppet::Util::Execution).to receive(:execute).with(wget_params.join(' ')).and_return("a0c38e1aeb175201b0dacd65e2f37e187657050a README.md\n")
150 expect(provider.checksum).to eq('a0c38e1aeb175201b0dacd65e2f37e187657050a')