Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix $filename and $mode types in python::dotfile #446

Merged
merged 3 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifests/dotfile.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions spec/defines/dotfile_spec.rb
Original file line number Diff line number Diff line change
@@ -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
gdubicki marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion spec/defines/pyvenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down