Merge pull request #124 from DavidS/geppetto-infrastructure
[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   ].each do |param_set|
79     describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
80       let :param_hash do
81         default_params.merge(param_set[:params])
82       end
83
84       let :params do
85         param_set[:params]
86       end
87
88       it { should include_class("apt::params") }
89
90       it { should contain_file("#{title}.pref").with({
91           'ensure'  => param_hash[:ensure],
92           'path'    => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
93           'owner'   => 'root',
94           'group'   => 'root',
95           'mode'    => '0644',
96           'content' => param_set[:content],
97         })
98       }
99     end
100   end
101 end