diff --git a/libraries/helpers.rb b/libraries/helpers.rb index bf53a88c..0b2012f2 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -103,5 +103,3 @@ def ubuntu_18? end end end - -Chef::DSL::Universal.include(Nginx::Cookbook::Helpers) diff --git a/resources/config.rb b/resources/config.rb index 9c655c3f..47335de9 100644 --- a/resources/config.rb +++ b/resources/config.rb @@ -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.' diff --git a/resources/install.rb b/resources/install.rb index 56f4b2c4..eab0a4fb 100644 --- a/resources/install.rb +++ b/resources/install.rb @@ -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 @@ -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 diff --git a/resources/service.rb b/resources/service.rb index 40e42dd6..f07d1068 100644 --- a/resources/service.rb +++ b/resources/service.rb @@ -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' diff --git a/resources/site.rb b/resources/site.rb index e49e89e0..5d3c8626 100644 --- a/resources/site.rb +++ b/resources/site.rb @@ -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 } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ca390425..d87acd73 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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| diff --git a/spec/support/install.rb b/spec/support/install.rb index 854b5237..3b369a13 100644 --- a/spec/support/install.rb +++ b/spec/support/install.rb @@ -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' diff --git a/spec/unit/resources/config_spec.rb b/spec/unit/resources/config_spec.rb index e777cd37..825e3c62 100644 --- a/spec/unit/resources/config_spec.rb +++ b/spec/unit/resources/config_spec.rb @@ -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) @@ -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', @@ -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 diff --git a/spec/unit/resources/install_spec.rb b/spec/unit/resources/install_spec.rb index 39b5993b..62b68045 100644 --- a/spec/unit/resources/install_spec.rb +++ b/spec/unit/resources/install_spec.rb @@ -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) @@ -71,7 +72,7 @@ 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 @@ -79,7 +80,7 @@ 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) @@ -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