Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get 7zip path from the windows registry. #151

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

default['ark']['apache_mirror'] = 'http://apache.mirrors.tds.net'
default['ark']['prefix_root'] = '/usr/local'
default['ark']['prefix_bin'] = '/usr/local/bin'
default['ark']['prefix_home'] = '/usr/local'
default['ark']['tar'] = case node['platform_family']
when 'windows'
"\"#{ENV['SYSTEMDRIVE']}\\7-zip\\7z.exe\""
"\"#{::Win32::Registry::HKEY_LOCAL_MACHINE.open(
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).read_s('Path')}\\7z.exe\""
when 'mac_os_x', 'freebsd'
'/usr/bin/tar'
when 'smartos'
Expand Down
21 changes: 20 additions & 1 deletion spec/recipes/windows/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ def node_attributes
let(:expected_packages) do
%w( libtool autoconf unzip rsync make gcc autogen xz-lzma-compat )
end

let(:fake_hkey_local_machine) do
fake_hkey_local_machine = double('fake_hkey_local_machine')
seven_zip_win32_registry = double('seven_zip_registry')
allow(seven_zip_win32_registry).to receive(:read_s).with('Path').and_return('C:\\Program Files\\7-Zip')
allow(fake_hkey_local_machine).to receive(:open).with('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).and_return(seven_zip_win32_registry)
fake_hkey_local_machine
end

before(:each) do
if not defined? ::Win32
module Win32
class Registry
end
end
end
stub_const("::Win32::Registry::KEY_READ", double('win32_registry_key_read'))
stub_const("::Win32::Registry::HKEY_LOCAL_MACHINE", fake_hkey_local_machine)
end

it 'does not installs packages' do
expected_packages.each do |package|
Expand All @@ -21,7 +40,7 @@ def node_attributes

context 'sets default attributes' do
it 'tar binary' do
expect(default_cookbook_attribute('tar')).to eq %("\\7-zip\\7z.exe")
expect(default_cookbook_attribute('tar')).to eq %("C:\\Program Files\\7-Zip\\7z.exe")
end
end
end
16 changes: 16 additions & 0 deletions spec/resources/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,25 @@
describe 'install on windows' do
let(:example_recipe) { 'ark_spec::install_windows' }

let(:fake_hkey_local_machine) do
fake_hkey_local_machine = double('fake_hkey_local_machine')
seven_zip_win32_registry = double('seven_zip_registry')
allow(seven_zip_win32_registry).to receive(:read_s).with('Path').and_return('C:\\Program Files\\7-Zip')
allow(fake_hkey_local_machine).to receive(:open).with('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe', ::Win32::Registry::KEY_READ).and_return(seven_zip_win32_registry)
fake_hkey_local_machine
end

before(:each) do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with('SystemRoot').and_return('C:\\Windows')
if not defined? ::Win32
module Win32
class Registry
end
end
end
stub_const("::Win32::Registry::KEY_READ", double('win32_registry_key_read'))
stub_const("::Win32::Registry::HKEY_LOCAL_MACHINE", fake_hkey_local_machine)
end

def node_attributes
Expand Down