55 let ( :package ) { Puppet ::Type . type ( :package ) . new ( :name => 'bash' , :provider => 'openbsd' ) }
66 let ( :provider ) { described_class . new ( package ) }
77
8- def expect_read_from_pkgconf ( lines )
9- pkgconf = double ( :readlines => lines )
10- expect ( Puppet ::FileSystem ) . to receive ( :exist? ) . with ( '/etc/pkg.conf' ) . and_return ( true )
11- expect ( File ) . to receive ( :open ) . with ( '/etc/pkg.conf' , 'rb' ) . and_return ( pkgconf )
12- end
13-
14- def expect_pkgadd_with_source ( source )
15- expect ( provider ) . to receive ( :pkgadd ) . with ( [ source ] ) do
16- expect ( ENV ) . not_to have_key ( 'PKG_PATH' )
17- end
18- end
19-
20- def expect_pkgadd_with_env_and_name ( source , &block )
21- expect ( ENV ) . not_to have_key ( 'PKG_PATH' )
22-
23- expect ( provider ) . to receive ( :pkgadd ) . with ( [ provider . resource [ :name ] ] ) do
24- expect ( ENV ) . to have_key ( 'PKG_PATH' )
25- expect ( ENV [ 'PKG_PATH' ] ) . to eq ( source )
26- end
27- expect ( provider ) . to receive ( :execpipe ) . with ( [ '/bin/pkg_info' , '-I' , provider . resource [ :name ] ] ) . and_yield ( '' )
28-
29- yield
30-
31- expect ( ENV ) . not_to be_key ( 'PKG_PATH' )
32- end
33-
348 context 'provider features' do
359 it { is_expected . to be_installable }
3610 it { is_expected . to be_install_options }
@@ -61,20 +35,23 @@ def expect_pkgadd_with_env_and_name(source, &block)
6135
6236 it "should return all packages when invoked" do
6337 fixture = File . read ( my_fixture ( 'pkginfo.list' ) )
64- expect ( described_class ) . to receive ( :execpipe ) . with ( %w{ /bin/pkg_info -a } ) . and_yield ( fixture )
38+ expect ( described_class ) . to receive ( :execpipe ) . with ( %w{ /bin/pkg_info -a -z } ) . and_yield ( fixture )
6539 expect ( described_class . instances . map ( &:name ) . sort ) . to eq (
66- %w{ bash bzip2 expat gettext libiconv lzo openvpn python vim wget } . sort
40+ %w{ autoconf%2.13 autoconf%2.56 bash postfix%stable puppet%8 } . sort
6741 )
6842 end
6943
7044 it "should return all flavors if set" do
71- fixture = File . read ( my_fixture ( 'pkginfo_flavors .list' ) )
72- expect ( described_class ) . to receive ( :execpipe ) . with ( %w{ /bin/pkg_info -a } ) . and_yield ( fixture )
45+ fixture = File . read ( my_fixture ( 'pkginfo .list' ) )
46+ expect ( described_class ) . to receive ( :execpipe ) . with ( %w{ /bin/pkg_info -a -z } ) . and_yield ( fixture )
7347 instances = described_class . instances . map { |p | { :name => p . get ( :name ) ,
7448 :ensure => p . get ( :ensure ) , :flavor => p . get ( :flavor ) } }
7549 expect ( instances . size ) . to eq ( 2 )
76- expect ( instances [ 0 ] ) . to eq ( { :name => 'bash' , :ensure => '3.1.17' , :flavor => 'static' } )
77- expect ( instances [ 1 ] ) . to eq ( { :name => 'vim' , :ensure => '7.0.42' , :flavor => 'no_x11' } )
50+ expect ( instances [ 0 ] ) . to eq ( { :name => 'autoconf%2.13' , :ensure => 'present' , :flavor => nil } )
51+ expect ( instances [ 1 ] ) . to eq ( { :name => 'autoconf%2.56' , :ensure => 'present' , :flavor => nil } )
52+ expect ( instances [ 2 ] ) . to eq ( { :name => 'bash' , :ensure => 'present' , :flavor => nil } )
53+ expect ( instances [ 3 ] ) . to eq ( { :name => 'postfix%stable' , :ensure => 'present' , :flavor => 'ldap' } )
54+ expect ( instances [ 4 ] ) . to eq ( { :name => 'puppet%8' , :ensure => 'present' , :flavor => nil } )
7855 end
7956 end
8057
@@ -86,39 +63,6 @@ def expect_pkgadd_with_env_and_name(source, &block)
8663 end
8764 end
8865
89- context "#latest" do
90- before do
91- provider . resource [ :source ] = '/tmp/tcsh.tgz'
92- provider . resource [ :name ] = 'tcsh'
93- allow ( provider ) . to receive ( :pkginfo ) . with ( 'tcsh--' )
94- end
95-
96- it "should return the ensure value if the package is already installed" do
97- allow ( provider ) . to receive ( :properties ) . and_return ( { :ensure => '4.2.45' } )
98- allow ( provider ) . to receive ( :pkginfo ) . with ( '-Q' , 'tcsh--' )
99- expect ( provider . latest ) . to eq ( '4.2.45' )
100- end
101-
102- it "should recognize a new version" do
103- pkginfo_query = 'tcsh-6.18.01p1'
104- allow ( provider ) . to receive ( :pkginfo ) . with ( '-Q' , 'tcsh--' ) . and_return ( pkginfo_query )
105- expect ( provider . latest ) . to eq ( '6.18.01p1' )
106- end
107-
108- it "should recognize a newer version" do
109- allow ( provider ) . to receive ( :properties ) . and_return ( { :ensure => '1.6.8' } )
110- pkginfo_query = 'tcsh-1.6.10'
111- allow ( provider ) . to receive ( :pkginfo ) . with ( '-Q' , 'tcsh--' ) . and_return ( pkginfo_query )
112- expect ( provider . latest ) . to eq ( '1.6.10' )
113- end
114-
115- it "should recognize a package that is already the newest" do
116- pkginfo_query = 'tcsh-6.18.01p0 (installed)'
117- allow ( provider ) . to receive ( :pkginfo ) . with ( '-Q' , 'tcsh--' ) . and_return ( pkginfo_query )
118- expect ( provider . latest ) . to eq ( '6.18.01p0' )
119- end
120- end
121-
12266 context "#get_full_name" do
12367 it "should return the full unversioned package name when updating with a flavor" do
12468 provider . resource [ :ensure ] = 'latest'
0 commit comments