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