diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-02-14 11:52:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-14 11:52:09 -0800 |
commit | 3fff8bb4f3f6759684c4a87f034008ec146a2658 (patch) | |
tree | b57559c7d97303cc99abafb20c2e12bbb64b6815 /spec/unit | |
parent | 8a2b56d0de4f2447ddb989f36ee0946434a5933f (diff) | |
parent | e03661ba4bca1906de7f50aff262e60a6dcaa90a (diff) | |
download | chef-3fff8bb4f3f6759684c4a87f034008ec146a2658.tar.gz |
Merge pull request #6848 from chef/lcg/add-nodemap-delete-class-13
add Chef::NodeMap#delete_class API (Chef 13 backport)
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/node_map_spec.rb | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/spec/unit/node_map_spec.rb b/spec/unit/node_map_spec.rb index 7fa115b532..20667df475 100644 --- a/spec/unit/node_map_spec.rb +++ b/spec/unit/node_map_spec.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2014-2017, Chef Software Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,9 @@ require "spec_helper" require "chef/node_map" +class Foo; end +class Bar; end + describe Chef::NodeMap do let(:node_map) { Chef::NodeMap.new } @@ -120,9 +123,7 @@ describe Chef::NodeMap do end describe "ordering classes" do - class Foo; end - class Bar; end - it "orders them alphabetically when they're set in the reverse order" do + it "last writer wins when its reverse alphabetic order" do node_map.set(:thing, Foo) node_map.set(:thing, Bar) expect(node_map.get(node, :thing)).to eql(Bar) @@ -135,6 +136,30 @@ describe Chef::NodeMap do end end + describe "deleting classes" do + it "deletes a class and removes the mapping completely" do + node_map.set(:thing, Bar) + expect( node_map.delete_class(Bar) ).to eql({ :thing => [{ :klass => Bar }] }) + expect( node_map.get(node, :thing) ).to eql(nil) + end + + it "deletes a class and leaves the mapping that still has an entry" do + node_map.set(:thing, Bar) + node_map.set(:thing, Foo) + expect( node_map.delete_class(Bar) ).to eql({ :thing => [{ :klass => Bar }] }) + expect( node_map.get(node, :thing) ).to eql(Foo) + end + + it "handles deleting classes from multiple keys" do + node_map.set(:thing1, Bar) + node_map.set(:thing2, Bar) + node_map.set(:thing2, Foo) + expect( node_map.delete_class(Bar) ).to eql({ :thing1 => [{ :klass => Bar }], :thing2 => [{ :klass => Bar }] }) + expect( node_map.get(node, :thing1) ).to eql(nil) + expect( node_map.get(node, :thing2) ).to eql(Foo) + end + end + describe "with a block doing platform_version checks" do before do node_map.set(:thing, :foo, platform_family: "rhel") do |node| |