X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fpin_spec.rb;h=1b6ac33c28f629eac360d7468114c08ab8b9a39f;hb=7e31732abd277c852564c10011099bdf6967dc4f;hp=6438e8cbee46a7ce1c244fa8f3346b42287e2dfa;hpb=3917e080f36daaa087caef83d81555be5e970c7d;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index 6438e8c..1b6ac33 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -1,120 +1,157 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'apt::pin', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } +describe 'apt::pin', type: :define do + let :pre_condition do + 'class { "apt": }' + end + let(:facts) do + { + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + id: 'Debian', + }, + }, + } + end let(:title) { 'my_pin' } - let :default_params do - { - :ensure => 'present', - :order => '', - :packages => '*', - :priority => '0', - :release => nil + context 'with defaults' do + it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n}) } + end + + context 'with set version' do + let :params do + { + 'packages' => 'vim', + 'version' => '1', + } + end + + it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n}) } + end + + context 'with set origin' do + let :params do + { + 'packages' => 'vim', + 'origin' => 'test', + } + end + + it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n}) } + end + + context 'without 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_apt__setting('pref-my_pin').with_content(%r{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_apt__setting('pref-my_pin').with('priority' => 99) } end - [ - { :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 'with ensure absent' do + let :params do + { + 'ensure' => 'absent', + } + end + + it { + is_expected.to contain_apt__setting('pref-my_pin').with('ensure' => 'absent') + } + end + + context 'with bad characters' do + let(:title) { 'such bad && wow!' } + + it { is_expected.to contain_apt__setting('pref-such__bad____wow_') } + end + + describe 'validation' do + context 'with invalid order' do + let :params do + { + 'order' => 'foo', + } + end + + it do + is_expected.to raise_error(Puppet::Error, %r{expects an Integer value, got String}) end + end + context 'with packages == * and version' do let :params do - param_set[:params] + { + 'version' => '1', + } end - it { should contain_class("apt::params") } + it do + is_expected.to raise_error(Puppet::Error, %r{parameter version cannot be used in general form}) + end + end - it { should contain_file("#{title}.pref").with({ - 'ensure' => param_hash[:ensure], - 'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref", - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'content' => param_set[:content], - }) - } + context 'with packages == * and release and origin' do + let :params do + { + 'origin' => 'test', + 'release' => 'foo', + } + end + + it do + is_expected.to raise_error(Puppet::Error, %r{parameters release and origin are mutually exclusive}) + end end - end - describe 'resource title with invalid chars' do - context 'spaces' do - let(:title) { 'oh my god this is not valid' } - it { should contain_file('oh_my_god_this_is_not_valid.pref') } + context 'with specific release and origin' do + let :params do + { + 'release' => 'foo', + 'origin' => 'test', + 'packages' => 'vim', + } + end + + it do + is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) + end end - context '#$&*$' do - let(:title) { 'so && many $* invalid @! things' } - it { should contain_file('so____many____invalid____things.pref') } + context 'with specific version and origin' do + let :params do + { + 'version' => '1', + 'origin' => 'test', + 'packages' => 'vim', + } + end + + it do + is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) + end end end end