@@ -99,9 +99,47 @@ def mkdump(base, size, x64 = false)
9999 context "on linux" do
100100 before { stub_ohai ( platform : "ubuntu" , version : "16.04" ) }
101101
102+ # file_list just needs to have one file which is inside of the install_dir
103+ let ( :file_list ) do
104+ double ( "Mixlib::Shellout" ,
105+ error! : false ,
106+ stdout : <<~EOH
107+ /opt/chefdk/shouldnt/matter
108+ EOH
109+ )
110+ end
111+
112+ let ( :empty_list ) do
113+ double ( "Mixlib::Shellout" ,
114+ error! : false ,
115+ stdout : <<~EOH
116+ EOH
117+ )
118+ end
119+
120+ let ( :failed_list ) do
121+ failed_list = double ( "Mixlib::Shellout" ,
122+ stdout : <<~EOH
123+ /opt/chefdk/shouldnt/matter
124+ EOH
125+ )
126+ allow ( failed_list ) . to receive ( :error! ) . and_raise ( "Mixlib::Shellout::ShellCommandFailed" )
127+ failed_list
128+ end
129+
130+ let ( :bad_list ) do
131+ double ( "Mixlib::Shellout" ,
132+ error! : false ,
133+ stdout : <<~EOH
134+ /somewhere/other/than/install/dir
135+ EOH
136+ )
137+ end
138+
102139 let ( :bad_healthcheck ) do
103140 double ( "Mixlib::Shellout" ,
104- stdout : <<-EOH . gsub ( /^ {12}/ , "" )
141+ error! : false ,
142+ stdout : <<~EOH
105143 /bin/ls:
106144 linux-vdso.so.1 => (0x00007fff583ff000)
107145 libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fad8592a000)
@@ -122,7 +160,8 @@ def mkdump(base, size, x64 = false)
122160
123161 let ( :good_healthcheck ) do
124162 double ( "Mixlib::Shellout" ,
125- stdout : <<-EOH . gsub ( /^ {12}/ , "" )
163+ error! : false ,
164+ stdout : <<~EOH
126165 /bin/echo:
127166 linux-vdso.so.1 => (0x00007fff8a6ee000)
128167 libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f70f58c0000)
@@ -135,19 +174,25 @@ def mkdump(base, size, x64 = false)
135174 )
136175 end
137176
138- let ( :regexp ) { ".*(\\ .TXT|\\ .[ch]|\\ .[ch]pp|\\ .[eh]rl|\\ .app|\\ .appup|\\ .bat|\\ .beam|\\ .cc|\\ .cmake|\\ .conf|\\ .css|\\ .e*rb|\\ .feature|\\ .gemspec|\\ .gif|\\ .gitignore|\\ .gitkeep|\\ .h*h|\\ .jar|\\ .java|\\ .jpg|\\ .js|\\ .jsm|\\ .json|\\ .lock|\\ .log|\\ .lua|\\ .md|\\ .mkd|\\ .npmignore|\\ .out|\\ .packlist|\\ .perl|\\ .pl|\\ .pm|\\ .png|\\ .pod|\\ .properties|\\ .py[oc]*|\\ .r*html|\\ .rake|\\ .rdoc|\\ .ri|\\ .rst|\\ .scss|\\ .sh|\\ .sql|\\ .svg|\\ .toml|\\ .ttf|\\ .txt|\\ .xml|\\ .yml|Gemfile|LICENSE|Makefile|README|Rakefile|VERSION|license)$|.*\\ /build_info\\ /.*|.*\\ /licenses\\ /.*|.*\\ /LICENSES\\ /.*|.*\\ /man\\ /.*|.*\\ /share\\ /doc\\ /.*|.*\\ /share\\ /info\\ /.*|.*\\ /share\\ /postgresql\\ /.*|.*\\ /share\\ /terminfo\\ /.*|.*\\ /share\\ /timezone\\ /.*|.*\\ /terminfo\\ /.*" }
139-
140177 it "raises an exception when there are external dependencies" do
141178 allow ( subject ) . to receive ( :shellout )
142- . with ( "find #{ project . install_dir } / -type f -regextype posix-extended ! -regex '#{ regexp } ' | xargs ldd" )
179+ . with ( "find /opt/chefdk/ -type f" )
180+ . and_return ( file_list )
181+
182+ allow ( subject ) . to receive ( :shellout )
183+ . with ( "xargs ldd" , { input : "/opt/chefdk/shouldnt/matter\n " } )
143184 . and_return ( bad_healthcheck )
144185
145186 expect { subject . run! } . to raise_error ( HealthCheckFailed )
146187 end
147188
148189 it "does not raise an exception when the healthcheck passes" do
149190 allow ( subject ) . to receive ( :shellout )
150- . with ( "find #{ project . install_dir } / -type f -regextype posix-extended ! -regex '#{ regexp } ' | xargs ldd" )
191+ . with ( "find /opt/chefdk/ -type f" )
192+ . and_return ( file_list )
193+
194+ allow ( subject ) . to receive ( :shellout )
195+ . with ( "xargs ldd" , { input : "/opt/chefdk/shouldnt/matter\n " } )
151196 . and_return ( good_healthcheck )
152197
153198 expect { subject . run! } . to_not raise_error
@@ -156,6 +201,30 @@ def mkdump(base, size, x64 = false)
156201 it "will not perform dll base relocation checks" do
157202 expect ( subject . relocation_checkable? ) . to be false
158203 end
204+
205+ it "raises an exception if there's nothing in the file list" do
206+ allow ( subject ) . to receive ( :shellout )
207+ . with ( "find /opt/chefdk/ -type f" )
208+ . and_return ( empty_list )
209+
210+ expect { subject . run! } . to raise_error ( RuntimeError , "Internal Error: Health Check found no lines" )
211+ end
212+
213+ it "raises an exception if the file list command raises" do
214+ allow ( subject ) . to receive ( :shellout )
215+ . with ( "find /opt/chefdk/ -type f" )
216+ . and_return ( failed_list )
217+
218+ expect { subject . run! } . to raise_error ( RuntimeError , "Mixlib::Shellout::ShellCommandFailed" )
219+ end
220+
221+ it "raises an exception if the file list command has no entries in the install_dir" do
222+ allow ( subject ) . to receive ( :shellout )
223+ . with ( "find /opt/chefdk/ -type f" )
224+ . and_return ( bad_list )
225+
226+ expect { subject . run! } . to raise_error ( RuntimeError , "Internal Error: Health Check lines not matching the install_dir" )
227+ end
159228 end
160229 end
161230end
0 commit comments