d79462cd48ad4cb7a1cccaa50ef499e252725027
[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 => "Explanation: : 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 => "Explanation: : 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 => "Explanation: : 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 => "Explanation: : 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 => "Explanation: : 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 => "Explanation: : 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 => "Explanation: : 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 => "Explanation: : 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     {
80       :params => {
81         :packages        => ['apache', 'ntop'],
82       },
83       :content => "Explanation: : my_pin\nPackage: apache ntop\nPin: release a=my_pin\nPin-Priority: 0\n"
84     },
85   ].each do |param_set|
86     describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
87       let :param_hash do
88         default_params.merge(param_set[:params])
89       end
90
91       let :params do
92         param_set[:params]
93       end
94
95       it { should contain_class("apt::params") }
96
97       it { should contain_file("#{title}.pref").with({
98           'ensure'  => param_hash[:ensure],
99           'path'    => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
100           'owner'   => 'root',
101           'group'   => 'root',
102           'mode'    => '0644',
103           'content' => param_set[:content],
104         })
105       }
106     end
107   end
108
109   describe 'resource title with invalid chars' do
110     context 'spaces' do
111       let(:title) { 'oh my god this is not valid' }
112       it { should contain_file('oh_my_god_this_is_not_valid.pref') }
113     end
114
115     context '#$&*$' do
116       let(:title) { 'so && many $* invalid @! things' }
117       it { should contain_file('so____many____invalid____things.pref') }
118     end
119   end
120 end