Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ install:
- openssl aes-256-cbc -K $encrypted_264707aa6565_key -iv $encrypted_264707aa6565_iv -in codenamephp.pem.enc -out codenamephp.pem -d

script:
- chef exec foodcritic .
- chef exec rubocop
- chef exec cookstyle .
- chef exec kitchen test

before_deploy:
Expand Down
2 changes: 2 additions & 0 deletions resources/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
property :filename, String, required: true, description: 'The file name in the dropfolder, should begin with a number for sorting, e.g. 100-myFile'
property :source, String, required: true, description: 'The source template to use'
property :cookbook, String, description: 'The cookbook the template file is in, defaults to the current cookbook'
property :variables, Hash, default: {}, description: 'Hash of variables to pass to the template resource'

action :add do
create_file('/etc/skel', 'root', new_resource.filename, new_resource.source) if new_resource.skel
Expand All @@ -20,6 +21,7 @@ def create_file(folder, user, filename, source)
path "#{folder}/.bashrc.d/#{filename}"
source source
cookbook new_resource.cookbook
variables(new_resource.variables)
end
end

Expand Down
24 changes: 16 additions & 8 deletions test/fixtures/cookbooks/test/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,54 @@
end

codenamephp_bash_manage 'manage bash' do
users %w[user1 user2 user3]
users %w(user1 user2 user3)
end

codenamephp_bash_file 'add a file' do
users %w[user1 user2 user3]
users %w(user1 user2 user3)
filename '100-content'
content 'just some test'
end

codenamephp_bash_cookbook_file 'add a cookbook file' do
users %w[user1 user2 user3]
users %w(user1 user2 user3)
filename '200-file'
cookbook_file 'some_file'
cookbook 'test'
end

codenamephp_bash_template 'add a template file' do
users %w[user1 user2 user3]
users %w(user1 user2 user3)
filename '300-template'
source 'some_template'
cookbook 'test'
end

codenamephp_bash_template 'add a template file with variables' do
users %w(user1 user2 user3)
filename '300-template-with-variables'
source 'template_with_variable.erb'
cookbook 'test'
variables({ 'value': 'super value' })
end

codenamephp_bash_file 'add a file' do
users %w[user3]
users %w(user3)
filename '400-content'
content 'just some test'
end
codenamephp_bash_file 'add a file' do
users %w[user3]
users %w(user3)
filename '500-content'
content 'just some test'
end

codenamephp_bash_remove_file 'remove a file' do
users %w[user3]
users %w(user3)
filename '400-content'
end
codenamephp_bash_remove_file 'remove a file' do
users %w[user3]
users %w(user3)
filename '500-content'
skel false
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Just some <%= @value %>
10 changes: 10 additions & 0 deletions test/smoke/default/default_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@
its('owner') { should eq 'user1' }
its('group') { should eq 'user1' }
end

describe file('/home/user1/.bashrc.d/300-template-with-variables') do
it { should exist }
it { should be_file }
its('content') { should match('Just some super value') }
its('mode') { should cmp '0770' }
its('owner') { should eq 'user1' }
its('group') { should eq 'user1' }
end

describe file('/home/user1/.bashrc.d/400-content') do
it { should_not exist }
end
Expand Down