File: shared_behaviour.rb

package info (click to toggle)
puppet-module-voxpupuli-archive 7.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 744 kB
  • sloc: ruby: 2,483; sh: 10; makefile: 4
file content (108 lines) | stat: -rw-r--r-- 3,279 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# frozen_string_literal: true

require 'spec_helper'
require 'tmpdir'

RSpec.shared_examples 'an archive provider' do |provider_class|
  describe provider_class do
    let(:resource) do
      Puppet::Type::Archive.new(name: '/tmp/example.zip', source: 'http://home.lan/example.zip')
    end

    let(:provider) do
      provider_class.new(resource)
    end

    let(:zipfile) do
      File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'files', 'test.zip'))
    end

    it '#checksum?' do
      Dir.mktmpdir do |dir|
        resource[:path] = File.join(dir, resource[:filename])
        FileUtils.cp(zipfile, resource[:path])

        resource[:checksum] = '377ec712d7fdb7266221db3441e3af2055448ead'
        resource[:checksum_type] = :sha1
        expect(provider.checksum?).to be true

        resource[:checksum] = '557e2ebb67b35d1fddff18090b6bc26b'
        resource[:checksum_type] = :md5
        expect(provider.checksum?).to be true

        resource[:checksum] = '557e2ebb67b35d1fddff18090b6bc26b'
        resource[:checksum_type] = :sha1
        expect(provider.checksum?).to be false
      end
    end

    it '#extract' do
      skip 'jruby not supported' if defined? JRUBY_VERSION
      Dir.mktmpdir do |dir|
        resource[:path] = File.join(dir, resource[:filename])
        extracted_file = File.join(dir, 'test')
        FileUtils.cp(zipfile, resource[:path])

        resource[:extract] = :true
        resource[:creates] = extracted_file
        resource[:extract_path] = dir

        provider.extract
        expect(File.read(extracted_file)).to eq "hello world\n"
      end
    end

    it '#extracted?' do
      skip 'jruby not supported' if defined? JRUBY_VERSION
      Dir.mktmpdir do |dir|
        resource[:path] = File.join(dir, resource[:filename])
        extracted_file = File.join(dir, 'test')
        FileUtils.cp(zipfile, resource[:path])

        resource[:extract] = :true
        resource[:creates] = extracted_file
        resource[:extract_path] = dir

        expect(provider.extracted?).to be false
        provider.extract
        expect(provider.extracted?).to be true
      end
    end

    it '#cleanup' do
      skip 'jruby not supported' if defined? JRUBY_VERSION
      Dir.mktmpdir do |dir|
        resource[:path] = File.join(dir, resource[:filename])
        extracted_file = File.join(dir, 'test')
        FileUtils.cp(zipfile, resource[:path])

        resource[:extract] = :true
        resource[:cleanup] = :true
        resource[:creates] = extracted_file
        resource[:extract_path] = dir

        provider.extract
        provider.cleanup
        expect(File.exist?(resource[:path])).to be false
      end
    end

    it '#create' do
      skip 'jruby not supported' if defined? JRUBY_VERSION
      Dir.mktmpdir do |dir|
        resource[:path] = File.join(dir, resource[:filename])
        extracted_file = File.join(dir, 'test')
        FileUtils.cp(zipfile, resource[:path])

        resource[:extract] = :true
        resource[:cleanup] = :true
        resource[:creates] = extracted_file
        resource[:extract_path] = dir

        provider.create
        expect(File.read(extracted_file)).to eq "hello world\n"
        expect(File.exist?(resource[:path])).to be false
      end
    end
  end
end