summaryrefslogtreecommitdiff
path: root/spec/unit/plugins/darwin/system_profiler_spec.rb
blob: 98b6c84519eba16f2f3c16ace1e93cc0de803478 (plain)
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
#
# Author:: Paul Mooring (<paul@chef.io>)
# Copyright:: Copyright (c) 2012-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 File.expand_path("#{File.dirname(__FILE__)}/system_profiler_output.rb")

begin
  require "plist"
rescue LoadError => e
  puts "The darwin systemprofile plugin spec tests will fail without the 'plist' library/gem.\n\n"
  raise e
end

describe Ohai::System, "Darwin system_profiler plugin", :unix_only do
  before(:each) do
    @plugin = get_plugin("darwin/system_profiler")
    allow(@plugin).to receive(:collect_os).and_return(:darwin)
  end

  it "should return the right serial number" do
    mini_cmd = "system_profiler -xml -detailLevel mini SPParallelATAData SPAudioData SPBluetoothData"
    mini_cmd += " SPCardReaderData SPDiagnosticsData SPDiscBurningData SPEthernetData SPFibreChannelData"
    mini_cmd += " SPFireWireData SPDisplaysData SPHardwareRAIDData SPMemoryData SPModemData SPNetworkData"
    mini_cmd += " SPPCIData SPParallelSCSIData SPPrintersSoftwareData SPPrintersData SPSASData SPSerialATAData"
    mini_cmd += " SPSoftwareData SPThunderboltData SPUSBData SPWWANData SPAirPortData"
    full_cmd = "system_profiler -xml -detailLevel full SPHardwareDataType"
    allow(@plugin).to receive(:shell_out).with(full_cmd).and_return(mock_shell_out(0, SystemProfilerOutput::Full, ""))
    allow(@plugin).to receive(:shell_out).with(mini_cmd).and_return(mock_shell_out(0, SystemProfilerOutput::Mini, ""))
    @plugin.run
    expect(@plugin["system_profile"][18]["_items"][0]["serial_number"]).to eq("ABCDEFG12345")
  end
end