-
Notifications
You must be signed in to change notification settings - Fork 19
/
hwinfo_reader_test.rb
executable file
·114 lines (99 loc) · 3.71 KB
/
hwinfo_reader_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env rspec
#
# Copyright (c) [2017-2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require_relative "spec_helper"
require "y2storage/hwinfo_reader"
describe Y2Storage::HWInfoReader do
let(:reader) { described_class.instance }
let(:hwinfo_output) { File.read(File.join(DATA_PATH, hwinfo_file)) }
let(:hwinfo_file) { "hwinfo.txt" }
before do
# Disable the global mock that normally prevents calls to hwinfo
allow(reader).to receive(:for_device).and_call_original
allow(Yast::Execute).to receive(:on_target!)
.with(/hwinfo/, anything, anything, anything).and_return(hwinfo_output)
reader.reset
end
describe "#for_device" do
it "returns hardware information for the given device" do
data = reader.for_device("/dev/sda")
expect(data).to be_a(Y2Storage::HWInfoDisk)
expect(data.to_h)
.to include(bus: "IDE",
unique_id: "3OOL.7kkY9irDFZ4",
driver_modules: ["ahci"],
driver: ["ahci", "sd"],
io_ports: "0xe000-0xefff rw",
geometry_logical: "CHS 121601/255/63")
end
it "supports alternative devices names" do
data = reader.for_device("/dev/sg1")
expect(data.device_file).to eq(["/dev/sdb", "/dev/sg1"])
end
it "retrieves hardware information from hwinfo" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/sbin/hwinfo", "--disk", "--listmd", stdout: :capture)
.and_return(hwinfo_output)
reader.for_device("/dev/sda")
end
it "caches hardware information" do
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/sbin/hwinfo", "--disk", "--listmd", stdout: :capture)
.and_return(hwinfo_output)
.once
reader.for_device("/dev/sda")
reader.for_device("/dev/sda")
end
it "returns an empty object for non-existing device names" do
data = reader.for_device("/dev/nothing")
expect(data).to be_a(Y2Storage::HWInfoDisk)
expect(data).to be_empty
end
context "when the system contains some zFCP multipath device" do
let(:hwinfo_file) { "hwinfo_bug1982536.txt" }
# Regression test for bug#1982536
it "does not raise any exception" do
expect { reader.for_device("/dev/sda") }.to_not raise_error
end
it "returns hardware information for the given device" do
data = reader.for_device("/dev/sda")
expect(data).to be_a(Y2Storage::HWInfoDisk)
expect(data.to_h)
.to include(bus: "SCSI",
driver_modules: ["zfcp", "sd_mod"],
driver: ["zfcp", "sd"],
geometry_logical: "CHS 20480/64/32")
end
end
end
describe "#reset" do
context "when information is cached" do
before do
reader.for_device("/dev/sda")
end
it "resets information" do
reader.reset
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/sbin/hwinfo", "--disk", "--listmd", stdout: :capture)
reader.for_device("/dev/sda")
end
end
end
end