Skip to content

Commit 613aa87

Browse files
Chef unit test
Signed-off-by: Hanwen <[email protected]>
1 parent 32623e2 commit 613aa87

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'chefspec'
2-
31
require_relative '../../aws-parallelcluster-shared/spec/spec_helper'
42

53
RSpec.configure do |c|

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,28 @@
33
# Chef::Mixin::ShellOut is required to mock shellout
44
include Chef::Mixin::ShellOut
55

6+
# Create symlinks for third-party cookbooks so ChefSpec can find them
7+
third_party_dir = File.expand_path('../../cookbooks/third-party', __dir__)
8+
cookbooks_dir = File.expand_path('../../cookbooks', __dir__)
9+
10+
if Dir.exist?(third_party_dir)
11+
Dir.entries(third_party_dir).each do |entry|
12+
next if entry.start_with?('.')
13+
source = File.join(third_party_dir, entry)
14+
target = File.join(cookbooks_dir, entry)
15+
16+
if Dir.exist?(source) && !File.exist?(target)
17+
File.symlink(source, target)
18+
end
19+
end
20+
end
21+
622
RSpec.configure do |c|
23+
c.cookbook_path = [
24+
File.expand_path('../..', __dir__),
25+
File.expand_path('../../cookbooks', __dir__),
26+
File.expand_path('../../cookbooks/third-party', __dir__)
27+
]
728
c.before(:each) do
829
allow(File).to receive(:exist?).and_call_original
930
allow(Dir).to receive(:exist?).and_call_original
@@ -58,7 +79,16 @@ def for_all_node_types
5879
end
5980

6081
def runner(platform:, version:, step_into: [])
61-
ChefSpec::SoloRunner.new(platform: platform, version: version, step_into: step_into) do |node|
82+
ChefSpec::SoloRunner.new(
83+
platform: platform,
84+
version: version,
85+
step_into: step_into,
86+
cookbook_path: [
87+
File.expand_path('../..', __dir__),
88+
File.expand_path('../../cookbooks', __dir__),
89+
File.expand_path('../../cookbooks/third-party', __dir__)
90+
]
91+
) do |node|
6292
yield node if block_given?
6393
end
6494
end

0 commit comments

Comments
 (0)