|
17 | 17 | # limitations under the License. |
18 | 18 | # |
19 | 19 |
|
20 | | -require 'spec_helper' |
21 | | -require 'ohai/mixin/oci_metadata' |
| 20 | +require "spec_helper" |
| 21 | +require "ohai/mixin/oci_metadata" |
22 | 22 |
|
23 | 23 | describe Ohai::Mixin::OCIMetadata do |
24 | 24 | let(:mixin) do |
|
27 | 27 | end |
28 | 28 |
|
29 | 29 | before do |
30 | | - logger = instance_double('Mixlib::Log::Child', trace: nil, debug: nil, warn: nil) |
| 30 | + logger = instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil) |
31 | 31 | allow(mixin).to receive(:logger).and_return(logger) |
32 | 32 | end |
33 | 33 |
|
34 | | - describe '#http_get' do |
35 | | - it 'gets the passed URI' do |
36 | | - http_mock = double('http') |
| 34 | + describe "#http_get" do |
| 35 | + it "gets the passed URI" do |
| 36 | + http_mock = double("http") |
37 | 37 | allow(http_mock).to receive(:read_timeout=) |
38 | 38 | allow(Net::HTTP).to receive(:start).with(Ohai::Mixin::OCIMetadata::OCI_METADATA_ADDR).and_return(http_mock) |
39 | 39 |
|
40 | 40 | expect(http_mock).to receive(:get).with(Ohai::Mixin::OCIMetadata::OCI_METADATA_ADDR, |
41 | | - { 'Authorization' => 'Bearer Oracle', |
42 | | - 'User-Agent' => "chef-ohai/#{Ohai::VERSION}" }) |
| 41 | + { "Authorization" => "Bearer Oracle", |
| 42 | + "User-Agent" => "chef-ohai/#{Ohai::VERSION}" }) |
43 | 43 | mixin.http_get(Ohai::Mixin::OCIMetadata::OCI_METADATA_ADDR) |
44 | 44 | end |
45 | 45 | end |
46 | 46 |
|
47 | | - describe '#fetch_metadata' do |
48 | | - it 'returns an empty hash given a non-200 response' do |
49 | | - http_mock = double('http', { code: '404' }) |
| 47 | + describe "#fetch_metadata" do |
| 48 | + it "returns an empty hash given a non-200 response" do |
| 49 | + http_mock = double("http", { code: "404" }) |
50 | 50 | allow(mixin).to receive(:http_get).and_return(http_mock) |
51 | 51 |
|
52 | 52 | expect(mixin.logger).to receive(:warn) |
53 | 53 | vals = mixin.fetch_metadata |
54 | 54 | expect(vals).to eq(nil) |
55 | 55 | end |
56 | 56 |
|
57 | | - it 'returns a populated hash given valid JSON response' do |
58 | | - http_mock = double('http', { code: '200', body: '{ "foo": "bar"}' }) |
| 57 | + it "returns a populated hash given valid JSON response" do |
| 58 | + http_mock = double("http", { code: "200", body: '{ "foo": "bar"}' }) |
59 | 59 | allow(mixin).to receive(:http_get).and_return(http_mock) |
60 | 60 |
|
61 | 61 | expect(mixin.logger).not_to receive(:warn) |
62 | 62 | vals = mixin.fetch_metadata |
63 | | - expect(vals).to eq({ 'foo' => 'bar' }) |
| 63 | + expect(vals).to eq({ "foo" => "bar" }) |
64 | 64 | end |
65 | 65 | end |
66 | 66 |
|
67 | | - describe '#chassis_asset_tag' do |
68 | | - context 'on Windows platform' do |
| 67 | + describe "#chassis_asset_tag" do |
| 68 | + context "on Windows platform" do |
69 | 69 | before do |
70 | | - stub_const('RUBY_PLATFORM', 'mswin') |
| 70 | + stub_const("RUBY_PLATFORM", "mswin") |
71 | 71 | end |
72 | 72 |
|
73 | | - it 'calls get_chassis_asset_tag_windows' do |
74 | | - expect(mixin).to receive(:get_chassis_asset_tag_windows).and_return('test-asset-tag') |
75 | | - expect(mixin.chassis_asset_tag).to eq('test-asset-tag') |
| 73 | + it "calls get_chassis_asset_tag_windows" do |
| 74 | + expect(mixin).to receive(:get_chassis_asset_tag_windows).and_return("test-asset-tag") |
| 75 | + expect(mixin.chassis_asset_tag).to eq("test-asset-tag") |
76 | 76 | end |
77 | 77 | end |
78 | 78 |
|
79 | | - context 'on non-Windows platform' do |
| 79 | + context "on non-Windows platform" do |
80 | 80 | before do |
81 | | - stub_const('RUBY_PLATFORM', 'linux') |
| 81 | + stub_const("RUBY_PLATFORM", "linux") |
82 | 82 | end |
83 | 83 |
|
84 | | - it 'calls get_chassis_asset_tag_linux' do |
85 | | - expect(mixin).to receive(:get_chassis_asset_tag_linux).and_return('test-asset-tag') |
86 | | - expect(mixin.chassis_asset_tag).to eq('test-asset-tag') |
| 84 | + it "calls get_chassis_asset_tag_linux" do |
| 85 | + expect(mixin).to receive(:get_chassis_asset_tag_linux).and_return("test-asset-tag") |
| 86 | + expect(mixin.chassis_asset_tag).to eq("test-asset-tag") |
87 | 87 | end |
88 | 88 | end |
89 | 89 | end |
90 | 90 |
|
91 | | - describe '#get_chassis_asset_tag_linux' do |
| 91 | + describe "#get_chassis_asset_tag_linux" do |
92 | 92 | let(:chassis_file) { Ohai::Mixin::OCIMetadata::CHASSIS_ASSET_TAG_FILE } |
93 | 93 |
|
94 | | - it 'returns asset tag when file exists and is readable' do |
| 94 | + it "returns asset tag when file exists and is readable" do |
95 | 95 | allow(::File).to receive(:exist?).with(chassis_file).and_return(true) |
96 | 96 | allow(::File).to receive(:read).with(chassis_file).and_return(" OracleCloud.com \n") |
97 | 97 |
|
98 | | - expect(mixin.get_chassis_asset_tag_linux).to eq('OracleCloud.com') |
| 98 | + expect(mixin.get_chassis_asset_tag_linux).to eq("OracleCloud.com") |
99 | 99 | end |
100 | 100 |
|
101 | | - it 'returns nil when file does not exist' do |
| 101 | + it "returns nil when file does not exist" do |
102 | 102 | allow(::File).to receive(:exist?).with(chassis_file).and_return(false) |
103 | 103 |
|
104 | 104 | expect(mixin.get_chassis_asset_tag_linux).to be_nil |
105 | 105 | end |
106 | 106 |
|
107 | | - it 'returns nil when file read fails' do |
| 107 | + it "returns nil when file read fails" do |
108 | 108 | allow(::File).to receive(:exist?).with(chassis_file).and_return(true) |
109 | 109 | allow(::File).to receive(:read).with(chassis_file).and_raise(Errno::EACCES) |
110 | 110 |
|
|
113 | 113 | end |
114 | 114 | end |
115 | 115 |
|
116 | | - describe '#get_chassis_asset_tag_windows' do |
117 | | - let(:wmi_mock) { double('WmiLite::Wmi') } |
118 | | - let(:enclosure_mock) { { 'SMBIOSAssetTag' => 'OracleCloud.com' } } |
| 116 | + describe "#get_chassis_asset_tag_windows" do |
| 117 | + let(:wmi_mock) { double("WmiLite::Wmi") } |
| 118 | + let(:enclosure_mock) { { "SMBIOSAssetTag" => "OracleCloud.com" } } |
119 | 119 |
|
120 | 120 | before do |
121 | 121 | allow(mixin).to receive(:require) |
122 | | - stub_const('WmiLite::Wmi', double(new: wmi_mock)) |
| 122 | + stub_const("WmiLite::Wmi", double(new: wmi_mock)) |
123 | 123 | end |
124 | 124 |
|
125 | | - it 'returns asset tag from WMI when available' do |
126 | | - allow(wmi_mock).to receive(:first_of).with('Win32_SystemEnclosure').and_return(enclosure_mock) |
| 125 | + it "returns asset tag from WMI when available" do |
| 126 | + allow(wmi_mock).to receive(:first_of).with("Win32_SystemEnclosure").and_return(enclosure_mock) |
127 | 127 |
|
128 | | - expect(mixin.get_chassis_asset_tag_windows).to eq('OracleCloud.com') |
| 128 | + expect(mixin.get_chassis_asset_tag_windows).to eq("OracleCloud.com") |
129 | 129 | end |
130 | 130 |
|
131 | | - it 'returns nil when WMI query returns nil' do |
132 | | - allow(wmi_mock).to receive(:first_of).with('Win32_SystemEnclosure').and_return(nil) |
| 131 | + it "returns nil when WMI query returns nil" do |
| 132 | + allow(wmi_mock).to receive(:first_of).with("Win32_SystemEnclosure").and_return(nil) |
133 | 133 |
|
134 | 134 | expect(mixin.get_chassis_asset_tag_windows).to be_nil |
135 | 135 | end |
136 | 136 |
|
137 | | - it 'returns nil when WMI query fails' do |
138 | | - allow(wmi_mock).to receive(:first_of).with('Win32_SystemEnclosure').and_raise(StandardError.new('WMI error')) |
| 137 | + it "returns nil when WMI query fails" do |
| 138 | + allow(wmi_mock).to receive(:first_of).with("Win32_SystemEnclosure").and_raise(StandardError.new("WMI error")) |
139 | 139 |
|
140 | 140 | expect(mixin.logger).to receive(:debug).with(/Failed to read chassis asset tag from WMI/) |
141 | 141 | expect(mixin.get_chassis_asset_tag_windows).to be_nil |
142 | 142 | end |
143 | 143 |
|
144 | | - it 'returns nil when SMBIOSAssetTag is not present' do |
145 | | - allow(wmi_mock).to receive(:first_of).with('Win32_SystemEnclosure').and_return({}) |
| 144 | + it "returns nil when SMBIOSAssetTag is not present" do |
| 145 | + allow(wmi_mock).to receive(:first_of).with("Win32_SystemEnclosure").and_return({}) |
146 | 146 |
|
147 | 147 | expect(mixin.get_chassis_asset_tag_windows).to be_nil |
148 | 148 | end |
|
0 commit comments