Skip to content

Commit 7612dbd

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

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-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: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,44 @@
33
# Chef::Mixin::ShellOut is required to mock shellout
44
include Chef::Mixin::ShellOut
55

6+
# Global monkey patch for ChefSpec::SoloRunner to include cookbook paths
7+
ChefSpec::SoloRunner.class_eval do
8+
alias_method :solo_original_initialize, :initialize
9+
10+
def initialize(options = {})
11+
options ||= {}
12+
options[:cookbook_path] ||= [
13+
File.expand_path('../..', __dir__),
14+
File.expand_path('../../cookbooks', __dir__),
15+
File.expand_path('../../cookbooks/third-party', __dir__)
16+
]
17+
solo_original_initialize(options)
18+
end
19+
end
20+
21+
# Patch other runners if they exist
22+
if defined?(ChefSpec::ServerRunner)
23+
ChefSpec::ServerRunner.class_eval do
24+
alias_method :server_original_initialize, :initialize
25+
26+
def initialize(options = {})
27+
options ||= {}
28+
options[:cookbook_path] ||= [
29+
File.expand_path('../..', __dir__),
30+
File.expand_path('../../cookbooks', __dir__),
31+
File.expand_path('../../cookbooks/third-party', __dir__)
32+
]
33+
server_original_initialize(options)
34+
end
35+
end
36+
end
37+
638
RSpec.configure do |c|
39+
c.cookbook_path = [
40+
File.expand_path('../..', __dir__),
41+
File.expand_path('../../cookbooks', __dir__),
42+
File.expand_path('../../cookbooks/third-party', __dir__)
43+
]
744
c.before(:each) do
845
allow(File).to receive(:exist?).and_call_original
946
allow(Dir).to receive(:exist?).and_call_original
@@ -58,7 +95,16 @@ def for_all_node_types
5895
end
5996

6097
def runner(platform:, version:, step_into: [])
61-
ChefSpec::SoloRunner.new(platform: platform, version: version, step_into: step_into) do |node|
98+
ChefSpec::SoloRunner.new(
99+
platform: platform,
100+
version: version,
101+
step_into: step_into,
102+
cookbook_path: [
103+
File.expand_path('../..', __dir__),
104+
File.expand_path('../../cookbooks', __dir__),
105+
File.expand_path('../../cookbooks/third-party', __dir__)
106+
]
107+
) do |node|
62108
yield node if block_given?
63109
end
64110
end

0 commit comments

Comments
 (0)