Add lsbdistid facts where appropriate.
[puppet-modules/puppetlabs-apt.git] / spec / defines / pin_spec.rb
1 require 'spec_helper'
2 describe 'apt::pin', :type => :define do
3   let(:facts) { { :lsbdistid => 'Debian' } }
4   let(:title) { 'my_pin' }
5
6   let :default_params do
7     {
8       :ensure   => 'present',
9       :order    => '',
10       :packages => '*',
11       :priority => '0',
12       :release  => nil
13     }
14   end
15
16   [
17     { :params  => {},
18       :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
19     },
20     {
21       :params => {
22         :packages => 'apache',
23         :priority => '1'
24       },
25       :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
26     },
27     {
28       :params => {
29         :order    => 50,
30         :packages => 'apache',
31         :priority => '1'
32       },
33       :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
34     },
35     {
36       :params => {
37         :ensure   => 'absent',
38         :packages => 'apache',
39         :priority => '1'
40       },
41       :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
42     },
43     {
44       :params => {
45         :packages => 'apache',
46         :priority => '1',
47         :release  => 'my_newpin'
48       },
49       :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
50     },
51     {
52       :params => {
53         :packages => 'apache',
54         :priority => '1',
55         :version  => '2.2.16*'
56       },
57       :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
58     },
59     {
60       :params => {
61         :priority => '1',
62         :origin   => 'ftp.de.debian.org'
63       },
64       :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: origin \"ftp.de.debian.org\"\nPin-Priority: 1\n"
65     },
66     {
67       :params => {
68         :packages        => 'apache',
69         :priority        => '1',  
70         :release         => 'stable',
71         :codename        => 'wheezy',
72         :release_version => '3.0',
73         :component       => 'main',
74         :originator      => 'Debian',
75         :label           => 'Debian'
76       },
77       :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"
78     },
79   ].each do |param_set|
80     describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
81       let :param_hash do
82         default_params.merge(param_set[:params])
83       end
84
85       let :params do
86         param_set[:params]
87       end
88
89       it { should contain_class("apt::params") }
90
91       it { should contain_file("#{title}.pref").with({
92           'ensure'  => param_hash[:ensure],
93           'path'    => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
94           'owner'   => 'root',
95           'group'   => 'root',
96           'mode'    => '0644',
97           'content' => param_set[:content],
98         })
99       }
100     end
101   end
102 end