-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add rspec tests for Apple M1 silicon Homebrew path helper * Add Homebrew.install_path() helper for Apple M1 silicon (arm64) * Add HomebrewWrapper class to use install_path() M1 detection function * Convert /usr/local to use install_path() for M1 /opt/homebrew support * Fixing InSpec tests for macOS M1 / arm64 and x86_64 Note: InSpec running as root will not have PATH to Homebrew set up. Thus, package checks will fail if `inspec --sudo` is used * Remove deprecated full option for Homebrew (Breaking upstream change!) Error was: Error: Calling the `--full` switch is disabled! There is no replacement. * Use private macOS Vagrant boxes w/up-to-date Chef Infra & InSpec for testing this cookbook * Add Homebrew.repository_path() helper for Apple M1 silicon (arm64) * Use HomebrewWrapper.repository_path() for homebrew_tap resource idempotency on Apple M1 silicon (arm64) * Revert "Use private macOS Vagrant boxes [...]" for upstream pull request This reverts commit 5a9f462. * CHANGELOG.md: Update Unreleased section w/Apple M1 changes * CHANGELOG.md: Fix markdownlint issues * Autocorrect Cookstyle issues
- Loading branch information
1 parent
8e02dce
commit 2980305
Showing
10 changed files
with
149 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ provisioner: | |
|
||
verifier: | ||
name: inspec | ||
sudo: false | ||
|
||
platforms: | ||
- name: macos-10.12 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'chef/mixin/shell_out' | ||
|
||
describe Homebrew do | ||
let(:opt_homebrew_path) { '/opt/homebrew' } | ||
let(:usr_local_homebrew_path) { '/usr/local' } | ||
let(:usr_local_repository_path) { '/usr/local/Homebrew' } | ||
|
||
let(:shellout) do | ||
double(command: 'sysctl -n hw.optional.arm64', run_command: nil, error!: nil, stdout: arm64_test_output, | ||
stderr: stderr, exitstatus: exitstatus, live_stream: nil) | ||
end | ||
|
||
before(:each) do | ||
allow(Mixlib::ShellOut).to receive(:new).and_return(shellout) | ||
allow(shellout).to receive(:live_stream=).and_return(nil) | ||
end | ||
|
||
context 'when on Apple arm64 Silicon' do | ||
let(:arm64_test_output) { "1\n" } | ||
let(:exitstatus) { 0 } | ||
let(:stderr) { double(empty?: true) } | ||
|
||
describe '#install_path' do | ||
let(:dummy_class) { Class.new { include Homebrew } } | ||
it 'returns /opt/homebrew path' do | ||
expect(dummy_class.new.install_path).to eq opt_homebrew_path | ||
end | ||
end | ||
|
||
describe '#repository_path' do | ||
let(:dummy_class) { Class.new { include Homebrew } } | ||
it 'returns /opt/homebrew path' do | ||
expect(dummy_class.new.repository_path).to eq opt_homebrew_path | ||
end | ||
end | ||
end | ||
|
||
context 'when on Apple Intel Silicon' do | ||
let(:arm64_test_output) { '' } | ||
let(:exitstatus) { 1 } | ||
let(:stderr) { 'sysctl: unknown oid \'hw.optional.arm64\'' } | ||
|
||
describe '#install_path' do | ||
let(:dummy_class) { Class.new { include Homebrew } } | ||
it 'returns /usr/local path' do | ||
expect(dummy_class.new.install_path).to eq usr_local_homebrew_path | ||
end | ||
end | ||
|
||
describe '#install_path' do | ||
let(:dummy_class) { Class.new { include Homebrew } } | ||
it 'returns /usr/local/Homebrew path' do | ||
expect(dummy_class.new.repository_path).to eq usr_local_repository_path | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
describe command('brew info redis --json=v1 | jq ".[].installed[0].installed_on_request"') do | ||
its('stdout') { should match('true') } | ||
# Check both x86_64 and arm64 locations for brew | ||
# Depending on shell setup in the box: | ||
# InSpec commands want a full path, but this depends on arch + platform_version | ||
# macOS default shell may be /bin/bash or /bin/zsh ... back to basics: /bin/sh | ||
describe command('/bin/sh -c "PATH=/opt/homebrew/bin:/usr/local/bin:$PATH brew --version"') do | ||
its('stdout') { should match('^Homebrew.*$') } | ||
end | ||
|
||
describe file('/usr/local/Caskroom/caffeine') do | ||
brew_prefix = command('/bin/sh -c "PATH=/opt/homebrew/bin:/usr/local/bin:$PATH brew --prefix"').stdout.chomp | ||
describe brew_prefix do | ||
it { should match('^(\/usr\/local|\/opt\/homebrew)$') } | ||
end | ||
|
||
describe file(brew_prefix) do | ||
it { should be_directory } | ||
end | ||
|
||
brew_caskroom = command('/bin/sh -c "PATH=/opt/homebrew/bin:/usr/local/bin:$PATH brew --caskroom"').stdout.chomp | ||
describe brew_caskroom do | ||
it { should match('^(\/usr\/local|\/opt\/homebrew)/Caskroom$') } | ||
end | ||
|
||
describe file(brew_caskroom) do | ||
it { should be_directory } | ||
end | ||
|
||
describe package('redis') do | ||
it { should be_installed } | ||
end | ||
|
||
describe package('jq') do | ||
it { should be_installed } | ||
end | ||
|
||
# CI agnostic caskroom owner check | ||
# InSpec may be running commands w/sudo | ||
ci_user = command('whoami').stdout.chomp | ||
if ci_user == 'root' | ||
ci_user = command("/bin/sh -c 'echo $SUDO_USER'").stdout.chomp | ||
end | ||
describe file("#{brew_caskroom}/caffeine") do | ||
it { should be_directory } | ||
its('mode') { should cmp '0755' } | ||
it { should be_owned_by 'runner' } | ||
it { should be_owned_by ci_user } | ||
end |
This could be done with an ohai attribute to avoid another shellout every time the resource runs