summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBhavesh Davda <bhavesh.davda@oracle.com>2021-03-25 16:10:54 -0700
committerBhavesh Davda <bhavesh.davda@oracle.com>2021-03-25 16:21:32 -0700
commitcee306bf3c3de883af53e1ee43c30c55a1e18c3f (patch)
tree7e5784c53e12f9950bd0d83c1eb36a926e334b85
parent479ec9919b0ad4a4c9c9c6b9b5ec0bbac938fb12 (diff)
downloadohai-cee306bf3c3de883af53e1ee43c30c55a1e18c3f.tar.gz
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 <bhavesh.davda@oracle.com>
-rw-r--r--spec/unit/plugins/c_spec.rb43
1 files changed, 13 insertions, 30 deletions
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:
- <http://www.gnu.org/software/libc/bugs.html>.
+ 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