From cee306bf3c3de883af53e1ee43c30c55a1e18c3f Mon Sep 17 00:00:00 2001 From: Bhavesh Davda Date: Thu, 25 Mar 2021 16:10:54 -0700 Subject: Ohai: Fix unit tests for C-language glibc version check Replace invocation of libc.so.6 with "ldd --version" instead Signed-off-by: Bhavesh Davda --- spec/unit/plugins/c_spec.rb | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'spec/unit/plugins') diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb index 0b895291..e89b941d 100644 --- a/spec/unit/plugins/c_spec.rb +++ b/spec/unit/plugins/c_spec.rb @@ -28,25 +28,11 @@ C_GCC = <<~EOF.freeze EOF C_GLIBC = <<~EOF.freeze - GNU C Library stable release version 2.5, by Roland McGrath et al. - Copyright (C) 2006 Free Software Foundation, Inc. - This is free software; see the source for copying conditions. - There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A - PARTICULAR PURPOSE. - Compiled by GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-44). - Compiled on a Linux 2.6.9 system on 2009-09-02. - Available extensions: - The C stubs add-on version 2.1.2. - crypt add-on version 2.1 by Michael Glad and others - GNU Libidn by Simon Josefsson - GNU libio by Per Bothner - NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk - Native POSIX Threads Library by Ulrich Drepper et al - BIND-8.2.3-T5B - RT using linux kernel aio - Thread-local storage support included. - For bug reporting instructions, please see: - . + ldd (GNU libc) 2.17 + Copyright (C) 2012 Free Software Foundation, Inc. + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + Written by Roland McGrath and Ulrich Drepper. EOF C_CL = <<~EOF.freeze @@ -224,8 +210,7 @@ describe Ohai::System, "plugin c" do before do allow(plugin).to receive(:collect_os).and_return(:linux) # glibc - allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, "")) - allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, "")) + allow(plugin).to receive(:shell_out).with("ldd --version").and_return(mock_shell_out(0, C_GLIBC, "")) # sun pro allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN)) end @@ -275,8 +260,8 @@ describe Ohai::System, "plugin c" do end # glibc - it "gets the glibc x.x.x version from running /lib/libc.so.6" do - expect(plugin).to receive(:shell_out).with("/lib/libc.so.6") + it "gets the glibc x.x.x version from running ldd" do + expect(plugin).to receive(:shell_out).with("ldd --version") plugin.run end @@ -291,23 +276,21 @@ describe Ohai::System, "plugin c" do end it "does not set the languages[:c][:glibc] tree up if glibc exits nonzero" do - allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(1, "", "")) - allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(1, "", "")) + allow(plugin).to receive(:shell_out).with("ldd --version").and_return(mock_shell_out(1, "", "")) plugin.run expect(plugin[:languages][:c]).not_to have_key(:glibc) end it "does not set the languages[:c][:glibc] tree up if glibc fails" do - allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_raise(Ohai::Exceptions::Exec) - allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_raise(Ohai::Exceptions::Exec) + allow(plugin).to receive(:shell_out).with("ldd --version").and_raise(Ohai::Exceptions::Exec) plugin.run expect(plugin[:languages][:c]).not_to have_key(:glibc) expect(plugin[:languages][:c]).not_to be_empty # expect other attributes end - it "gets the glibc x.x version from running /lib/libc.so.6" do - allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, "")) - expect(plugin).to receive(:shell_out).with("/lib/libc.so.6") + it "gets the glibc x.x version from running ldd" do + allow(plugin).to receive(:shell_out).with("ldd --version").and_return(mock_shell_out(0, C_GLIBC, "")) + expect(plugin).to receive(:shell_out).with("ldd --version") plugin.run expect(plugin.languages[:c][:glibc][:version]).to eql("2.5") end -- cgit v1.2.1 From 426f5852142dd9b0fa36057c838db56bc36ed8f1 Mon Sep 17 00:00:00 2001 From: Bhavesh Davda Date: Thu, 25 Mar 2021 16:21:59 -0700 Subject: Ohai: Fix C-language unit test to match new versions and strings for glibc Signed-off-by: Bhavesh Davda --- spec/unit/plugins/c_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/unit/plugins') diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb index e89b941d..e80737e4 100644 --- a/spec/unit/plugins/c_spec.rb +++ b/spec/unit/plugins/c_spec.rb @@ -267,12 +267,12 @@ describe Ohai::System, "plugin c" do it "sets languages[:c][:glibc][:version]", :unix_only do plugin.run - expect(plugin.languages[:c][:glibc][:version]).to eql("2.5") + expect(plugin.languages[:c][:glibc][:version]).to eql("2.17") end it "sets languages[:c][:glibc][:description]" do plugin.run - expect(plugin.languages[:c][:glibc][:description]).to eql("GNU C Library stable release version 2.5, by Roland McGrath et al.") + expect(plugin.languages[:c][:glibc][:description]).to eql("ldd (GNU libc) 2.17") end it "does not set the languages[:c][:glibc] tree up if glibc exits nonzero" do @@ -292,7 +292,7 @@ describe Ohai::System, "plugin c" do allow(plugin).to receive(:shell_out).with("ldd --version").and_return(mock_shell_out(0, C_GLIBC, "")) expect(plugin).to receive(:shell_out).with("ldd --version") plugin.run - expect(plugin.languages[:c][:glibc][:version]).to eql("2.5") + expect(plugin.languages[:c][:glibc][:version]).to eql("2.17") end # sun pro -- cgit v1.2.1