3 ruby_provider = Puppet::Type.type(:archive).provider(:ruby)
5 RSpec.describe ruby_provider do
6 it_behaves_like 'an archive provider', ruby_provider
8 describe 'ruby provider' do
9 let(:name) { '/tmp/example.zip' }
10 let(:resource_properties) do
13 source: 's3://home.lan/example.zip'
16 let(:resource) { Puppet::Type::Archive.new(resource_properties) }
17 let(:provider) { ruby_provider.new(resource) }
19 let(:s3_download_options) do
20 ['s3', 'cp', 's3://home.lan/example.zip', String]
24 allow(provider).to receive(:aws)
27 context 'default resource property' do
29 provider.s3_download(name)
30 expect(provider).to have_received(:aws).with(s3_download_options)
33 it '#extract nothing' do
34 expect(provider.extract).to be_nil
38 describe '#checksum' do
39 subject { provider.checksum }
42 let(:remote_hash) { nil }
45 resource[:checksum_url] = url if url
46 allow(PuppetX::Bodeco::Util).to receive(:content) .\
47 with(url, any_args).and_return(remote_hash)
51 it { is_expected.to be_nil }
54 context 'with a url' do
55 let(:url) { 'http://example.com/checksum' }
57 context 'responds with hash' do
58 let(:remote_hash) { 'a0c38e1aeb175201b0dacd65e2f37e187657050a' }
60 it { is_expected.to eq('a0c38e1aeb175201b0dacd65e2f37e187657050a') }
62 context 'responds with hash and newline' do
63 let(:remote_hash) { "a0c38e1aeb175201b0dacd65e2f37e187657050a\n" }
65 it { is_expected.to eq('a0c38e1aeb175201b0dacd65e2f37e187657050a') }
67 context 'responds with `sha1sum README.md` output' do
68 let(:remote_hash) { "a0c38e1aeb175201b0dacd65e2f37e187657050a README.md\n" }
70 it { is_expected.to eq('a0c38e1aeb175201b0dacd65e2f37e187657050a') }
72 context 'responds with `openssl dgst -hex -sha256 README.md` output' do
73 let(:remote_hash) { "SHA256(README.md)= 8fa3f0ff1f2557657e460f0f78232679380a9bcdb8670e3dcb33472123b22428\n" }
75 it { is_expected.to eq('8fa3f0ff1f2557657e460f0f78232679380a9bcdb8670e3dcb33472123b22428') }
80 describe 'download options' do
81 let(:resource_properties) do
84 source: 's3://home.lan/example.zip',
85 download_options: ['--region', 'eu-central-1']
89 context 'default resource property' do
91 provider.s3_download(name)
92 expect(provider).to have_received(:aws).with(s3_download_options << '--region' << 'eu-central-1')