File: tar_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (36 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'
require 'puppet/module_tool/tar'

describe Puppet::ModuleTool::Tar do
  [
    { :name => 'ObscureLinuxDistro', :win => false }, 
    { :name => 'Windows', :win => true }
  ].each do |os|
    it "always prefers minitar if it and zlib are present, even with tar available" do
      allow(Facter).to receive(:value).with('osfamily').and_return(os[:name])
      allow(Puppet::Util).to receive(:which).with('tar').and_return('/usr/bin/tar')
      allow(Puppet::Util::Platform).to receive(:windows?).and_return(os[:win])
      allow(Puppet).to receive(:features).and_return(double(:minitar? => true, :zlib? => true))

      expect(described_class.instance).to be_a_kind_of Puppet::ModuleTool::Tar::Mini
    end
  end

  it "falls back to tar when minitar not present and not on Windows" do
    allow(Facter).to receive(:value).with('osfamily').and_return('ObscureLinuxDistro')
    allow(Puppet::Util).to receive(:which).with('tar').and_return('/usr/bin/tar')
    allow(Puppet::Util::Platform).to receive(:windows?).and_return(false)
    allow(Puppet).to receive(:features).and_return(double(:minitar? => false))

    expect(described_class.instance).to be_a_kind_of Puppet::ModuleTool::Tar::Gnu
  end

  it "fails when there is no possible implementation" do
    allow(Facter).to receive(:value).with('osfamily').and_return('Windows')
    allow(Puppet::Util).to receive(:which).with('tar')
    allow(Puppet::Util::Platform).to receive(:windows?).and_return(true)
    allow(Puppet).to receive(:features).and_return(double(:minitar? => false, :zlib? => false))

    expect { described_class.instance }.to raise_error RuntimeError, /No suitable tar/
  end
end