X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fpin_spec.rb;h=1dd02980afe12a76f511c858fad50a295d2c9e81;hb=refs%2Fheads%2Frelease-prep;hp=23ebd59b32d77d08c28108a3c9ff79c64ead7175;hpb=5d7982dba0e6c5f31f320ebc2466a1811d283d51;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index 23ebd59..1dd0298 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -1,166 +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: '9', + full: '9.0' + }, + distro: { + codename: 'stretch', + id: 'Debian' + } + } + } + end let(:title) { 'my_pin' } - context 'defaults' do - it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)} - it { is_expected.to contain_file("my_pin.pref").with({ - 'ensure' => 'present', - 'path' => '/etc/apt/preferences.d/my_pin.pref', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + 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 'set version' do + context 'with set version' do let :params do { 'packages' => 'vim', - 'version' => '1', + 'version' => '1' } end - it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)} - it { is_expected.to contain_file("my_pin.pref").with({ - 'ensure' => 'present', - 'path' => '/etc/apt/preferences.d/my_pin.pref', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + + 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 'set origin' do + context 'with set origin' do let :params do { 'packages' => 'vim', - 'origin' => 'test', + 'origin' => 'test' } end - it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)} - it { is_expected.to contain_file("my_pin.pref").with({ - 'ensure' => 'present', - 'path' => '/etc/apt/preferences.d/my_pin.pref', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + + 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 'not defaults' do + context 'without defaults' do let :params do { - 'explanation' => 'foo', - 'order' => 99, - 'release' => '1', - 'codename' => 'bar', + 'explanation' => 'foo', + 'order' => 99, + 'release' => '1', + 'codename' => 'bar', 'release_version' => '2', - 'component' => 'baz', - 'originator' => 'foobar', - 'label' => 'foobaz', - 'priority' => 10, + 'component' => 'baz', + 'originator' => 'foobar', + 'label' => 'foobaz', + 'priority' => 10 } end - it { is_expected.to contain_file("my_pin.pref").with_content(/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_file("my_pin.pref").with({ - 'ensure' => 'present', - 'path' => '/etc/apt/preferences.d/99-my_pin.pref', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) + + 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 { + expect(subject).to contain_apt__setting('pref-my_pin').with('priority' => 99) } end - context 'ensure absent' do + context 'with ensure absent' do let :params do { 'ensure' => 'absent' } end - it { is_expected.to contain_file("my_pin.pref").with({ - 'ensure' => 'absent', - }) + + it { + expect(subject).to contain_apt__setting('pref-my_pin').with('ensure' => 'absent') } end - context 'bad characters' do + context 'with bad characters' do let(:title) { 'such bad && wow!' } - it { is_expected.to contain_file("such__bad____wow_.pref") } + + it { is_expected.to contain_apt__setting('pref-such__bad____wow_') } end describe 'validation' do - context 'invalid order' do + context 'with invalid order' do let :params do { - 'order' => 'foo', + 'order' => 'foo' } end + it do - expect { - should compile - }.to raise_error(Puppet::Error, /Only integers are allowed/) + expect(subject).to raise_error(Puppet::Error, %r{expects an Integer value, got String}) end end - context 'packages == * and version' do + context 'with packages == * and version' do let :params do { - 'version' => '1', + 'version' => '1' } end + it do - expect { - should compile - }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/) + expect(subject).to raise_error(Puppet::Error, %r{parameter version cannot be used in general form}) end end - context 'packages == * and release and origin' do + context 'with packages == * and release and origin' do let :params do { - 'origin' => 'test', - 'release' => 'foo', + 'origin' => 'test', + 'release' => 'foo' } end + it do - expect { - should compile - }.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/) + expect(subject).to raise_error(Puppet::Error, %r{parameters release and origin are mutually exclusive}) end end - context 'specific form with release and origin' do + context 'with specific release and origin' do let :params do { - 'release' => 'foo', - 'origin' => 'test', - 'packages' => 'vim', + 'release' => 'foo', + 'origin' => 'test', + 'packages' => 'vim' } end + it do - expect { - should compile - }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) + expect(subject).to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) end end - context 'specific form with version and origin' do + context 'with specific version and origin' do let :params do { - 'version' => '1', - 'origin' => 'test', - 'packages' => 'vim', + 'version' => '1', + 'origin' => 'test', + 'packages' => 'vim' } end + it do - expect { - should compile - }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) + expect(subject).to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive}) end end end