- [
- { :params => {},
- :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
- },
- {
- :params => {
- :packages => 'apache',
- :priority => '1'
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
- },
- {
- :params => {
- :order => 50,
- :packages => 'apache',
- :priority => '1'
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
- },
- {
- :params => {
- :ensure => 'absent',
- :packages => 'apache',
- :priority => '1'
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
- },
- {
- :params => {
- :packages => 'apache',
- :priority => '1',
- :release => 'my_newpin'
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
- },
- {
- :params => {
- :packages => 'apache',
- :priority => '1',
- :version => '2.2.16*'
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
- },
- {
- :params => {
- :priority => '1',
- :origin => 'ftp.de.debian.org'
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: origin \"ftp.de.debian.org\"\nPin-Priority: 1\n"
- },
- {
- :params => {
- :packages => 'apache',
- :priority => '1',
- :release => 'stable',
- :codename => 'wheezy',
- :release_version => '3.0',
- :component => 'main',
- :originator => 'Debian',
- :label => 'Debian'
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n"
- },
- {
- :params => {
- :packages => ['apache', 'ntop'],
- },
- :content => "# my_pin\nExplanation: : my_pin\nPackage: apache ntop\nPin: release a=my_pin\nPin-Priority: 0\n"
- },
- ].each do |param_set|
- describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
- let :param_hash do
- default_params.merge(param_set[:params])
+ context 'set version' do
+ let :params do
+ {
+ 'packages' => 'vim',
+ 'version' => '1',
+ }
+ end
+ it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
+ it { is_expected.to contain_file("my_pin.pref").with({
+ 'ensure' => 'present',
+ 'path' => '/etc/apt/preferences.d/my_pin.pref',
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ end
+
+ context 'set origin' do
+ let :params do
+ {
+ 'packages' => 'vim',
+ 'origin' => 'test',
+ }
+ end
+ it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
+ it { is_expected.to contain_file("my_pin.pref").with({
+ 'ensure' => 'present',
+ 'path' => '/etc/apt/preferences.d/my_pin.pref',
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ end
+
+ context 'not defaults' do
+ let :params do
+ {
+ 'explanation' => 'foo',
+ 'order' => 99,
+ 'release' => '1',
+ 'codename' => 'bar',
+ 'release_version' => '2',
+ 'component' => 'baz',
+ 'originator' => 'foobar',
+ 'label' => 'foobaz',
+ 'priority' => 10,
+ }
+ end
+ it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) }
+ it { is_expected.to contain_file("my_pin.pref").with({
+ 'ensure' => 'present',
+ 'path' => '/etc/apt/preferences.d/99-my_pin.pref',
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ end
+
+ context 'ensure absent' do
+ let :params do
+ {
+ 'ensure' => 'absent'
+ }
+ end
+ it { is_expected.to contain_file("my_pin.pref").with({
+ 'ensure' => 'absent',
+ })
+ }
+ end
+
+ context 'bad characters' do
+ let(:title) { 'such bad && wow!' }
+ it { is_expected.to contain_file("such__bad____wow_.pref") }
+ end
+
+ describe 'validation' do
+ context 'invalid order' do
+ let :params do
+ {
+ 'order' => 'foo',
+ }
+ end
+ it do
+ expect {
+ should compile
+ }.to raise_error(Puppet::Error, /Only integers are allowed/)
+ end
+ end
+
+ context 'packages == * and version' do
+ let :params do
+ {
+ 'version' => '1',
+ }