summaryrefslogtreecommitdiff
path: root/spec/integration
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-04-04 18:41:06 +0100
committerGitHub <noreply@github.com>2017-04-04 18:41:06 +0100
commit4b8cd07d8049701acdf5344ca159f9e43561a356 (patch)
tree7e910fa98e18d7217b1f7623ee176c807cc22e21 /spec/integration
parentba719eb02ebab4feb3201f7b1225e5059076cadb (diff)
parentd51d31cf0c514d353cc6883a4af77c11fe802ee9 (diff)
downloadchef-4b8cd07d8049701acdf5344ca159f9e43561a356.tar.gz
Merge pull request #5850 from criteo-forks/rb_support
Add real support for rb files (at least roles) in knife-serve
Diffstat (limited to 'spec/integration')
-rw-r--r--spec/integration/knife/serve_spec.rb80
1 files changed, 58 insertions, 22 deletions
diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb
index 72f0bb59ed..b0cdd8c070 100644
--- a/spec/integration/knife/serve_spec.rb
+++ b/spec/integration/knife/serve_spec.rb
@@ -24,33 +24,69 @@ describe "knife serve", :workstation do
include KnifeSupport
include AppServerSupport
+ def with_knife_serve
+ exception = nil
+ t = Thread.new do
+ begin
+ knife("serve --chef-zero-port=8890")
+ rescue
+ exception = $!
+ end
+ end
+ begin
+ Chef::Config.log_level = :debug
+ Chef::Config.chef_server_url = "http://localhost:8890"
+ Chef::Config.node_name = nil
+ Chef::Config.client_key = nil
+ api = Chef::ServerAPI.new
+ yield api
+ rescue
+ if exception
+ raise exception
+ else
+ raise
+ end
+ ensure
+ t.kill
+ sleep 0.5
+ end
+ end
+
when_the_repository "also has one of each thing" do
- before { file "nodes/x.json", { "foo" => "bar" } }
+ before do
+ file "nodes/a_node_in_json.json", { "foo" => "bar" }
+ file "nodes/a_node_in_ruby.rb", "name 'a_node_in_ruby'"
+ file "roles/a_role_in_json.json", { "foo" => "bar" }
+ file "roles/a_role_in_ruby.rb", "name 'a_role_in_ruby'"
+ end
- it "knife serve serves up /nodes/x" do
- exception = nil
- t = Thread.new do
- begin
- knife("serve --chef-zero-port=8890")
- rescue
- exception = $!
+ %w{a_node_in_json a_node_in_ruby}.each do |file_type|
+ context file_type do
+ it "knife serve serves up /nodes" do
+ with_knife_serve do |api|
+ expect(api.get("nodes")).to have_key(file_type)
+ end
+ end
+ it "knife serve serves up /nodes/#{file_type}" do
+ with_knife_serve do |api|
+ expect(api.get("nodes/#{file_type}")["name"]).to eq(file_type)
+ end
end
end
- begin
- Chef::Config.log_level = :debug
- Chef::Config.chef_server_url = "http://localhost:8890"
- Chef::Config.node_name = nil
- Chef::Config.client_key = nil
- api = Chef::ServerAPI.new
- expect(api.get("nodes/x")["name"]).to eq("x")
- rescue
- if exception
- raise exception
- else
- raise
+ end
+
+ %w{a_role_in_json a_role_in_ruby}.each do |file_type|
+ context file_type do
+ it "knife serve serves up /roles" do
+ with_knife_serve do |api|
+ expect(api.get("roles")).to have_key(file_type)
+ end
+ end
+ it "knife serve serves up /roles/#{file_type}" do
+ with_knife_serve do |api|
+ expect(api.get("roles/#{file_type}")["name"]).to eq(file_type)
+ end
end
- ensure
- t.kill
end
end
end