summaryrefslogtreecommitdiff
path: root/chef/spec/unit/client_spec.rb
diff options
context:
space:
mode:
authorAdam Jacob <adam@opscode.com>2009-08-01 21:26:21 -0700
committerAdam Jacob <adam@opscode.com>2009-08-20 13:31:58 -0700
commit89779a4d487ac7dd313e16eb68732835bd13d4e4 (patch)
treed8b867f3a5610ed39bd864149152085af05a1c3d /chef/spec/unit/client_spec.rb
parent89a2609242a63d6bc85e0ddfed078319b4d4a81b (diff)
downloadchef-89779a4d487ac7dd313e16eb68732835bd13d4e4.tar.gz
Initial pass at a Chef 0.8.0 alpha
Conflicts: Rakefile chef-server-slice/Rakefile chef-server-slice/app/controllers/application.rb chef-server-slice/app/controllers/exceptions.rb chef-server-slice/app/controllers/nodes.rb chef-server-slice/app/controllers/openid_consumer.rb chef-server-slice/app/controllers/openid_server.rb chef-server-slice/app/helpers/nodes_helper.rb chef-server/Rakefile chef-server/config/dependencies.rb chef-server/config/init.rb chef/Rakefile chef/lib/chef.rb chef/lib/chef/application/indexer.rb chef/lib/chef/client.rb chef/lib/chef/config.rb chef/lib/chef/node.rb chef/lib/chef/queue.rb chef/spec/unit/application/indexer_spec.rb chef/spec/unit/client_spec.rb chef/spec/unit/config_spec.rb cucumber.yml features/api/nodes/create_node_api.feature features/api/nodes/delete_node_api.feature features/api/nodes/list_nodes_api.feature features/api/nodes/show_node_api.feature features/api/nodes/update_node_api.feature features/api/roles/list_roles_api.feature features/steps/fixture_steps.rb
Diffstat (limited to 'chef/spec/unit/client_spec.rb')
-rw-r--r--chef/spec/unit/client_spec.rb82
1 files changed, 27 insertions, 55 deletions
diff --git a/chef/spec/unit/client_spec.rb b/chef/spec/unit/client_spec.rb
index 303306a659..eb53803cf9 100644
--- a/chef/spec/unit/client_spec.rb
+++ b/chef/spec/unit/client_spec.rb
@@ -30,13 +30,9 @@ describe Chef::Client, "run" do
to_stub = [
:build_node,
:register,
- :authenticate,
- :sync_library_files,
- :sync_attribute_files,
- :sync_definitions,
- :sync_recipes,
+ :sync_cookbooks,
:save_node,
- :save_node
+ :converge
]
to_stub.each do |method|
@client.stub!(method).and_return(true)
@@ -58,37 +54,17 @@ describe Chef::Client, "run" do
@client.run
end
- it "should register for an openid" do
+ it "should register for a client" do
@client.should_receive(:register).and_return(true)
@client.run
end
- it "should authenticate with the server" do
- @client.should_receive(:authenticate).and_return(true)
+ it "should synchronize the cookbooks from the server" do
+ @client.should_receive(:sync_cookbooks).and_return(true)
@client.run
end
- it "should synchronize definitions from the server" do
- @client.should_receive(:sync_definitions).and_return(true)
- @client.run
- end
-
- it "should synchronize recipes from the server" do
- @client.should_receive(:sync_recipes).and_return(true)
- @client.run
- end
-
- it "should synchronize and load library files from the server" do
- @client.should_receive(:sync_library_files).and_return(true)
- @client.run
- end
-
- it "should synchronize and load attribute files from the server" do
- @client.should_receive(:sync_attribute_files).and_return(true)
- @client.run
- end
-
- it "should save the nodes state on the server (twice!)" do
+ it "should save the nodes state on the server (thrice!)" do
@client.should_receive(:save_node).exactly(3).times.and_return(true)
@client.run
end
@@ -98,11 +74,6 @@ describe Chef::Client, "run" do
@client.run
end
- it "should set the cookbook_path" do
- Chef::Config.should_receive('[]').with(:file_cache_path).
- and_return('/var/chef/cache/cookbooks')
- @client.run
- end
end
describe Chef::Client, "run_solo" do
@@ -149,6 +120,7 @@ describe Chef::Client, "build_node" do
Chef::REST.stub!(:new).and_return(@mock_rest)
@client = Chef::Client.new
Chef::Platform.stub!(:find_platform_and_version).and_return(["FooOS", "1.3.3.7"])
+ Chef::Config[:node_name] = nil
end
it "should set the name equal to the FQDN" do
@@ -208,35 +180,34 @@ describe Chef::Client, "register" do
before do
@mock_rest = mock("Chef::REST", :null_object => true)
@mock_rest.stub!(:get_rest).and_return(true)
+ @mock_rest.stub!(:register).and_return(true)
Chef::REST.stub!(:new).and_return(@mock_rest)
@chef_client = Chef::Client.new
@chef_client.safe_name = "testnode"
+ @chef_client.node_name = "testnode"
@chef_client.stub!(:determine_node_name).and_return(true)
- @chef_client.stub!(:create_registration).and_return(true)
- Chef::Application.stub!(:fatal!).and_return(true)
- Chef::FileCache.stub!(:create_cache_path).and_return("/tmp")
- Chef::FileCache.stub!(:load).and_return("/tmp/testnode")
- end
-
- it "should log an appropriate debug message regarding registering an openid" do
- Chef::Log.should_receive(:debug).with("Registering testnode for an openid").and_return(true)
- @chef_client.register
+ File.stub!(:exists?).and_return(false)
end
+
+ describe "when the validation key is present" do
+ before(:each) do
+ File.stub!(:exists?).with(Chef::Config[:validation_key]).and_return(true)
+ end
- it "should fetch the registration based on safe_name from the chef server" do
- @mock_rest.should_receive(:get_rest).with("registrations/testnode").and_return(true)
- @chef_client.register
- end
+ it "should sign requests with the validation key" do
+ Chef::REST.should_receive(:new).with(Chef::Config[:client_url], Chef::Config[:validation_client_name], Chef::Config[:validation_key]).and_return(@mock_rest)
+ @chef_client.register
+ end
- it "should load the secret from disk" do
- Chef::FileCache.should_receive(:load).with(File.join("registration", "testnode")).and_return("/tmp/testnode")
- @chef_client.register
+ it "should register for a new key-pair" do
+ @mock_rest.should_receive(:register).with("testnode", Chef::Config[:client_key])
+ @chef_client.register
+ end
end
- it "should cause chef to die fatally if the filecache cannot find the registration" do
- Chef::FileCache.stub!(:load).with(File.join("registration", "testnode")).and_raise(Chef::Exceptions::FileNotFound)
- Chef::Application.should_receive(:fatal!).with(/^.*$/, 3).and_return(true)
- @chef_client.register
+ it "should setup the rest client to use the client key-pair" do
+ Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url]).and_return(@mock_rest)
+ @chef_client.register
end
end
@@ -256,3 +227,4 @@ describe Chef::Client, "run_ohai" do
@chef_client.run_ohai
end
end
+