spec/unit/plugins/darwin/filesystem_spec.rb in ohai-8.26.1 vs spec/unit/plugins/darwin/filesystem_spec.rb in ohai-13.0.0
- old
+ new
@@ -14,21 +14,26 @@
# 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.
#
-require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
+require_relative "../../../spec_helper.rb"
describe Ohai::System, "darwin filesystem plugin" do
let (:plugin) { get_plugin("darwin/filesystem") }
before(:each) do
allow(plugin).to receive(:collect_os).and_return(:darwin)
allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, "", ""))
allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
end
+ it "sets both filesystem and filesystem2 attributes" do
+ plugin.run
+ expect(plugin[:filesystem]).to eq(plugin[:filesystem2])
+ end
+
describe "when gathering filesystem usage data from df" do
before(:each) do
@stdout = <<-DF
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /
@@ -46,26 +51,27 @@
plugin.run
end
it "should set size to value from df -i" do
plugin.run
- expect(plugin[:filesystem]["/dev/disk0s2"][:kb_size]).to eq(244277768)
- expect(plugin[:filesystem]["/dev/disk0s2"][:kb_used]).to eq(156848224)
- expect(plugin[:filesystem]["/dev/disk0s2"][:kb_available]).to eq(87173544)
- expect(plugin[:filesystem]["/dev/disk0s2"][:percent_used]).to eq("65%")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_size]).to eq("244277768")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_used]).to eq("156848224")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_available]).to eq("87173544")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:percent_used]).to eq("65%")
end
- it "should set mount to value from df -i" do
+ it "should set device and mount to value from df -i" do
plugin.run
- expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:device]).to eq("/dev/disk0s2")
end
it "should set inode info to value from df -i" do
plugin.run
- expect(plugin[:filesystem]["/dev/disk0s2"][:total_inodes]).to eq("61069440")
- expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_used]).to eq("39276054")
- expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_available]).to eq("21793386")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:total_inodes]).to eq("61069440")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_used]).to eq("39276054")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_available]).to eq("21793386")
end
end
describe "when gathering mounted filesystem data from mount" do
before(:each) do
@@ -85,11 +91,54 @@
plugin.run
end
it "should set values from mount" do
plugin.run
- expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/")
- expect(plugin[:filesystem]["/dev/disk0s2"][:fs_type]).to eq("hfs")
- expect(plugin[:filesystem]["/dev/disk0s2"][:mount_options]).to eq(%w{local journaled})
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:fs_type]).to eq("hfs")
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount_options]).to eq(%w{local journaled})
+ end
+ end
+
+ describe "when gathering filesystem data with devices mounted more than once" do
+ before(:each) do
+ @dfstdout = <<-DF
+Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
+/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /
+devfs 385 385 0 100% 666 0 100% /dev
+map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol
+map -hosts 0 0 0 100% 0 0 100% /net
+map -static 0 0 0 100% 0 0 100% /mobile_symbol
+deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey
+/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /another/mountpoint
+DF
+ allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, ""))
+ end
+
+ it "should provide a devices view with all mountpoints" do
+ plugin.run
+ expect(plugin[:filesystem]["by_device"]["/dev/disk0s2"][:mounts]).to eq(["/", "/another/mountpoint"])
+ end
+ end
+
+ describe "when gathering filesystem data with double-mounts" do
+ before(:each) do
+ @dfstdout = <<-DF
+Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
+/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /
+devfs 385 385 0 100% 666 0 100% /dev
+map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol
+map -hosts 0 0 0 100% 0 0 100% /net
+map -static 0 0 0 100% 0 0 100% /mobile_symbol
+deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey
+/dev/disk0s3 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt
+/dev/disk0s4 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt
+DF
+ allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, ""))
+ end
+
+ it "should provide a mounts view with all devices" do
+ plugin.run
+ expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/disk0s3", "/dev/disk0s4"])
end
end
end