summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/knife/download_spec.rb9
-rw-r--r--spec/unit/http_spec.rb2
-rw-r--r--spec/unit/lwrp_spec.rb2
-rw-r--r--spec/unit/mixin/properties_spec.rb97
-rw-r--r--spec/unit/provider/user_spec.rb9
-rw-r--r--spec/unit/resource_reporter_spec.rb7
-rw-r--r--spec/unit/run_list/run_list_expansion_spec.rb21
7 files changed, 142 insertions, 5 deletions
diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb
index 8842ed5ac4..b8a19061b7 100644
--- a/spec/integration/knife/download_spec.rb
+++ b/spec/integration/knife/download_spec.rb
@@ -1103,6 +1103,15 @@ EOM
before :each do
Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo')
end
+ when_the_repository 'has existing top level files' do
+ before do
+ file 'invitations.json', {}
+ end
+
+ it "can still download top level files" do
+ knife('download /invitations.json').should_succeed
+ end
+ end
when_the_repository 'is empty' do
it 'knife download / downloads everything' do
diff --git a/spec/unit/http_spec.rb b/spec/unit/http_spec.rb
index 4d851df951..a654d14aa2 100644
--- a/spec/unit/http_spec.rb
+++ b/spec/unit/http_spec.rb
@@ -89,4 +89,4 @@ describe Chef::HTTP do
end # head
-end
+end \ No newline at end of file
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index bcb64cb21e..7f6d315bbb 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -190,7 +190,7 @@ describe "LWRP" do
end
it "should have a class that outputs a reasonable string" do
- expect(get_lwrp(:lwrp_foo).to_s).to eq "LWRP resource lwrp_foo from cookbook lwrp"
+ expect(get_lwrp(:lwrp_foo).to_s).to eq "Custom resource lwrp_foo from cookbook lwrp"
end
it "should add the specified actions to the allowed_actions array" do
diff --git a/spec/unit/mixin/properties_spec.rb b/spec/unit/mixin/properties_spec.rb
new file mode 100644
index 0000000000..18178619e4
--- /dev/null
+++ b/spec/unit/mixin/properties_spec.rb
@@ -0,0 +1,97 @@
+require 'support/shared/integration/integration_helper'
+require 'chef/mixin/properties'
+
+module ChefMixinPropertiesSpec
+ describe "Chef::Resource.property" do
+ include IntegrationSupport
+
+ context "with a base class A with properties a, ab, and ac" do
+ class A
+ include Chef::Mixin::Properties
+ property :a, 'a', default: 'a'
+ property :ab, ['a', 'b'], default: 'a'
+ property :ac, ['a', 'c'], default: 'a'
+ end
+
+ context "and a module B with properties b, ab and bc" do
+ module B
+ include Chef::Mixin::Properties
+ property :b, 'b', default: 'b'
+ property :ab, default: 'b'
+ property :bc, ['b', 'c'], default: 'c'
+ end
+
+ context "and a derived class C < A with properties c, ac and bc" do
+ class C < A
+ include B
+ property :c, 'c', default: 'c'
+ property :ac, default: 'c'
+ property :bc, default: 'c'
+ end
+
+ it "A.properties has a, ab, and ac with types 'a', ['a', 'b'], and ['b', 'c']" do
+ expect(A.properties.keys).to eq [ :a, :ab, :ac ]
+ expect(A.properties[:a].validation_options[:is]).to eq 'a'
+ expect(A.properties[:ab].validation_options[:is]).to eq [ 'a', 'b' ]
+ expect(A.properties[:ac].validation_options[:is]).to eq [ 'a', 'c' ]
+ end
+ it "B.properties has b, ab, and bc with types 'b', nil and ['b', 'c']" do
+ expect(B.properties.keys).to eq [ :b, :ab, :bc ]
+ expect(B.properties[:b].validation_options[:is]).to eq 'b'
+ expect(B.properties[:ab].validation_options[:is]).to be_nil
+ expect(B.properties[:bc].validation_options[:is]).to eq [ 'b', 'c' ]
+ end
+ it "C.properties has a, b, c, ac and bc with merged types" do
+ expect(C.properties.keys).to eq [ :a, :ab, :ac, :b, :bc, :c ]
+ expect(C.properties[:a].validation_options[:is]).to eq 'a'
+ expect(C.properties[:b].validation_options[:is]).to eq 'b'
+ expect(C.properties[:c].validation_options[:is]).to eq 'c'
+ expect(C.properties[:ac].validation_options[:is]).to eq [ 'a', 'c' ]
+ expect(C.properties[:bc].validation_options[:is]).to eq [ 'b', 'c' ]
+ end
+ it "C.properties has ab with a non-merged type (from B)" do
+ expect(C.properties[:ab].validation_options[:is]).to be_nil
+ end
+
+ context "and an instance of C" do
+ let(:c) { C.new }
+
+ it "all properties can be retrieved and merged properties default to ab->b, ac->c, bc->c" do
+ expect(c.a).to eq('a')
+ expect(c.b).to eq('b')
+ expect(c.c).to eq('c')
+ expect(c.ab).to eq('b')
+ expect(c.ac).to eq('c')
+ expect(c.bc).to eq('c')
+ end
+ end
+ end
+ end
+ end
+ end
+
+ context "with an Inner module" do
+ module Inner
+ include Chef::Mixin::Properties
+ property :inner
+ end
+
+ context "and an Outer module including it" do
+ module Outer
+ include Inner
+ property :outer
+ end
+
+ context "and an Outerest class including that" do
+ class Outerest
+ include Outer
+ property :outerest
+ end
+
+ it "Outerest.properties.validation_options[:is] inner, outer, outerest" do
+ expect(Outerest.properties.keys).to eq [:inner, :outer, :outerest]
+ end
+ end
+ end
+ end
+end
diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb
index 2345ce18fb..bd24a6a01e 100644
--- a/spec/unit/provider/user_spec.rb
+++ b/spec/unit/provider/user_spec.rb
@@ -452,11 +452,20 @@ describe Chef::Provider::User do
it "should raise an error if we can't translate the group name during resource assertions" do
expect(Etc).to receive(:getgrnam).and_raise(ArgumentError)
+ @provider.action = :create
@provider.define_resource_requirements
@provider.convert_group_name
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::User)
end
+ it "does not raise an error if we can't translate the group name during resource assertions if we are removing the user" do
+ expect(Etc).to receive(:getgrnam).and_raise(ArgumentError)
+ @provider.action = :remove
+ @provider.define_resource_requirements
+ @provider.convert_group_name
+ expect { @provider.process_resource_requirements }.not_to raise_error
+ end
+
it "should set the new resources gid to the integerized version if available" do
expect(Etc).to receive(:getgrnam).with("999").and_return(@group)
@provider.convert_group_name
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb
index 4f3a085584..f2c0b8fd8b 100644
--- a/spec/unit/resource_reporter_spec.rb
+++ b/spec/unit/resource_reporter_spec.rb
@@ -50,6 +50,9 @@ describe Chef::ResourceReporter do
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
@run_status = Chef::RunStatus.new(@node, @events)
+ @run_list = Chef::RunList.new
+ @run_list << 'recipe[lobster]' << 'role[rage]' << 'recipe[fist]'
+ @expansion = Chef::RunList::RunListExpansion.new("_default", @run_list.run_list_items)
@run_id = @run_status.run_id
allow(Time).to receive(:now).and_return(@start_time, @end_time)
end
@@ -424,6 +427,10 @@ describe Chef::ResourceReporter do
expect(@report["run_list"]).to eq(Chef::JSONCompat.to_json(@run_status.node.run_list))
end
+ it "includes the expanded_run_list" do
+ expect(@report).to have_key("expanded_run_list")
+ end
+
it "includes the end_time" do
expect(@report).to have_key("end_time")
expect(@report["end_time"]).to eq(@run_status.end_time.to_s)
diff --git a/spec/unit/run_list/run_list_expansion_spec.rb b/spec/unit/run_list/run_list_expansion_spec.rb
index 859219d346..a7df9e749b 100644
--- a/spec/unit/run_list/run_list_expansion_spec.rb
+++ b/spec/unit/run_list/run_list_expansion_spec.rb
@@ -21,7 +21,7 @@ require 'spec_helper'
describe Chef::RunList::RunListExpansion do
before do
@run_list = Chef::RunList.new
- @run_list << 'recipe[lobster]' << 'role[rage]' << 'recipe[fist]'
+ @run_list << 'recipe[lobster::mastercookbook@0.1.0]' << 'role[rage]' << 'recipe[fist@0.1]'
@expansion = Chef::RunList::RunListExpansion.new("_default", @run_list.run_list_items)
end
@@ -59,7 +59,7 @@ describe Chef::RunList::RunListExpansion do
end
it "has the correct list of recipes for the given environment" do
- expect(@expansion.recipes).to eq(["lobster", "prod-only", "fist"])
+ expect(@expansion.recipes).to eq(["lobster::mastercookbook", "prod-only", "fist"])
end
end
@@ -82,19 +82,34 @@ describe Chef::RunList::RunListExpansion do
describe "after expanding a run list" do
before do
@first_role = Chef::Role.new
+ @first_role.name('rage')
@first_role.run_list('role[mollusk]')
@first_role.default_attributes({'foo' => 'bar'})
@first_role.override_attributes({'baz' => 'qux'})
@second_role = Chef::Role.new
+ @second_role.name('rage')
@second_role.run_list('recipe[crabrevenge]')
@second_role.default_attributes({'foo' => 'boo'})
@second_role.override_attributes({'baz' => 'bux'})
allow(@expansion).to receive(:fetch_role).and_return(@first_role, @second_role)
@expansion.expand
+ @json = '{"id":"_default","run_list":[{"type":"recipe","name":"lobster::mastercookbook","version":"0.1.0",'
+ .concat(
+'"skipped":false},{"type":"role","name":"rage","children":[{"type":"role","name":"mollusk","children":[],"missing":null,'
+ .concat(
+'"error":null,"skipped":null},{"type":"recipe","name":"crabrevenge","version":null,"skipped":false}],"missing":null,'
+ .concat(
+'"error":null,"skipped":null},{"type":"recipe","name":"fist","version":"0.1","skipped":false}]}')))
+
+ end
+
+ it "produces json tree upon tracing expansion" do
+ jsonRunList = @expansion.to_json
+ expect(jsonRunList).to eq(@json)
end
it "has the ordered list of recipes" do
- expect(@expansion.recipes).to eq(['lobster', 'crabrevenge', 'fist'])
+ expect(@expansion.recipes).to eq(['lobster::mastercookbook', 'crabrevenge', 'fist'])
end
it "has the merged attributes from the roles with outer roles overriding inner" do