* bump version

* New Keep Awake Tests (#99)

* Add test case for portable bare metal

* rename systemsetup to system

* Fix spec_helper to use system

* cookstyle changes

* Add CONTRIBUTING.md and reference Contributing to Chef Managed Community Cookbooks (#97)

* Add keychain guards (#100)

* update keep_awake documentation regarding spec testing (#101)

* refactor location of shared_examples

* don't stub git

* don't test library specific methods in recipe testing

* remove nil and any references to node attributes in system library

* add tests for when node attributes are nil

* make variable names more descriptive
This commit is contained in:
Jacob Zaval 2018-04-25 10:32:20 -07:00 коммит произвёл GitHub
Родитель cb551382c9
Коммит 465c29d5f7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 79 добавлений и 50 удалений

1
CONTRIBUTING.md Normal file
Просмотреть файл

@ -0,0 +1 @@
Please refer to [Contributing to Chef Managed Community Cookbooks](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for guidelines on contributing to this cookbook.

Просмотреть файл

@ -64,6 +64,18 @@ to always keep macOS on and available.
| `node['macos']['network_time_server']` | `'time.windows.com'` |
| `node['macos']['time_zone']` | `'America/Los_Angeles'` |
**N.b.** When ChefSpec testing implementations of this recipe, the `node['hardware']['machine_model']`
attribute needs to be set to a Mac model identifier, e.g. `MacMini6,2`, in order
for tests to pass:
```ruby
let(:chef_run) do
ChefSpec::SoloRunner.new do |node|
node.normal['hardware']['machine_model'] = 'MacMini6,2'
end.converge(described_recipe)
end
```
### Mono
Installs [Mono](http://www.mono-project.com/docs/about-mono/). Requires setting

Просмотреть файл

@ -3,12 +3,8 @@ module MacOS
class FormFactor
attr_reader :machine_model
def initialize(machine_model = nil)
@machine_model = if Chef.node.nil?
machine_model
else
Chef.node['hardware']['machine_model']
end
def initialize(machine_model)
@machine_model = machine_model
end
def desktop?
@ -25,12 +21,8 @@ module MacOS
class Environment
attr_reader :virtualization_systems
def initialize(virtualization_systems = nil)
@virtualization_systems = if Chef.node.nil?
virtualization_systems
else
Chef.node['virtualization']['systems']
end
def initialize(virtualization_systems)
@virtualization_systems = virtualization_systems
end
def vm?
@ -40,12 +32,9 @@ module MacOS
class ScreenSaver
attr_reader :user
def initialize(user = nil)
@user = if Chef.node.nil?
user
else
Chef.node['macos']['admin_user']
end
def initialize(user)
@user = user
end
def disabled?

Просмотреть файл

@ -5,7 +5,7 @@ license 'MIT'
description 'Resources for configuring and provisioning macOS'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
chef_version '>= 13.0' if respond_to?(:chef_version)
version '1.12.0'
version '1.13.0'
source_url 'https://github.com/Microsoft/macos-cookbook'
issues_url 'https://github.com/Microsoft/macos-cookbook/issues'

Просмотреть файл

@ -1,6 +1,6 @@
form_factor = MacOS::System::FormFactor.new()
env = MacOS::System::Environment.new()
scr_svr = MacOS::System::ScreenSaver.new()
form_factor = MacOS::System::FormFactor.new(node['hardware']['machine_model'])
environment = MacOS::System::Environment.new(node['virtualization']['systems'])
screensaver = MacOS::System::ScreenSaver.new(node['macos']['admin_user'])
system_preference 'disable computer sleep' do
preference :computersleep
@ -25,13 +25,13 @@ end
system_preference 'wake the computer when accessed using a network connection' do
preference :wakeonnetworkaccess
setting 'On'
not_if { env.vm? }
not_if { environment.vm? }
end
system_preference 'restart after a power failure' do
preference :restartpowerfailure
setting 'On'
not_if { env.vm? }
not_if { environment.vm? }
end
system_preference 'pressing power button does not sleep computer' do
@ -67,6 +67,6 @@ end
defaults 'com.apple.screensaver' do
option '-currentHost write'
settings 'idleTime' => 0
not_if { scr_svr.disabled? }
not_if { screensaver.disabled? }
user node['macos']['admin_user']
end

Просмотреть файл

@ -15,6 +15,7 @@ action :create do
execute 'create a keychain' do
command [*keyc.create_keychain(new_resource.kc_passwd)]
not_if { ::File.exist?(keychain) }
end
end
@ -22,6 +23,7 @@ action :delete do
keyc = SecurityCommand.new('', keychain)
execute 'delete selected keychain' do
command [*keyc.delete_keychain]
only_if { ::File.exist?(keychain) }
end
end
@ -29,11 +31,13 @@ action :lock do
keyc = SecurityCommand.new('', keychain)
execute 'lock selected keychain' do
command [*keyc.lock_keychain]
only_if { ::File.exist?(keychain) }
end
end
action :unlock do
keyc = SecurityCommand.new('', keychain) do
command [*keyc.unlock_keychain(new_resource.kc_passwd)]
only_if { ::File.exist?(keychain) }
end
end

Просмотреть файл

@ -5,7 +5,7 @@ require_relative '../libraries/macos_user'
require_relative '../libraries/machine_name'
require_relative '../libraries/metadata_util'
require_relative '../libraries/plist'
require_relative '../libraries/systemsetup'
require_relative '../libraries/system'
require_relative '../libraries/xcode'
require_relative '../libraries/xcversion'
require_relative '../libraries/command_line_tools'

Просмотреть файл

@ -72,6 +72,20 @@ describe MacOS::System::FormFactor do
expect(ff.portable?).to eq false
end
end
context 'when passed a machine model that is nil' do
it 'it does not register as form factor desktop' do
ff = MacOS::System::FormFactor.new(nil)
expect(ff.desktop?).to eq false
end
end
context 'when passed a machine model that is nil' do
it 'it does not register as form factor portable' do
ff = MacOS::System::FormFactor.new(nil)
expect(ff.portable?).to eq false
end
end
end
describe MacOS::System::Environment do

Просмотреть файл

@ -3,18 +3,12 @@ require 'spec_helper'
include MacOS::System
shared_context 'when running on bare metal macmini' do
before(:each) do
chef_run.node.normal['virtualization']['systems'] = { 'vbox' => 'host', 'parallels' => 'host' }
chef_run.node.normal['hardware']['machine_model'] = 'MacMini6,2'
end
shared_examples 'setting metal-specific power preferences' do
before(:each) do
chef_run.node.normal['hardware']['machine_model'] = 'MacMini6,2'
chef_run.node.normal['virtualization']['systems'] = { 'vbox' => 'host', 'parallels' => 'host' }
stub_command('which git').and_return('/usr/bin/git')
end
it 'returns false' do
env = System::Environment.new('host')
expect(env.vm?).to be false
end
it 'sets wake on lan' do
chef_run.converge(described_recipe)
expect(chef_run).to set_system_preference('wake the computer when accessed using a network connection')
@ -36,19 +30,36 @@ shared_context 'when running on bare metal macmini' do
end
end
shared_context 'when running on bare metal macbook' do
before(:each) do
chef_run.node.normal['virtualization']['systems'] = { 'vbox' => 'host', 'parallels' => 'host' }
chef_run.node.normal['hardware']['machine_model'] = 'Macbook10,1'
end
shared_examples 'setting portable metal-specific power preferences' do
it 'sets wake on lan' do
chef_run.converge(described_recipe)
expect(chef_run).to set_system_preference('wake the computer when accessed using a network connection')
end
it 'sets restart after a power failure' do
chef_run.converge(described_recipe)
expect(chef_run).to set_system_preference('restart after a power failure')
end
it 'converges successfully on bare metal' do
expect { chef_run }.to_not raise_error
end
end
end
shared_context 'running in a parallels virtual machine' do
before(:each) do
chef_run.node.normal['virtualization']['systems'] = { 'parallels' => 'guest' }
chef_run.node.normal['hardware']['machine_model'] = 'Parallels13,1'
stub_command('which git').and_return('/usr/bin/git')
end
shared_examples 'not setting metal-specific power prefs' do
it 'confirms we are in a vm' do
env = System::Environment.new()
expect(env.vm?).to be true
end
it 'does not set wake on lan' do
chef_run.converge(described_recipe)
expect(chef_run).to_not set_system_preference('wake the computer when accessed using a network connection')
@ -63,7 +74,6 @@ shared_context 'running in a parallels virtual machine' do
chef_run.converge(described_recipe)
expect(chef_run).to_not set_system_preference('restart after a power failure')
end
it 'converges successfully in a vm' do
expect { chef_run }.to_not raise_error
end
@ -74,15 +84,9 @@ shared_context 'running in an undetermined virtualization system' do
before(:each) do
chef_run.node.normal['virtualization']['systems'] = {}
chef_run.node.normal['hardware']['machine_model'] = ''
stub_command('which git').and_return('/usr/bin/git')
end
shared_examples 'not setting metal-specific power prefs' do
it 'assumes we are in a vm' do
env = System::Environment.new('undetermined')
expect(env.vm?).to be true
end
it 'does not set wake on lan' do
chef_run.converge(described_recipe)
expect(chef_run).to_not set_system_preference('wake the computer when accessed using a network connection')
@ -121,4 +125,9 @@ describe 'macos::keep_awake' do
include_context 'when running on bare metal macmini'
it_behaves_like 'setting metal-specific power preferences'
end
describe 'keep_awake on portable bare metal' do
include_context 'when running on bare metal macbook'
it_behaves_like 'setting portable metal-specific power preferences'
end
end