diff --git a/lib/specinfra/helper/detect_os/suse.rb b/lib/specinfra/helper/detect_os/suse.rb index 1e460be4..6837b300 100644 --- a/lib/specinfra/helper/detect_os/suse.rb +++ b/lib/specinfra/helper/detect_os/suse.rb @@ -12,7 +12,9 @@ def detect if line =~ /VERSION_ID=\"(\d+\.\d+|\d+)\"/ release = $1 end - { :family => family, :release => release } + if family + { :family => family, :release => release } + end elsif run_command('ls /etc/SuSE-release').success? and run_command('zypper -V').success? line = run_command('cat /etc/SuSE-release').stdout if line =~ /SUSE Linux Enterprise Server (\d+)/ diff --git a/spec/helper/detect_os/suse_spec.rb b/spec/helper/detect_os/suse_spec.rb index ad292670..1f91fe1f 100644 --- a/spec/helper/detect_os/suse_spec.rb +++ b/spec/helper/detect_os/suse_spec.rb @@ -39,4 +39,10 @@ :release => '11.4' ) end + it 'should not assume the system is SUSE just because zypper is installed' do + allow(suse).to receive(:run_command) { + CommandResult.new(:stdout => "PRETTY_NAME=\"Debian GNU/Linux forky/sid\"\nNAME=\"Debian GNU/Linux\"\nVERSION_CODENAME=forky\nID=debian\nHOME_URL=\"https://www.debian.org/\"\nSUPPORT_URL=\"https://www.debian.org/support\"\nBUG_REPORT_URL=\"https://bugs.debian.org/\"\n", :exit_status => 0) + } + expect(suse.detect).to be_nil + end end