summaryrefslogtreecommitdiff
path: root/spec/integration/knife
diff options
context:
space:
mode:
authorGrégoire Seux <g.seux@criteo.com>2017-03-01 15:01:11 +0100
committerGrégoire Seux <g.seux@criteo.com>2017-03-06 12:00:35 +0100
commit9e6bf57b2bc2a2d3422f7798090a6f38c7e6c7b8 (patch)
tree870c76672114509cad43ca2aef598eb1482091d4 /spec/integration/knife
parent46d19a502fb8824fa3fccf4535fcfa226c4e9473 (diff)
downloadchef-9e6bf57b2bc2a2d3422f7798090a6f38c7e6c7b8.tar.gz
Extract with_knife_serve helper in knife serve tests
Change-Id: I0ddb921a30daf33007b37483b163fc76117441c7 Signed-off-by: Grégoire Seux <g.seux@criteo.com>
Diffstat (limited to 'spec/integration/knife')
-rw-r--r--spec/integration/knife/serve_spec.rb51
1 files changed, 29 insertions, 22 deletions
diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb
index 72f0bb59ed..7d379e1e71 100644
--- a/spec/integration/knife/serve_spec.rb
+++ b/spec/integration/knife/serve_spec.rb
@@ -24,33 +24,40 @@ 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" } }
it "knife serve serves up /nodes/x" do
- 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
+ with_knife_serve do |api|
expect(api.get("nodes/x")["name"]).to eq("x")
- rescue
- if exception
- raise exception
- else
- raise
- end
- ensure
- t.kill
end
end
end