Skip to content

Commit

Permalink
Merge pull request #10401 from chef/file
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Sep 10, 2020
2 parents 969cf79 + c0fe791 commit ee5a3d5
Show file tree
Hide file tree
Showing 38 changed files with 52 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bin/knife
Expand Up @@ -18,7 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
$:.unshift(File.expand_path(File.join(__dir__, "..", "lib")))
require "chef/application/knife"

Chef::Application::Knife.new.run
2 changes: 1 addition & 1 deletion chef-bin/bin/chef-apply
Expand Up @@ -18,7 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
$:.unshift(File.join(__dir__, "..", "lib"))
require "chef/application/apply"

Chef::Application::Apply.new.run(enforce_license: true)
2 changes: 1 addition & 1 deletion chef-bin/bin/chef-client
Expand Up @@ -18,7 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
$:.unshift(File.join(__dir__, "..", "lib"))
require "chef"
require "chef/application/client"

Expand Down
2 changes: 1 addition & 1 deletion chef-bin/bin/chef-resource-inspector
Expand Up @@ -19,7 +19,7 @@

Encoding.default_external = Encoding::UTF_8

$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
$:.unshift(File.expand_path(File.join(__dir__, "..", "lib")))

require "chef/resource_inspector"

Expand Down
2 changes: 1 addition & 1 deletion chef-bin/bin/chef-service-manager
Expand Up @@ -18,7 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
$:.unshift(File.join(__dir__, "..", "lib"))
require "chef"
require "chef/application/windows_service_manager"
require "chef/dist"
Expand Down
2 changes: 1 addition & 1 deletion chef-bin/bin/chef-shell
Expand Up @@ -24,7 +24,7 @@ require "irb"
require "irb/completion"
require "irb/ext/save-history"

$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
$:.unshift(File.expand_path(File.join(__dir__, "..", "lib")))

require "chef/shell"

Expand Down
2 changes: 1 addition & 1 deletion chef-bin/bin/chef-solo
Expand Up @@ -18,7 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
$:.unshift(File.join(__dir__, "..", "lib"))
require "chef/application/solo"

Chef::Application::Solo.new.run(enforce_license: true)
2 changes: 1 addition & 1 deletion chef-bin/bin/chef-windows-service
Expand Up @@ -23,7 +23,7 @@
# generate will call that file, and will be registered as
# a windows service.

$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
$:.unshift(File.join(__dir__, "..", "lib"))
require "chef"
require "chef/application/windows_service"

Expand Down
2 changes: 1 addition & 1 deletion lib/chef/knife/bootstrap.rb
Expand Up @@ -489,7 +489,7 @@ def find_template

# Otherwise search the template directories until we find the right one
bootstrap_files = []
bootstrap_files << File.join(File.dirname(__FILE__), "bootstrap/templates", "#{template}.erb")
bootstrap_files << File.join(__dir__, "bootstrap/templates", "#{template}.erb")
bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{template}.erb") if Chef::Knife.chef_config_dir
Chef::Util::PathHelper.home(".chef", "bootstrap", "#{template}.erb") { |p| bootstrap_files << p }
bootstrap_files << Gem.find_files(File.join("chef", "knife", "bootstrap", "#{template}.erb"))
Expand Down
Expand Up @@ -22,7 +22,7 @@
# This is required to make Chef tools use https URLs out of the box.

unless ENV.key?("SSL_CERT_FILE")
base_dirs = File.dirname(__FILE__).split(File::SEPARATOR)
base_dirs = __dir__.split(File::SEPARATOR)

(base_dirs.length - 1).downto(0) do |i|
candidate_ca_bundle = File.join(base_dirs[0..i] + [ "ssl/certs/cacert.pem" ])
Expand Down
2 changes: 1 addition & 1 deletion omnibus_overrides.rb
Expand Up @@ -29,5 +29,5 @@
# is in master, which won't match what's in the Gemfile.lock and used by the chef
# definition. This pin will ensure that ohai and chef-client commands use the
# same (released) version of ohai.
gemfile_lock = File.join(File.expand_path(File.dirname(__FILE__)), "Gemfile.lock")
gemfile_lock = File.join(File.expand_path(__dir__), "Gemfile.lock")
override "ohai", version: "#{::File.readlines(gemfile_lock).find { |l| l =~ /^\s+ohai \((\d+\.\d+\.\d+)\)/ }; "v" + $1}" # rubocop: disable Layout/SpaceInsideStringInterpolation
2 changes: 1 addition & 1 deletion spec/data/shef-config.rb
Expand Up @@ -7,5 +7,5 @@
ohai[:disabled_plugins] << "solaris2::virtualization" << "solaris2::zpools"
ohai[:disabled_plugins] << "c" << "php" << "mono" << "groovy" << "lua" << "erlang"
ohai[:disabled_plugins] << "kernel" << "linux::filesystem" << "ruby"
chef_repo_path File.dirname(__FILE__)
chef_repo_path __dir__
cookbook_path "#{chef_repo_path}/cookbooks"
4 changes: 2 additions & 2 deletions spec/functional/resource/aix_service_spec.rb
Expand Up @@ -89,7 +89,7 @@ def get_user_id

describe "When service is a subsystem" do
before(:all) do
script_dir = File.join(File.dirname(__FILE__), "/../assets/")
script_dir = File.join(__dir__, "/../assets/")
shell_out!("mkssys -s ctestsys -p #{script_dir}/testchefsubsys -u #{get_user_id} -S -n 15 -f 9 -R -Q")
end

Expand Down Expand Up @@ -117,7 +117,7 @@ def get_user_id
# Cannot run this test on a WPAR
describe "When service is a group", :not_wpar do
before(:all) do
script_dir = File.join(File.dirname(__FILE__), "/../assets/")
script_dir = File.join(__dir__, "/../assets/")
shell_out!("mkssys -s ctestsys -p #{script_dir}/testchefsubsys -u #{get_user_id} -S -n 15 -f 9 -R -Q -G ctestgrp")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functional/resource/aixinit_service_spec.rb
Expand Up @@ -69,7 +69,7 @@ def delete_test_files

before(:all) do
File.delete("/etc/rc.d/init.d/chefinittest") if File.exist?("/etc/rc.d/init.d/chefinittest")
FileUtils.cp((File.join(File.dirname(__FILE__), "/../assets/chefinittest")).to_s, "/etc/rc.d/init.d/chefinittest")
FileUtils.cp((File.join(__dir__, "/../assets/chefinittest")).to_s, "/etc/rc.d/init.d/chefinittest")
end

after(:all) do
Expand Down
2 changes: 1 addition & 1 deletion spec/functional/resource/insserv_spec.rb
Expand Up @@ -74,7 +74,7 @@ def delete_test_files

before(:all) do
File.delete("/etc/init.d/inittest") if File.exist?("/etc/init.d/inittest")
FileUtils.cp((File.join(File.dirname(__FILE__), "/../assets/inittest")).to_s, "/etc/init.d/inittest")
FileUtils.cp((File.join(__dir__, "/../assets/inittest")).to_s, "/etc/init.d/inittest")
FileUtils.chmod(0755, "/etc/init.d/inittest")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functional/version_spec.rb
Expand Up @@ -23,7 +23,7 @@

describe "Chef Versions", :executables do
include Chef::Mixin::ShellOut
let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..") }
let(:chef_dir) { File.join(__dir__, "..", "..") }

binaries = [ Chef::Dist::CLIENT, "chef-shell", "chef-apply", "knife", Chef::Dist::SOLOEXEC ]

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/client/client_spec.rb
Expand Up @@ -34,7 +34,7 @@ def stop_tiny_server
include IntegrationSupport
include Chef::Mixin::ShellOut

let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
let(:chef_dir) { File.join(__dir__, "..", "..", "..", "bin") }

# Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the
# following constraints are satisfied:
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/client/exit_code_spec.rb
Expand Up @@ -11,7 +11,7 @@
include IntegrationSupport
include Chef::Mixin::ShellOut

let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
let(:chef_dir) { File.join(__dir__, "..", "..", "..", "bin") }

# Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the
# following constraints are satisfied:
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/client/ipv6_spec.rb
Expand Up @@ -74,7 +74,7 @@
basic_config_file
end

let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
let(:chef_dir) { File.join(__dir__, "..", "..", "..", "bin") }

let(:chef_client_cmd) { %Q{bundle exec chef-client --minimal-ohai -c "#{path_to("config/client.rb")}" -lwarn} }

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/knife/cookbook_api_ipv6_spec.rb
Expand Up @@ -62,7 +62,7 @@
Dir.mktmpdir
end

let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
let(:chef_dir) { File.join(__dir__, "..", "..", "..", "bin") }
let(:knife) { "ruby '#{chef_dir}/knife'" }

let(:knife_config_flag) { "-c '#{path_to("config/knife.rb")}'" }
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/recipes/remote_directory.rb
Expand Up @@ -5,7 +5,7 @@
include Chef::Mixin::ShellOut

# Until Cheffish::RSpec has cookbook support, we have to run the whole client
let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
let(:chef_dir) { File.join(__dir__, "..", "..", "..", "bin") }

# Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the
# following constraints are satisfied:
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/solo/solo_spec.rb
Expand Up @@ -12,7 +12,7 @@
include IntegrationSupport
include Chef::Mixin::ShellOut

let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..") }
let(:chef_dir) { File.join(__dir__, "..", "..", "..") }

let(:cookbook_x_100_metadata_rb) { cb_metadata("x", "1.0.0") }

Expand Down Expand Up @@ -183,7 +183,7 @@
# run_lock gets stuck we can discover it.
expect do
Timeout.timeout(120) do
chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..")
chef_dir = File.join(__dir__, "..", "..", "..")

threads = []

Expand Down
2 changes: 1 addition & 1 deletion spec/stress/win32/file_spec.rb
Expand Up @@ -21,7 +21,7 @@

describe "Chef::ReservedNames::Win32::File", :windows_only do
before(:each) do
@path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "data", "old_home_dir", "my-dot-emacs"))
@path = File.expand_path(File.join(__dir__, "..", "..", "data", "old_home_dir", "my-dot-emacs"))
end

it "should not leak significant memory", :volatile do
Expand Down
4 changes: 2 additions & 2 deletions spec/support/chef_helpers.rb
Expand Up @@ -14,8 +14,8 @@
# limitations under the License.
#

CHEF_SPEC_DATA = File.expand_path(File.dirname(__FILE__) + "/../data/")
CHEF_SPEC_ASSETS = File.expand_path(File.dirname(__FILE__) + "/../functional/assets/")
CHEF_SPEC_DATA = File.expand_path(__dir__ + "/../data/")
CHEF_SPEC_ASSETS = File.expand_path(__dir__ + "/../functional/assets/")
CHEF_SPEC_BACKUP_PATH = File.join(Dir.tmpdir, "test-backup-path")

def sha256_checksum(path)
Expand Down
4 changes: 2 additions & 2 deletions spec/support/matchers/leak.rb
Expand Up @@ -61,10 +61,10 @@ def match(measure, given_proc)
def profiler
@profiler ||= begin
if ChefUtils.windows?
require File.join(File.dirname(__FILE__), "..", "platforms", "prof", "win32")
require File.join(__dir__, "..", "platforms", "prof", "win32")
RSpec::Prof::Win32::Profiler.new
else
require File.join(File.dirname(__FILE__), "..", "prof", "gc")
require File.join(__dir__, "..", "prof", "gc")
RSpec::Prof::GC::Profiler.new
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared/functional/win32_service.rb
Expand Up @@ -42,7 +42,7 @@ def cleanup
service_name: "spec-service",
service_display_name: "Spec Test Service",
service_description: "Service for testing Chef::Application::WindowsServiceManager.",
service_file_path: File.expand_path(File.join(File.dirname(__FILE__), "../../platforms/win32/spec_service.rb")),
service_file_path: File.expand_path(File.join(__dir__, "../../platforms/win32/spec_service.rb")),
delayed_start: true,
}
end
Expand Down
6 changes: 3 additions & 3 deletions spec/support/shared/unit/application_dot_d.rb
Expand Up @@ -33,7 +33,7 @@
# make sure that we are correctly globbing.
let(:client_d_dir) do
Chef::Util::PathHelper.cleanpath(
File.join(File.dirname(__FILE__), "../../../data/client.d_00")
File.join(__dir__, "../../../data/client.d_00")
)
end

Expand All @@ -53,7 +53,7 @@
context "when client_d_dir is set to a directory without configuration" do
let(:client_d_dir) do
Chef::Util::PathHelper.cleanpath(
File.join(File.dirname(__FILE__), "../../data/client.d_01")
File.join(__dir__, "../../data/client.d_01")
)
end

Expand All @@ -71,7 +71,7 @@
# foo.rb as a directory should be ignored
let(:client_d_dir) do
Chef::Util::PathHelper.cleanpath(
File.join(File.dirname(__FILE__), "../../data/client.d_02")
File.join(__dir__, "../../data/client.d_02")
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/chef_fs/path_util_spec.rb
Expand Up @@ -61,7 +61,7 @@
end

context "invoking realest_path" do
let(:good_path) { File.dirname(__FILE__) }
let(:good_path) { __dir__ }
let(:parent_path) { File.dirname(good_path) }

it "handles paths with no wildcards or globs" do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/cookbook_spec.rb
Expand Up @@ -19,10 +19,10 @@
require "spec_helper"

describe Chef::CookbookVersion do
COOKBOOK_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks", "openldap"))
COOKBOOK_PATH = File.expand_path(File.join(__dir__, "..", "data", "cookbooks", "openldap"))

before(:each) do
@cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
@cookbook_repo = File.expand_path(File.join(__dir__, "..", "data", "cookbooks"))
cl = Chef::CookbookLoader.new(@cookbook_repo)
cl.load_cookbooks
@cookbook_collection = Chef::CookbookCollection.new(cl)
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/dsl/declare_resource_spec.rb
Expand Up @@ -19,7 +19,7 @@

describe Chef::ResourceCollection do
let(:run_context) do
cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "data", "cookbooks"))
cookbook_repo = File.expand_path(File.join(__dir__, "..", "..", "data", "cookbooks"))
cookbook_loader = Chef::CookbookLoader.new(cookbook_repo)
cookbook_loader.load_cookbooks
node = Chef::Node.new
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/file_access_control_spec.rb
Expand Up @@ -26,7 +26,7 @@
# we have to re-load the file so the proper
# platform specific module is mixed in
@node = Chef::Node.new
load File.join(File.dirname(__FILE__), "..", "..", "lib", "chef", "file_access_control.rb")
load File.join(__dir__, "..", "..", "lib", "chef", "file_access_control.rb")
@resource = Chef::Resource::File.new("/tmp/a_file.txt")
@resource.owner("toor")
@resource.group("wheel")
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/knife/bootstrap_spec.rb
Expand Up @@ -185,7 +185,7 @@
context "when :bootstrap_template config is set to a template name" do
let(:bootstrap_template) { "example" }

let(:builtin_template_path) { File.expand_path(File.join(File.dirname(__FILE__), "../../../lib/chef/knife/bootstrap/templates", "example.erb")) }
let(:builtin_template_path) { File.expand_path(File.join(__dir__, "../../../lib/chef/knife/bootstrap/templates", "example.erb")) }

let(:chef_config_dir_template_path) { "/knife/chef/config/bootstrap/example.erb" }

Expand Down Expand Up @@ -472,7 +472,7 @@ def configure_gem_files
end

describe "when transferring trusted certificates" do
let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(File.dirname(__FILE__), "../../data/trusted_certs")) }
let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(__dir__, "../../data/trusted_certs")) }

let(:rendered_template) do
knife.merge_configs
Expand Down Expand Up @@ -504,7 +504,7 @@ def certificates
end

context "when :trusted_cets_dir is empty" do
let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(File.dirname(__FILE__), "../../data/trusted_certs_empty")) }
let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(__dir__, "../../data/trusted_certs_empty")) }
it "doesn't create /etc/chef/trusted_certs if :trusted_certs_dir is empty" do
expect(rendered_template).not_to match(%r{mkdir -p /etc/chef/trusted_certs})
end
Expand All @@ -514,7 +514,7 @@ def certificates

context "when doing fips things" do
let(:template_file) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "no_proxy.erb")) }
let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(File.dirname(__FILE__), "../../data/trusted_certs")) }
let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(__dir__, "../../data/trusted_certs")) }

before do
Chef::Config[:knife][:bootstrap_template] = template_file
Expand Down Expand Up @@ -570,7 +570,7 @@ def certificates
context "when client_d_dir is set" do
let(:client_d_dir) do
Chef::Util::PathHelper.cleanpath(
File.join(File.dirname(__FILE__), "../../data/client.d_00")
File.join(__dir__, "../../data/client.d_00")
)
end

Expand All @@ -597,7 +597,7 @@ def certificates
context "a nested directory structure" do
let(:client_d_dir) do
Chef::Util::PathHelper.cleanpath(
File.join(File.dirname(__FILE__), "../../data/client.d_01")
File.join(__dir__, "../../data/client.d_01")
)
end
it "creates a file foo/bar.rb" do
Expand Down

0 comments on commit ee5a3d5

Please sign in to comment.