summaryrefslogtreecommitdiff
path: root/platform_simulation_specs/common/ohai_plugin_common_spec.rb
blob: bb407bd44072a49607a888062db97023ea698395 (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
48
49
50
51
52

# Author:: Theodore Nordsieck <theo@chef.io>
# Copyright:: Copyright (c) 2013-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_relative "ohai_plugin_common.rb"

describe OhaiPluginCommon, "subsumes?" do
  before(:each) do
    @hash = { "languages" => { "python" => { "version" => "1.6.2", "type" => "interpreted" } } }
  end

  it "returns true if given an exact duplicate" do
    subsumes?( @hash, @hash ).should be_true
  end

  it "returns false if given an exact duplicate with extra info" do
    subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => "darwin", "type" => "interpreted" } } } ).should be_false
    subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => {}, "type" => "interpreted" } } } ).should be_false
    subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => { "name" => "darwin" }, "type" => "interpreted" } } } ).should be_false
  end

  it "returns true if all elements in the second hash are in the first hash" do
    subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2" } } } ).should be_true
    subsumes?( @hash, { "languages" => { "python" => {} } } ).should be_true
    subsumes?( @hash, { "languages" => {} } ).should be_true
  end

  it "returns true if the second hash contains a key pointing to a nil where the first hash has nothing" do
    subsumes?( @hash, { "languages" => { "lua" => nil } } ).should be_true
    subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2" }, "lua" => nil } } ).should be_true
  end

  it "returns false if the second hash has nil in the place of a real value" do
    subsumes?( @hash, { "languages" => { "python" => { "version" => nil } } } ).should be_false
    subsumes?( @hash, { "languages" => { "python" => nil } } ).should be_false
    subsumes?( { "languages" => {} }, { "languages" => nil } ).should be_false
  end
end