Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Add brew-boxen-cask-install #57

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package { 'firefox': provider => 'brewcask' }

## Required Puppet Modules

- `homebrew`, >= 1.10.0
* `homebrew`, >= 1.10

## Work in progress
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this wasn't you but can you delete this section? I don't think it really adds any value or information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I same as puppuet-homebrew/README


Expand Down
4 changes: 4 additions & 0 deletions files/brew-boxen-cask-install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib")
require "hbc"

Hbc::CLI::Install.new(ARGV).run
29 changes: 17 additions & 12 deletions lib/puppet/provider/package/brewcask.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "puppet/provider/package"
require "puppet/util/execution"
require 'puppet/provider/package'
require 'puppet/util/execution'

Puppet::Type.type(:package).provide :brewcask, :parent => Puppet::Provider::Package do
include Puppet::Util::Execution
Expand Down Expand Up @@ -45,15 +45,20 @@ def query
end

def install
install_cmd = ['brew']
if install_options.any?
execute ["brew", "install", "Caskroom/cask/#{resource[:name]}", *install_options].flatten, command_opts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was only looking at why Canary wasn't installing for me last week and completely overlooked this.

install_cmd << 'cask install'
install_cmd << install_options
else
execute ["brew", "boxen-install", "Caskroom/cask/#{resource[:name]}"], command_opts
install_cmd << 'boxen-cask-install'
end
install_cmd << resource[:name]

execute install_cmd.flatten, command_opts
end

def uninstall
execute ["brew", "cask", "uninstall", "--force", resource[:name]]
execute ['brew', 'cask', 'uninstall', '--force', resource[:name]]
end

def install_options
Expand Down Expand Up @@ -86,18 +91,18 @@ def self.execute(*args)
end

def default_user
Facter.value(:boxen_user) || Facter.value(:id) || "root"
Facter.value(:boxen_user) || Facter.value(:id) || 'root'
end

def command_opts
opts = {
:combine => true,
:custom_environment => {
"HOME" => "/Users/#{default_user}",
"PATH" => "#{self.class.home}/bin:/usr/bin:/usr/sbin:/bin:/sbin",
"HOMEBREW_NO_EMOJI" => "Yes",
:combine => true,
:custom_environment => {
'HOME' => "/Users/#{default_user}",
'PATH' => "#{self.class.home}/bin:/usr/bin:/usr/sbin:/bin:/sbin",
'HOMEBREW_NO_EMOJI' => 'Yes',
},
:failonfail => true,
:failonfail => true,
}
# Only try to run as another user if Puppet is run as root.
opts[:uid] = default_user if Process.uid == 0
Expand Down
7 changes: 6 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
require homebrew

file { "${boxen::config::envdir}/10_brewcask.sh":
ensure => 'absent'
ensure => 'absent',
}

file { "${homebrew::config::brewsdir}/cmd/brew-boxen-cask-install.rb":
source => 'puppet:///modules/brewcask/brew-boxen-cask-install.rb',
mode => '0755',
}
}
12 changes: 12 additions & 0 deletions spec/classes/brewcask_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

describe 'brewcask' do
let(:facts) { default_test_facts }

it do
should contain_class('boxen::config')
should contain_class('homebrew')

should contain_file('/test/boxen/env.d/10_brewcask.sh').
with_ensure('absent')

should contain_file('/test/boxen/homebrew/Library/Taps/boxen-brews/cmd/brew-boxen-cask-install.rb').
with_source('puppet:///modules/brewcask/brew-boxen-cask-install.rb').
with_mode('0755')
end
end
14 changes: 7 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require "rspec-puppet"
require 'rspec-puppet'

fixture_path = File.expand_path File.join(__FILE__, "..", "fixtures")
fixture_path = File.expand_path File.join(__FILE__, '..', 'fixtures')

RSpec.configure do |c|
c.manifest_dir = File.join(fixture_path, "manifests")
c.module_path = File.join(fixture_path, "modules")
c.manifest_dir = File.join(fixture_path, 'manifests')
c.module_path = File.join(fixture_path, 'modules')
end

def default_test_facts
{
:boxen_home => "/test/boxen",
:boxen_srcdir => "/test/boxen/src",
:boxen_user => "testuser",
:boxen_home => '/test/boxen',
:boxen_srcdir => '/test/boxen/src',
:boxen_user => 'testuser',
}
end
76 changes: 76 additions & 0 deletions spec/unit/provider/package/brewcask_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require 'spec_helper'

provider = Puppet::Type.type(:package).provider(:brewcask)

describe provider do
it 'should have an install method' do
is_expected.to respond_to(:install)
end

it 'should have a uninstall method' do
is_expected.to respond_to(:uninstall)
end

it 'should not have a latst method' do
is_expected.not_to respond_to(:latest)
end

it 'should not have a update method' do
is_expected.not_to respond_to(:update)
end

describe 'when installing' do
context 'installing cask without install options' do
before do
@resource = Puppet::Type.type(:package).new(
:name => 'cask',
:ensure => :present,
:provider => :brewcask,
)
@provider = provider.new(@resource)
end

it 'should return install command' do
expect{ @provider.install }.to raise_error(Puppet::ExecutionFailure,
/brew boxen-cask-install cask/)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brew command is failed, so I check exception message command name.

end

it 'should return nil query' do
expect(@provider.query).to eq(nil)
end
end

context 'installing cask with install options' do
before do
@resource = Puppet::Type.type(:package).new(
:name => 'cask',
:ensure => :present,
:provider => :brewcask,
:install_options => '--foo',
)
@provider = provider.new(@resource)
end

it 'should return install command with install options' do
expect { @provider.install }.to raise_error(Puppet::ExecutionFailure,
/brew cask install --foo cask/)
end
end
end

describe 'when uninstalling' do
before do
@resource = Puppet::Type.type(:package).new(
:name => 'cask',
:ensure => :present,
:provider => :brewcask,
)
@provider = provider.new(@resource)
end

it 'should return uninstall command' do
expect { @provider.uninstall }.to raise_error(Puppet::ExecutionFailure,
/brew cask uninstall --force cask/)
end
end
end