1 # rubocop:disable RSpec/MultipleExpectations
5 RSpec.shared_examples 'an archive provider' do |provider_class|
6 describe provider_class do
8 Puppet::Type::Archive.new(name: '/tmp/example.zip', source: 'http://home.lan/example.zip')
12 provider_class.new(resource)
16 File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'files', 'test.zip'))
21 resource[:path] = File.join(dir, resource[:filename])
22 FileUtils.cp(zipfile, resource[:path])
24 resource[:checksum] = '377ec712d7fdb7266221db3441e3af2055448ead'
25 resource[:checksum_type] = :sha1
26 expect(provider.checksum?).to eq true
28 resource[:checksum] = '557e2ebb67b35d1fddff18090b6bc26b'
29 resource[:checksum_type] = :md5
30 expect(provider.checksum?).to eq true
32 resource[:checksum] = '557e2ebb67b35d1fddff18090b6bc26b'
33 resource[:checksum_type] = :sha1
34 expect(provider.checksum?).to eq false
39 skip 'jruby not supported' if defined? JRUBY_VERSION
41 resource[:path] = File.join(dir, resource[:filename])
42 extracted_file = File.join(dir, 'test')
43 FileUtils.cp(zipfile, resource[:path])
45 resource[:extract] = :true
46 resource[:creates] = extracted_file
47 resource[:extract_path] = dir
50 expect(File.read(extracted_file)).to eq "hello world\n"
55 skip 'jruby not supported' if defined? JRUBY_VERSION
57 resource[:path] = File.join(dir, resource[:filename])
58 extracted_file = File.join(dir, 'test')
59 FileUtils.cp(zipfile, resource[:path])
61 resource[:extract] = :true
62 resource[:creates] = extracted_file
63 resource[:extract_path] = dir
65 expect(provider.extracted?).to eq false
67 expect(provider.extracted?).to eq true
72 skip 'jruby not supported' if defined? JRUBY_VERSION
74 resource[:path] = File.join(dir, resource[:filename])
75 extracted_file = File.join(dir, 'test')
76 FileUtils.cp(zipfile, resource[:path])
78 resource[:extract] = :true
79 resource[:cleanup] = :true
80 resource[:creates] = extracted_file
81 resource[:extract_path] = dir
85 expect(File.exist?(resource[:path])).to eq false
90 skip 'jruby not supported' if defined? JRUBY_VERSION
92 resource[:path] = File.join(dir, resource[:filename])
93 extracted_file = File.join(dir, 'test')
94 FileUtils.cp(zipfile, resource[:path])
96 resource[:extract] = :true
97 resource[:cleanup] = :true
98 resource[:creates] = extracted_file
99 resource[:extract_path] = dir
102 expect(File.read(extracted_file)).to eq "hello world\n"
103 expect(File.exist?(resource[:path])).to eq false