| 
17 | 17 |   before :each do  | 
18 | 18 |     # Stub some provider methods to avoid needing the actual software  | 
19 | 19 |     # installed, so we can test on whatever platform we want.  | 
20 |  | -    #allow(Puppet::Util).to receive(:which).with("pkg_info").and_return("/usr/sbin/pkg_info")  | 
21 |  | -    allow(described_class).to receive(:yalla).with("pkg_info").and_return("/usr/sbin/pkg_info")  | 
22 |  | -    allow(described_class).to receive(:command).with(:pkginfo).and_return('/usr/sbin/pkg_info')  | 
23 |  | -    allow(described_class).to receive(:command).with(:pkgadd).and_return('/usr/sbin/pkg_add')  | 
24 |  | -    allow(described_class).to receive(:command).with(:pkgdelete).and_return('/usr/sbin/pkg_delete')  | 
 | 20 | +    allow(described_class).to receive(:command).with(:pkginfo).and_return('/bin/pkg_info')  | 
 | 21 | +    allow(described_class).to receive(:command).with(:pkgadd).and_return('/bin/pkg_add')  | 
 | 22 | +    allow(described_class).to receive(:command).with(:pkgdelete).and_return('/bin/pkg_delete')  | 
25 | 23 |   end  | 
26 | 24 | 
 
  | 
27 | 25 |   context "#instances" do  | 
28 | 26 |     it "should return nil if execution failed" do  | 
29 |  | -      allow(provider).to receive(:command).with(:pkginfo).and_return('/usr/sbin/pkg_info')  | 
30 |  | -      expect(provider).to receive(:pkginfo).and_raise(Puppet::ExecutionFailure, 'wawawa')  | 
 | 27 | +      #expect(provider).to receive(:pkginfo).and_raise(Puppet::ExecutionFailure, 'wawawa')  | 
31 | 28 |       #expect(provider).to receive(:pkginfo).with(['-a', '-z'])  | 
32 | 29 |       expect(described_class.instances).to be_nil  | 
33 | 30 |     end  | 
34 | 31 | 
 
  | 
35 | 32 |     it "should return the empty set if no packages are listed" do  | 
36 |  | -      expect(described_class).to receive(:execpipe).with(%w{/usr/sbin/pkg_info -a}).and_yield(StringIO.new(''))  | 
 | 33 | +      expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(StringIO.new(''))  | 
37 | 34 |       expect(described_class.instances).to be_empty  | 
38 | 35 |     end  | 
39 | 36 | 
 
  | 
40 | 37 |     it "should return all packages when invoked" do  | 
41 | 38 |       fixture = File.read(my_fixture('pkginfo.list'))  | 
42 |  | -      expect(described_class).to receive(:execpipe).with(%w{/usr/sbin/pkg_info -a -z}).and_yield(fixture)  | 
 | 39 | +      expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture)  | 
43 | 40 |       expect(described_class.instances.map(&:name).sort).to eq(  | 
44 |  | -        %w{autoconf%2.13 autoconf%2.56 bash postfix%stable puppet%8}.sort  | 
 | 41 | +        %w{autoconf%2.13 autoconf%2.56 bash postfix%stable puppet%8 zstd}.sort  | 
45 | 42 |       )  | 
46 | 43 |     end  | 
47 | 44 | 
 
  | 
48 | 45 |     it "should return all flavors if set" do  | 
49 | 46 |       fixture = File.read(my_fixture('pkginfo.list'))  | 
50 |  | -      expect(provider).to receive(:pkgadd).with(['-a', '-z']).and_yield(fixture)  | 
 | 47 | +      expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture)  | 
51 | 48 |       instances = described_class.instances.map {|p| {:name => p.get(:name),  | 
52 |  | -        :ensure => p.get(:ensure), :flavor => p.get(:flavor)}}  | 
53 |  | -      expect(instances.size).to eq(5)  | 
54 |  | -      expect(instances[0]).to eq({:name => 'autoconf%2.13', :ensure => 'present', :flavor => nil})  | 
55 |  | -      expect(instances[1]).to eq({:name => 'autoconf%2.56', :ensure => 'present', :flavor => nil})  | 
56 |  | -      expect(instances[2]).to eq({:name => 'bash',  :ensure => 'present', :flavor => nil})  | 
57 |  | -      expect(instances[3]).to eq({:name => 'postfix%stable',  :ensure => 'present', :flavor => 'ldap'})  | 
58 |  | -      expect(instances[4]).to eq({:name => 'puppet%8',  :ensure => 'present', :flavor => nil})  | 
 | 49 | +        :flavor => p.get(:flavor), :branch => p.get(:branch)}}  | 
 | 50 | +      expect(instances.size).to eq(6)  | 
 | 51 | +      expect(instances[0]).to eq({:name => 'autoconf%2.13', :flavor => :absent, :branch => '%2.13'})  | 
 | 52 | +      expect(instances[1]).to eq({:name => 'autoconf%2.56', :flavor => :absent, :branch => '%2.56'})  | 
 | 53 | +      expect(instances[2]).to eq({:name => 'bash', :flavor => :absent, :branch => :absent})  | 
 | 54 | +      expect(instances[3]).to eq({:name => 'postfix%stable', :flavor => 'ldap', :branch => '%stable'})  | 
 | 55 | +      expect(instances[4]).to eq({:name => 'puppet%8', :flavor => :absent, :branch => '%8'})  | 
 | 56 | +      expect(instances[5]).to eq({:name => 'zstd', :flavor => :absent, :branch => :absent})  | 
59 | 57 |     end  | 
60 | 58 |   end  | 
61 | 59 | 
 
  | 
 | 
97 | 95 |   end  | 
98 | 96 | 
 
  | 
99 | 97 |   context "#query" do  | 
100 |  | -    it "should return the installed version if present" do  | 
101 |  | -      #fixture = File.read(my_fixture('pkginfo.detail'))  | 
102 |  | -      #expect(provider).to receive(:pkginfo).with('bash').and_return(fixture)  | 
103 |  | -      expect(provider.query).to eq({:branch=>nil, :ensure=>"present", :flavor=>nil, :name=>"bash", :provider=>:openbsd})  | 
 | 98 | +    it "should return package info if present" do  | 
 | 99 | +      fixture = File.read(my_fixture('pkginfo.list'))  | 
 | 100 | +      expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture)  | 
 | 101 | +      expect(provider.query).to eq({:branch=>nil, :flavor=>nil, :name=>"bash", :provider=>:openbsd})  | 
104 | 102 |     end  | 
105 | 103 | 
 
  | 
106 | 104 |     it "should return nothing if not present" do  | 
 | 105 | +      fixture = File.read(my_fixture('pkginfo.list'))  | 
107 | 106 |       provider.resource[:name] = 'zsh'  | 
 | 107 | +      expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture)  | 
108 | 108 |       expect(provider.query).to be_nil  | 
109 | 109 |     end  | 
110 | 110 |   end  | 
 | 
0 commit comments