diff --git a/manifests/dotfile.pp b/manifests/dotfile.pp index 9d6e3923..47556fea 100644 --- a/manifests/dotfile.pp +++ b/manifests/dotfile.pp @@ -24,10 +24,10 @@ # define python::dotfile ( Enum['absent', 'present'] $ensure = 'present', - Stdlib::Filemode $filename = $title, + String[1] $filename = $title, String[1] $owner = 'root', String[1] $group = 'root', - String[1] $mode = '0644', + Stdlib::Filemode $mode = '0644', Hash $config = {}, ) { $parent_dir = dirname($filename) diff --git a/spec/defines/dotfile_spec.rb b/spec/defines/dotfile_spec.rb new file mode 100644 index 00000000..d7d469e4 --- /dev/null +++ b/spec/defines/dotfile_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'python::dotfile', type: :define do + on_supported_os.each do |os, facts| + context("on #{os} ") do + let :facts do + facts + end + + describe 'dotfile as' do + context 'fails with empty string filename' do + let(:title) { '' } + + it { is_expected.to raise_error(%r{Evaluation Error: Empty string title at 0. Title strings must have a length greater than zero.}) } + end + context 'fails with incorrect mode' do + let(:title) { '/etc/pip.conf' } + let(:params) { { mode: 'not-a-mode' } } + + it { is_expected.to raise_error(%r{Evaluation Error: Error while evaluating a Resource}) } + end + context 'succeeds with filename in existing path' do + let(:title) { '/etc/pip.conf' } + + it { is_expected.to contain_file('/etc/pip.conf').with_mode('0644') } + end + context 'succeeds with filename in a non-existing path' do + let(:title) { '/home/someuser/.pip/pip.conf' } + + it { is_expected.to contain_exec('create /home/someuser/.pip/pip.conf\'s parent dir').with_command('install -o root -g root -d /home/someuser/.pip') } + it { is_expected.to contain_file('/home/someuser/.pip/pip.conf').with_mode('0644') } + end + context 'succeeds when set owner' do + let(:title) { '/home/someuser/.pip/pip.conf' } + let(:params) { { owner: 'someuser' } } + + it { is_expected.to contain_exec('create /home/someuser/.pip/pip.conf\'s parent dir').with_command('install -o someuser -g root -d /home/someuser/.pip') } + it { is_expected.to contain_file('/home/someuser/.pip/pip.conf').with_owner('someuser') } + end + context 'succeeds when set group set' do + let(:title) { '/home/someuser/.pip/pip.conf' } + let(:params) { { group: 'somegroup' } } + + it { is_expected.to contain_exec('create /home/someuser/.pip/pip.conf\'s parent dir').with_command('install -o root -g somegroup -d /home/someuser/.pip') } + it { is_expected.to contain_file('/home/someuser/.pip/pip.conf').with_group('somegroup') } + end + end + end + end +end diff --git a/spec/defines/pyvenv_spec.rb b/spec/defines/pyvenv_spec.rb index 876afe12..285a0de5 100644 --- a/spec/defines/pyvenv_spec.rb +++ b/spec/defines/pyvenv_spec.rb @@ -2,7 +2,7 @@ describe 'python::pyvenv', type: :define do on_supported_os.each do |os, facts| - context "on #{os} " do + context("on #{os} ") do let :facts do facts end