diff options
Diffstat (limited to 'spec/integration')
-rw-r--r-- | spec/integration/knife/raw_spec.rb | 58 | ||||
-rw-r--r-- | spec/integration/knife/redirection_spec.rb | 35 | ||||
-rw-r--r-- | spec/integration/knife/serve_spec.rb | 3 |
3 files changed, 62 insertions, 34 deletions
diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb index 9fd7664ddd..99fb7b5787 100644 --- a/spec/integration/knife/raw_spec.rb +++ b/spec/integration/knife/raw_spec.rb @@ -19,11 +19,11 @@ require "support/shared/integration/integration_helper" require "support/shared/context/config" require "chef/knife/raw" require "chef/knife/show" +require "tiny_server" describe "knife raw", :workstation do include IntegrationSupport include KnifeSupport - include AppServerSupport include_context "default config options" @@ -185,19 +185,29 @@ describe "knife raw", :workstation do end context "When a server returns raw json" do - before :each do - Chef::Config.chef_server_url = "http://localhost:9018" - app = lambda do |env| - [200, { "Content-Type" => "application/json" }, ['{ "x": "y", "a": "b" }'] ] + def start_tiny_server(server_opts = {}) + @server = TinyServer::Manager.new(server_opts) + @server.start + @api = TinyServer::API.instance + @api.clear + + @api.get("/blah", 200, nil, { "Content-Type" => "application/json" }) do + '{ "x": "y", "a": "b" }' end - @raw_server_thread = start_app_server(app, 9018) + end + + def stop_tiny_server + @server.stop + @server = @api = nil + end + + before :each do + Chef::Config.chef_server_url = "http://localhost:9000" + start_tiny_server end after :each do - if @raw_server_thread - @raw_server_thread.kill - @raw_server_thread.join(30) - end + stop_tiny_server end it "knife raw /blah returns the prettified json" do @@ -217,19 +227,29 @@ describe "knife raw", :workstation do end context "When a server returns text" do - before :each do - Chef::Config.chef_server_url = "http://localhost:9018" - app = lambda do |env| - [200, { "Content-Type" => "text" }, ['{ "x": "y", "a": "b" }'] ] + def start_tiny_server(server_opts = {}) + @server = TinyServer::Manager.new(server_opts) + @server.start + @api = TinyServer::API.instance + @api.clear + + @api.get("/blah", 200, nil, { "Content-Type" => "text" }) do + '{ "x": "y", "a": "b" }' end - @raw_server_thread = start_app_server(app, 9018) + end + + def stop_tiny_server + @server.stop + @server = @api = nil + end + + before :each do + Chef::Config.chef_server_url = "http://localhost:9000" + start_tiny_server end after :each do - if @raw_server_thread - @raw_server_thread.kill - @raw_server_thread.join(30) - end + stop_tiny_server end it "knife raw /blah returns the raw text" do diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb index 5e5ef27b9a..fe39315fe4 100644 --- a/spec/integration/knife/redirection_spec.rb +++ b/spec/integration/knife/redirection_spec.rb @@ -1,6 +1,6 @@ # # Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright 2013-2018, Chef Software Inc. +# Copyright:: Copyright 2013-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +require "tiny_server" require "support/shared/integration/integration_helper" require "support/shared/context/config" require "chef/knife/list" @@ -22,7 +23,21 @@ require "chef/knife/list" describe "redirection", :workstation do include IntegrationSupport include KnifeSupport - include AppServerSupport + + def start_tiny_server(real_chef_server_url, server_opts = {}) + @server = TinyServer::Manager.new(server_opts) + @server.start + @api = TinyServer::API.instance + @api.clear + + @api.get("/roles", 302, nil, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}/roles" }) do + end + end + + def stop_tiny_server + @server.stop + @server = @api = nil + end include_context "default config options" @@ -30,20 +45,14 @@ describe "redirection", :workstation do before { role "x", {} } context "and another server redirects to it with 302" do - before :each do + before(:each) do real_chef_server_url = Chef::Config.chef_server_url - Chef::Config.chef_server_url = "http://localhost:9018" - app = lambda do |env| - [302, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}#{env["PATH_INFO"]}" }, ["302 found"] ] - end - @redirector_server_thread = start_app_server(app, 9018) + Chef::Config.chef_server_url = "http://localhost:9000" + start_tiny_server(real_chef_server_url) end - after :each do - if @redirector_thread - @redirector_thread.kill - @redirector_thread.join(30) - end + after(:each) do + stop_tiny_server end it "knife list /roles returns the role" do diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb index b0cdd8c070..ab293174d4 100644 --- a/spec/integration/knife/serve_spec.rb +++ b/spec/integration/knife/serve_spec.rb @@ -1,6 +1,6 @@ # # Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright 2013-2016, Chef Software Inc. +# Copyright:: Copyright 2013-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,6 @@ require "chef/server_api" describe "knife serve", :workstation do include IntegrationSupport include KnifeSupport - include AppServerSupport def with_knife_serve exception = nil |