summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-09-21 18:23:51 -0700
committerGitHub <noreply@github.com>2021-09-21 18:23:51 -0700
commit37d9db0b37dd81255df29db13f94a845f0bd1c9b (patch)
tree9ffe96023e6dbb59e64e0739afb1558e5d31029f
parentbba62ea2b0df158116d722ba63a9a203fa729767 (diff)
parent2cd4f286f5b5f0d5e5641a7329e07d461539e5be (diff)
downloadchef-37d9db0b37dd81255df29db13f94a845f0bd1c9b.tar.gz
Merge pull request #12070 from jasonwbarnett/fix/windows-functional-testing-for-archive_file
Fix windows CI for archive_file
-rw-r--r--spec/functional/resource/archive_file_spec.rb3
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/support/ruby_installer.rb51
-rw-r--r--spec/unit/resource/archive_file_spec.rb15
4 files changed, 55 insertions, 15 deletions
diff --git a/spec/functional/resource/archive_file_spec.rb b/spec/functional/resource/archive_file_spec.rb
index 11ef5fa5fc..1289bc0fad 100644
--- a/spec/functional/resource/archive_file_spec.rb
+++ b/spec/functional/resource/archive_file_spec.rb
@@ -18,8 +18,7 @@
require "spec_helper"
require "tmpdir"
-# Excluding this test on Windows until CI issues can be addressed.
-describe Chef::Resource::ArchiveFile, :not_supported_on_windows do
+describe Chef::Resource::ArchiveFile do
include RecipeDSLHelper
let(:tmp_path) { Dir.mktmpdir }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9aafbfa994..afcaf955c5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -68,6 +68,7 @@ end
require "spec/support/local_gems" if File.exist?(File.join(File.dirname(__FILE__), "support", "local_gems.rb"))
# Explicitly require spec helpers that need to load first
+require "spec/support/ruby_installer"
require "spec/support/platform_helpers"
require "spec/support/shared/unit/mock_shellout"
diff --git a/spec/support/ruby_installer.rb b/spec/support/ruby_installer.rb
new file mode 100644
index 0000000000..ae282d3b2d
--- /dev/null
+++ b/spec/support/ruby_installer.rb
@@ -0,0 +1,51 @@
+#
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+def add_libarchive_dll_directory
+ require "ruby_installer"
+ libarchive_paths = Dir.glob("{#{Gem.dir},C:/hab}/**/libarchive.dll").map { |f| File.expand_path(f) }
+ if libarchive_paths.empty?
+ $stderr.puts <<~EOL
+ !!!!
+ We couldn't find a libarchive.dll in #{Gem.dir} or C:/hab
+
+ If this is running in a CI/CD environment, this may end up causing failures
+ in the tests for archive_file. If this is not running in a CI/CD
+ environment then it may be safe to ignore this. That is especially true if
+ you're not using the Ruby Installer as your Ruby runtime.
+ !!!!
+ EOL
+ return
+ end
+
+ $stderr.puts "\nFound the following libarchive paths:\n\n#{libarchive_paths.map { |f| "- #{f}\n" }.join}\n\n"
+ libarchive_path = libarchive_paths.first
+ libarchive_dir = File.dirname(libarchive_path)
+
+ if defined?(RubyInstaller::Build) && RubyInstaller::Build.methods.include?(:add_dll_directory)
+ $stderr.puts "Adding #{libarchive_dir} as a DLL load path using RubyInstaller::Build#add_dll_directory"
+ RubyInstaller::Build.add_dll_directory(libarchive_dir)
+ elsif defined?(RubyInstaller::Runtime) && RubyInstaller::Runtime.methods.include?(:add_dll_directory)
+ $stderr.puts "Adding #{libarchive_dir} as a DLL load path using RubyInstaller::Runtime#add_dll_directory"
+ RubyInstaller::Runtime.add_dll_directory(libarchive_dir)
+ else
+ $stderr.puts "Unable to find the right namespace to call #add_dll_directory! Please raise an issue on [GitHub](https://github.com/chef/chef/issues/new/choose)."
+ end
+rescue LoadError
+ $stderr.puts "Failed to load ruby_installer. Assuming Ruby Installer is not being used."
+end
+
+add_libarchive_dll_directory if RUBY_PLATFORM =~ /mswin|mingw32|windows/
diff --git a/spec/unit/resource/archive_file_spec.rb b/spec/unit/resource/archive_file_spec.rb
index 63096cb6ee..8fbd4a8ce1 100644
--- a/spec/unit/resource/archive_file_spec.rb
+++ b/spec/unit/resource/archive_file_spec.rb
@@ -16,21 +16,10 @@
#
require "spec_helper"
-
-begin
- require 'ffi-libarchive'
-rescue LoadError
- module Archive
- class Reader
- def close; end
- def each_entry; end
- def extract(entry, flags = 0, destination: nil); end
- end
- end
-end
+require 'ffi-libarchive'
# Excluding this test on Windows until CI issues can be addressed.
-describe Chef::Resource::ArchiveFile, :not_supported_on_windows do
+describe Chef::Resource::ArchiveFile do
let(:node) { Chef::Node.new }
let(:events) { Chef::EventDispatch::Dispatcher.new }
let(:run_context) { Chef::RunContext.new(node, {}, events) }