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. #153

Merged
merged 1 commit into from
May 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
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
4 changes: 3 additions & 1 deletion spec/recipes/windows/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'spec_helper'

describe_recipe 'ark::default' do
include_context 'seven zip installed'

def node_attributes
{ platform: 'windows', version: '2012R2' }
end
Expand All @@ -21,7 +23,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
2 changes: 2 additions & 0 deletions spec/resources/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
end

describe 'install on windows' do
include_context('seven zip installed')

let(:example_recipe) { 'ark_spec::install_windows' }

before(:each) do
Expand Down
21 changes: 21 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,24 @@ def recipe_name
cookbook_recipe_names.last
end
end

shared_context 'seven zip installed' do
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
unless defined? ::Win32
module Win32
class Registry
end
end
end
stub_const('::Win32::Registry::KEY_READ', double('win32_registry_key_read')) unless defined? ::Win32::Registry::KEY_READ
stub_const('::Win32::Registry::HKEY_LOCAL_MACHINE', fake_hkey_local_machine)
end
end