Skip to content

Commit 6431194

Browse files
Chef unit test
Signed-off-by: Hanwen <[email protected]>
1 parent f65902a commit 6431194

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

chefignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ Procfile
7070
#############
7171
Berksfile
7272
Berksfile.lock
73-
cookbooks/*
7473
tmp
7574

7675
# Cookbooks #

cookbooks/aws-parallelcluster-shared/spec/spec_helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
include Chef::Mixin::ShellOut
55

66
RSpec.configure do |c|
7+
c.before(:suite) do
8+
# Copy third-party cookbooks to cookbooks directory for ChefSpec tests
9+
require 'fileutils'
10+
third_party_path = File.expand_path('../../third-party', __dir__)
11+
cookbooks_path = File.expand_path('../..', __dir__)
12+
if Dir.exist?(third_party_path)
13+
Dir.glob(File.join(third_party_path, '*')).each do |cookbook|
14+
next unless File.directory?(cookbook)
15+
FileUtils.cp_r(cookbook, cookbooks_path)
16+
end
17+
end
18+
end
19+
720
c.before(:each) do
821
allow(File).to receive(:exist?).and_call_original
922
allow(Dir).to receive(:exist?).and_call_original

kitchen.global.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@ provisioner:
99
environments_path: test/environments
1010
client_rb:
1111
environment: kitchen
12+
cookbook_path:
13+
- /opt/kitchen/cookbooks
1214
attributes:
1315
kitchen: true
1416
cluster:
1517
# right now tests depend on this parameter: we will try to remove the dependency later
1618
region: us-east-1
1719

1820
lifecycle:
21+
pre_create:
22+
- remote: |
23+
for cookbook in /opt/kitchen/cookbooks/third-party/*; do
24+
if [ -d "$cookbook" ]; then
25+
cookbook_name=$(basename "$cookbook")
26+
if [ ! -e "/opt/kitchen/cookbooks/$cookbook_name" ]; then
27+
cp -r "$cookbook" "/opt/kitchen/cookbooks/"
28+
fi
29+
fi
30+
done
1931
<% %w(pre post).each do |prefix| %>
2032
<% %w(create converge verify destroy).each do |phase| %>
2133
<% op = "#{prefix}_#{phase}" %>

0 commit comments

Comments
 (0)