summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-08-12 20:12:58 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-08-17 15:02:17 -0700
commite538037d00fe0a5eb71444383985969e308684b7 (patch)
tree10b9372015e5c626d2eade751ebf5289b7a80211
parentfb10fe7123da931438fe8ae255ed9a6c1168cd4d (diff)
downloadchef-e538037d00fe0a5eb71444383985969e308684b7.tar.gz
Add unit and integration testing back to omnibus testers
It is slow but it does catch real bugs Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--Rakefile2
-rw-r--r--chef-utils/lib/chef-utils/dsl/which.rb10
-rw-r--r--chef-utils/spec/unit/dsl/which_spec.rb2
-rw-r--r--omnibus/omnibus-test.ps18
-rw-r--r--omnibus/omnibus-test.sh29
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/platform_helpers.rb8
-rw-r--r--spec/support/shared/unit/application_dot_d.rb2
-rw-r--r--spec/unit/chef_fs/parallelizer_spec.rb6
-rw-r--r--spec/unit/knife/core/ui_spec.rb1
-rw-r--r--spec/unit/mixin/powershell_exec_spec.rb2
-rw-r--r--spec/unit/provider/package/powershell_spec.rb2
-rw-r--r--spec/unit/provider/package/rubygems_spec.rb5
-rw-r--r--spec/unit/run_lock_spec.rb6
-rw-r--r--spec/unit/util/selinux_spec.rb2
15 files changed, 52 insertions, 35 deletions
diff --git a/Rakefile b/Rakefile
index 052b5b9828..780e379ecd 100644
--- a/Rakefile
+++ b/Rakefile
@@ -108,4 +108,4 @@ begin
end
rescue LoadError
puts "yard is not available. bundle install first to make sure all dependencies are installed."
-end \ No newline at end of file
+end
diff --git a/chef-utils/lib/chef-utils/dsl/which.rb b/chef-utils/lib/chef-utils/dsl/which.rb
index a91e35da38..c1aa64c159 100644
--- a/chef-utils/lib/chef-utils/dsl/which.rb
+++ b/chef-utils/lib/chef-utils/dsl/which.rb
@@ -79,11 +79,15 @@ module ChefUtils
extra_path ||= __extra_path
paths = __env_path.split(File::PATH_SEPARATOR) + Array(extra_path)
paths.uniq!
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : []
+ exts.unshift("")
cmds.map do |cmd|
paths.map do |path|
- filename = File.join(path, cmd)
- filename if __valid_executable?(filename, &block)
- end.compact
+ exts.map do |ext|
+ filename = File.join(path, "#{cmd}#{ext}")
+ filename if __valid_executable?(filename, &block)
+ end.compact
+ end
end.flatten
end
diff --git a/chef-utils/spec/unit/dsl/which_spec.rb b/chef-utils/spec/unit/dsl/which_spec.rb
index cd867c4e72..941f6282a0 100644
--- a/chef-utils/spec/unit/dsl/which_spec.rb
+++ b/chef-utils/spec/unit/dsl/which_spec.rb
@@ -30,6 +30,7 @@ RSpec.describe ChefUtils::DSL::Which do
it description do
# stub the ENV['PATH']
expect(ENV).to receive(:[]).with("PATH").and_return(path)
+ expect(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
# most files should not be found
allow(File).to receive(:executable?).and_return(false)
@@ -109,6 +110,7 @@ RSpec.describe ChefUtils::DSL::Which do
it description do
# stub the ENV['PATH']
expect(ENV).to receive(:[]).with("PATH").and_return(path)
+ expect(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
# most files should not be found
allow(File).to receive(:executable?).and_return(false)
diff --git a/omnibus/omnibus-test.ps1 b/omnibus/omnibus-test.ps1
index 09a01c94bc..999f590495 100644
--- a/omnibus/omnibus-test.ps1
+++ b/omnibus/omnibus-test.ps1
@@ -1,6 +1,9 @@
# Stop script execution when a non-terminating error occurs
$ErrorActionPreference = "Stop"
+# install chocolatey
+Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
+
$channel = "$Env:CHANNEL"
If ([string]::IsNullOrEmpty($channel)) { $channel = "unstable" }
@@ -91,8 +94,5 @@ winrm quickconfig -quiet
bundle
If ($lastexitcode -ne 0) { Exit $lastexitcode }
-# FIXME: we need to add back unit and integration tests here. we have no coverage of those on e.g. AIX
-#
-# chocolatey functional tests fail so disable that tag directly <-- and this is a bug that needs fixing.
-bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f documentation --tag ~choco_installed spec/functional
+bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f progress --tag ~choco_installed
If ($lastexitcode -ne 0) { Exit $lastexitcode }
diff --git a/omnibus/omnibus-test.sh b/omnibus/omnibus-test.sh
index 3117d6efb6..30a41467dc 100644
--- a/omnibus/omnibus-test.sh
+++ b/omnibus/omnibus-test.sh
@@ -43,33 +43,28 @@ if [[ -f /etc/redhat-release ]]; then
fi
# Set up a custom tmpdir, and clean it up before and after the tests
-TMPDIR="${TMPDIR:-/tmp}/cheftest"
-export TMPDIR
+export TMPDIR="${TMPDIR:-/tmp}/cheftest"
sudo rm -rf "$TMPDIR"
mkdir -p "$TMPDIR"
# Verify that we kill any orphaned test processes. Kill any orphaned rspec processes.
sudo kill -9 $(ps ax | grep 'rspec' | grep -v grep | awk '{ print $1 }') || true
-PATH="/opt/$product/bin:$PATH"
-export PATH
+export PATH="/opt/$product/bin:$PATH"
-BIN_DIR="/opt/$product/bin"
-export BIN_DIR
+export BIN_DIR="/opt/$product/bin"
# We don't want to add the embedded bin dir to the main PATH as this
# could mask issues in our binstub shebangs.
-EMBEDDED_BIN_DIR="/opt/$product/embedded/bin"
-export EMBEDDED_BIN_DIR
+export EMBEDDED_BIN_DIR="/opt/$product/embedded/bin"
# If we are on Mac our symlinks are located under /usr/local/bin
# otherwise they are under /usr/bin
if [[ -f /usr/bin/sw_vers ]]; then
- USR_BIN_DIR="/usr/local/bin"
+ export USR_BIN_DIR="/usr/local/bin"
else
- USR_BIN_DIR="/usr/bin"
+ export USR_BIN_DIR="/usr/bin"
fi
-export USR_BIN_DIR
# sanity check that we're getting the correct symlinks from the pre-install script
# solaris doesn't have readlink or test -e. ls -n is different on BSD. proceed with caution.
@@ -127,17 +122,16 @@ chef-client --version
# ffi-yajl must run in c-extension mode or we take perf hits, so we force it
# before running rspec so that we don't wind up testing the ffi mode
-FORCE_FFI_YAJL=ext
-export FORCE_FFI_YAJL
+export FORCE_FFI_YAJL=ext
# chef-shell smoke tests require "rb-readline" which requires "infocmp"
# most platforms provide "infocmp" by default via an "ncurses" package but SLES 12 provide it via "ncurses-devel" which
# isn't typically installed. omnibus-toolchain has "infocmp" built-in so we add omnibus-toolchain to the PATH to ensure
# tests will function properly.
-PATH="/opt/$TOOLCHAIN/bin:/usr/local/bin:/opt/$TOOLCHAIN/embedded/bin:$PATH"
+export PATH="/opt/$TOOLCHAIN/bin:/usr/local/bin:/opt/$TOOLCHAIN/embedded/bin:$PATH"
# add chef's bin paths to PATH to ensure tests function properly
-PATH="/opt/$product/bin:/opt/$product/embedded/bin:$PATH"
+export PATH="/opt/$product/bin:/opt/$product/embedded/bin:$PATH"
gem_list="$(gem which chef)"
lib_dir="$(dirname "$gem_list")"
@@ -153,9 +147,8 @@ elif [[ -d /usr/local/etc/sudoers.d ]]; then
fi
# accept license
-CHEF_LICENSE=accept-no-persist
+export CHEF_LICENSE=accept-no-persist
cd "$chef_gem"
sudo -E bundle install --jobs=3 --retry=3
-# FIXME: we need to add back unit and integration tests here. we have no coverage of those on e.g. AIX
-sudo -E bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f documentation spec/functional
+sudo -E bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f progress
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 165f87327c..a80c1c3771 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -242,6 +242,8 @@ RSpec.configure do |config|
Chef::Log.setup!
+ Chef::ServerAPIVersions.instance.reset!
+
Chef::Config[:log_level] = :fatal
Chef::Log.level(Chef::Config[:log_level])
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index 8d21c5cbd2..2c83287959 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -58,17 +58,17 @@ end
def windows_2012r2?
return false unless windows?
- (host_version && host_version.start_with?("6.3"))
+ (win32_os_version && win32_os_version.start_with?("6.3"))
end
def windows_gte_10?
return false unless windows?
- Gem::Requirement.new(">= 10").satisfied_by?(Gem::Version.new(host_version))
+ Gem::Requirement.new(">= 10").satisfied_by?(Gem::Version.new(win32_os_version))
end
-def host_version
- @host_version ||= begin
+def win32_os_version
+ @win32_os_version ||= begin
wmi = WmiLite::Wmi.new
host = wmi.first_of("Win32_OperatingSystem")
host["version"]
diff --git a/spec/support/shared/unit/application_dot_d.rb b/spec/support/shared/unit/application_dot_d.rb
index a1606b4ff3..a9e6d46ad9 100644
--- a/spec/support/shared/unit/application_dot_d.rb
+++ b/spec/support/shared/unit/application_dot_d.rb
@@ -38,9 +38,11 @@ shared_examples_for "an application that loads a dot d" do
end
it "loads the configuration in order" do
+ etc_chef_client_rb = Chef::Config.platform_specific_path("#{Chef::Dist::CONF_DIR}/client.rb")
expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_return("foo 0")
expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_return("bar 0")
expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/02-strings.rb").cleanpath.to_s).and_return("strings 0")
+ allow(app).to receive(:apply_config).with("", etc_chef_client_rb) # for chef-client managed nodes running this spec
expect(app).to receive(:apply_config).with("foo 0", Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_call_original.ordered
expect(app).to receive(:apply_config).with("bar 0", Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_call_original.ordered
expect(app).to receive(:apply_config).with("strings 0", Pathname.new("#{client_d_dir}/02-strings.rb").cleanpath.to_s).and_call_original.ordered
diff --git a/spec/unit/chef_fs/parallelizer_spec.rb b/spec/unit/chef_fs/parallelizer_spec.rb
index 3c675e74fe..519a628347 100644
--- a/spec/unit/chef_fs/parallelizer_spec.rb
+++ b/spec/unit/chef_fs/parallelizer_spec.rb
@@ -1,7 +1,11 @@
require "spec_helper"
require "chef/chef_fs/parallelizer"
-describe Chef::ChefFS::Parallelizer do
+# FIXME: these are disabled on MacOS due to timing issues in our anka build cluster
+# these issues should be fixed and the tests should be re-eenabled. If we are getting
+# omnibus test phases on mac tests which are reasonable and not ~3 hours long, then the
+# condition to avoid this testing on macs can be deleted
+describe Chef::ChefFS::Parallelizer, :not_supported_on_macos do
before :each do
@start_time = Time.now
end
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index c37bbf8e1e..3bbe799267 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -510,6 +510,7 @@ describe Chef::Knife::UI do
describe "color" do
context "when ui.color? => true" do
it "returns colored output" do
+ skip "doesn't work on systems that don't correctly have terminals setup for color"
expect(@ui).to receive(:color?).and_return(true)
expect(@ui.color("a_bus_is", :yellow)).to eql("\e[33ma_bus_is\e[0m")
end
diff --git a/spec/unit/mixin/powershell_exec_spec.rb b/spec/unit/mixin/powershell_exec_spec.rb
index fce73453a9..9cc5e50d7f 100644
--- a/spec/unit/mixin/powershell_exec_spec.rb
+++ b/spec/unit/mixin/powershell_exec_spec.rb
@@ -19,7 +19,7 @@
require "spec_helper"
require "chef/mixin/powershell_exec"
-describe Chef::Mixin::PowershellExec, :windows_only do
+describe Chef::Mixin::PowershellExec, :windows_only, :windows_gte_10 do
let(:powershell_mixin) { Class.new { include Chef::Mixin::PowershellExec } }
subject(:object) { powershell_mixin.new }
diff --git a/spec/unit/provider/package/powershell_spec.rb b/spec/unit/provider/package/powershell_spec.rb
index 482b19c218..256901c928 100644
--- a/spec/unit/provider/package/powershell_spec.rb
+++ b/spec/unit/provider/package/powershell_spec.rb
@@ -19,7 +19,7 @@
require "spec_helper"
require "chef/mixin/powershell_out"
-describe Chef::Provider::Package::Powershell, :windows_only do
+describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
include Chef::Mixin::PowershellOut
let(:timeout) { 900 }
let(:source) { nil }
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb
index d2b2a66027..6f31c231ce 100644
--- a/spec/unit/provider/package/rubygems_spec.rb
+++ b/spec/unit/provider/package/rubygems_spec.rb
@@ -387,8 +387,9 @@ describe Chef::Provider::Package::Rubygems do
before(:each) do
# We choose detect omnibus via RbConfig::CONFIG['bindir'] in Chef::Provider::Package::Rubygems.new
allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(bindir)
- # Rubygems uses this interally
+ # Rubygems uses these two interally
allow(RbConfig::CONFIG).to receive(:[]).with("arch").and_call_original
+ allow(RbConfig::CONFIG).to receive(:[]).with("ruby_install_name").and_call_original
allow(File).to receive(:executable?).and_return false
allow(File).to receive(:executable?).with("#{bindir}/gem").and_return true
# XXX: we can't stub the provider object directly here because referencing it will create it and that
@@ -467,6 +468,7 @@ describe Chef::Provider::Package::Rubygems do
it "searches for a gem binary when running on Omnibus on Unix" do
platform_mock :unix do
allow(ENV).to receive(:[]).with("PATH").and_return("/usr/bin:/usr/sbin:/opt/chef/embedded/bin")
+ allow(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
allow(File).to receive(:executable?).with("/usr/bin/gem").and_return(false)
allow(File).to receive(:executable?).with("/usr/sbin/gem").and_return(true)
allow(File).to receive(:executable?).with("/opt/chef/embedded/bin/gem").and_return(true) # should not get here
@@ -480,6 +482,7 @@ describe Chef::Provider::Package::Rubygems do
it "searches for a gem binary when running on Omnibus on Windows" do
platform_mock :windows do
allow(ENV).to receive(:[]).with("PATH").and_return('C:\windows\system32;C:\windows;C:\Ruby186\bin')
+ allow(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
allow(File).to receive(:executable?).with('C:\\windows\\system32/gem').and_return(false)
allow(File).to receive(:executable?).with('C:\\windows/gem').and_return(false)
allow(File).to receive(:executable?).with('C:\\Ruby186\\bin/gem').and_return(true)
diff --git a/spec/unit/run_lock_spec.rb b/spec/unit/run_lock_spec.rb
index 17e6fb6521..3459f86f68 100644
--- a/spec/unit/run_lock_spec.rb
+++ b/spec/unit/run_lock_spec.rb
@@ -18,7 +18,11 @@
require "spec_helper"
require "chef/client"
-describe Chef::RunLock do
+# FIXME: these are disabled on MacOS due to timing issues in our anka build cluster
+# these issues should be fixed and the tests should be re-eenabled. If we are getting
+# omnibus test phases on mac tests which are reasonable and not ~3 hours long, then the
+# condition to avoid this testing on macs can be deleted
+describe Chef::RunLock, :not_supported_on_macos do
default_cache_path = windows? ? 'C:\chef' : "/var/chef"
default_pid_location = windows? ? 'C:\chef\cache\chef-client-running.pid' : "/var/chef/cache/chef-client-running.pid"
diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb
index 2a4b26b2b6..72a0824895 100644
--- a/spec/unit/util/selinux_spec.rb
+++ b/spec/unit/util/selinux_spec.rb
@@ -31,6 +31,8 @@ describe Chef::Util::Selinux do
before do
allow(ChefUtils).to receive(:windows?).and_return(false)
+ allow(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
+ allow(ENV).to receive(:[]).with("PATH").and_call_original
TestClass.reset_state
@test_instance = TestClass.new
end