Commit 66960906 authored by Jamie Tanna's avatar Jamie Tanna

Create file if attribute is set

parent c7532efe
Pipeline #8517369 passed with stage
in 2 minutes and 39 seconds
......@@ -21,3 +21,11 @@ user "create user #{node['user']}" do
username node['user']
group node['group']
end
file 'creates the hello.txt file' do
path "~#{node['user']}/hello.txt"
content "hello #{node['user']}"
mode '0600'
owner node['user']
only_if { node['hello'] }
end
......@@ -37,6 +37,10 @@ describe 'user-cookbook::default' do
.with(username: 'jamie')
.with(group: nil)
end
it 'doesn\'t create the hello.txt file' do
expect(chef_run).to_not create_file('creates the hello.txt file')
end
end
context 'When the user attribute is set' do
......@@ -56,6 +60,10 @@ describe 'user-cookbook::default' do
.with(username: 'test')
.with(group: nil)
end
it 'doesn\'t create the hello.txt file' do
expect(chef_run).to_not create_file('creates the hello.txt file')
end
end
context 'When the user and group attributes are set' do
......@@ -76,5 +84,31 @@ describe 'user-cookbook::default' do
.with(username: 'test')
.with(group: 'users')
end
it 'doesn\'t create the hello.txt file' do
expect(chef_run).to_not create_file('creates the hello.txt file')
end
end
context 'When the hello attribute is set' do
let(:chef_run) do
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04') do |node|
node.automatic['user'] = 'jamie'
node.automatic['hello'] = true
end
runner.converge(described_recipe)
end
it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
it 'creates the hello.txt file' do
expect(chef_run).to create_file('creates the hello.txt file')
.with(path: '~jamie/hello.txt')
.with(content: 'hello jamie')
.with(mode: '0600')
.with(owner: 'jamie')
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment