Skip to content

Commit

Permalink
Don't include helpers in the universal dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
bmhughes committed Mar 26, 2021
1 parent 118728f commit 0c9a3a4
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 12 deletions.
2 changes: 0 additions & 2 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,3 @@ def ubuntu_18?
end
end
end

Chef::DSL::Universal.include(Nginx::Cookbook::Helpers)
2 changes: 2 additions & 0 deletions resources/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#

include Nginx::Cookbook::Helpers

deprecated_property_alias 'user',
'process_user',
'The user property was renamed process_user in the 11.3 release of this cookbook. Please update your cookbooks to use the new property name. This alias will be removed in the next major version.'
Expand Down
4 changes: 4 additions & 0 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#

include Nginx::Cookbook::Helpers

property :ohai_plugin_enabled, [true, false],
description: 'Whether or not ohai_plugin is enabled.',
default: true
Expand All @@ -39,6 +41,8 @@
coerce: proc { |p| p.is_a?(Array) ? p : [p] }

action_class do
include Nginx::Cookbook::Helpers

def ohai_plugin_enabled?
new_resource.ohai_plugin_enabled
end
Expand Down
2 changes: 2 additions & 0 deletions resources/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#

include Nginx::Cookbook::Helpers

property :service_name, String,
default: lazy { default_nginx_service_name },
description: 'The service name to perform actions upon'
Expand Down
2 changes: 2 additions & 0 deletions resources/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#

include Nginx::Cookbook::Helpers

property :conf_dir, String,
description: 'The directory to create the site configuraiton file in.',
default: lazy { nginx_config_site_dir }
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'chefspec'
require 'chefspec/berkshelf'
require_relative '../libraries/helpers'

Dir['libraries/*.rb'].sort.each { |f| require File.expand_path(f) }
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }

RSpec.configure do |config|
Expand Down
2 changes: 1 addition & 1 deletion spec/support/install.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def repo_url
def platform_repo_url
case chefspec_platform
when 'amazon', 'fedora', 'redhat'
'https://nginx.org/packages/rhel/7/$basearch'
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/resources/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'nginx_config' do
step_into :nginx_config, :nginx_install, :nginx_site
platform 'ubuntu'
platform 'centos'

before do
stub_command('/usr/sbin/nginx -t').and_return(true)
Expand All @@ -21,8 +21,8 @@
.with_variables(
nginx_dir: '/etc/nginx',
nginx_log_dir: '/var/log/nginx',
process_user: 'www-data',
process_group: 'www-data',
process_user: 'nginx',
process_group: 'nginx',
worker_processes: 'auto',
pid: '/run/nginx.pid',
worker_connections: '1024',
Expand All @@ -43,11 +43,11 @@
nginx_log_dir: '/var/log/nginx',
port: '80',
server_name: 'Fauxhai',
default_root: '/var/www/html'
default_root: '/usr/share/nginx/html'
)
end

it { is_expected.to create_directory('/var/log/nginx').with_mode('0750').with_owner(nginx_user) }
it { is_expected.to create_directory('/var/log/nginx').with_mode('0750').with_owner('nginx') }
it { is_expected.to create_directory('/etc/nginx/conf.d').with_mode('0750') }
it { is_expected.to create_directory('/etc/nginx/conf.http.d').with_mode('0750') }
end
Expand Down
7 changes: 4 additions & 3 deletions spec/unit/resources/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe 'nginx_install' do
step_into :nginx_install
platform 'centos'

before do
stub_command('dnf module list nginx | grep -q "^nginx.*\\[x\\]"').and_return(false)
Expand Down Expand Up @@ -71,15 +72,15 @@
shared_examples_for 'yum repository is created' do
it do
is_expected.to create_yum_repository('nginx')
.with_baseurl(repo_url)
.with_baseurl(platform_repo_url)
.with_gpgkey(repo_signing_key)
end
end

shared_examples_for 'apt repository is added' do
it do
is_expected.to add_apt_repository('nginx')
.with_uri(repo_url)
.with_uri(platform_repo_url)
.with_distribution(platform_distribution_nginx)
.with_components(%w(nginx))
.with_deb_src(true)
Expand Down Expand Up @@ -125,7 +126,7 @@

it do
is_expected.to create_zypper_repository('nginx')
.with_baseurl(repo_url)
.with_baseurl(platform_repo_url)
.with_gpgkey(repo_signing_key)
end
end
Expand Down

0 comments on commit 0c9a3a4

Please sign in to comment.