From 1065d39691382165273e5aaed1be67370e60bb91 Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Tue, 2 May 2017 01:28:40 +0300 Subject: [PATCH] Support ruby 2.4 Bump to Webmock 2.3.1 which fixed .close stubbing for ruby 2.4. Update tests using user:pass@... urls - webmock 2.x treats basic auth as a header, not url part. https://github.com/bblimke/webmock/blob/2.0/CHANGELOG.md#200 --- .travis.yml | 1 + kubeclient.gemspec | 2 +- test/test_kubeclient.rb | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4b428404..b469e2a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ rvm: - "2.1" - "2.2" - "2.3.0" + - "2.4.0" gemfile: - Gemfile - Gemfile-rest-client-1.8.rb diff --git a/kubeclient.gemspec b/kubeclient.gemspec index 6a292cda..3a0dc005 100644 --- a/kubeclient.gemspec +++ b/kubeclient.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'minitest' spec.add_development_dependency 'minitest-rg' - spec.add_development_dependency 'webmock', '~> 1.24.2' + spec.add_development_dependency 'webmock', '~> 2.3.1' spec.add_development_dependency 'vcr' spec.add_development_dependency 'rubocop', '= 0.47.1' spec.add_dependency 'rest-client' diff --git a/test/test_kubeclient.rb b/test/test_kubeclient.rb index a5835fd3..88f87785 100644 --- a/test/test_kubeclient.rb +++ b/test/test_kubeclient.rb @@ -404,9 +404,11 @@ def test_api_bearer_token_failure end def test_api_basic_auth_success - stub_request(:get, 'http://username:password@localhost:8080/api/v1') + stub_request(:get, 'http://localhost:8080/api/v1') + .with(basic_auth: %w(username password)) .to_return(body: open_test_file('core_api_resource_list.json'), status: 200) - stub_request(:get, 'http://username:password@localhost:8080/api/v1/pods') + stub_request(:get, 'http://localhost:8080/api/v1/pods') + .with(basic_auth: %w(username password)) .to_return(body: open_test_file('pod_list.json'), status: 200) client = Kubeclient::Client.new( @@ -420,15 +422,17 @@ def test_api_basic_auth_success assert_equal(1, pods.size) assert_requested( :get, - 'http://username:password@localhost:8080/api/v1/pods', + 'http://localhost:8080/api/v1/pods', times: 1 ) end def test_api_basic_auth_back_comp_success - stub_request(:get, 'http://username:password@localhost:8080/api/v1') + stub_request(:get, 'http://localhost:8080/api/v1') + .with(basic_auth: %w(username password)) .to_return(body: open_test_file('core_api_resource_list.json'), status: 200) - stub_request(:get, 'http://username:password@localhost:8080/api/v1/pods') + stub_request(:get, 'http://localhost:8080/api/v1/pods') + .with(basic_auth: %w(username password)) .to_return(body: open_test_file('pod_list.json'), status: 200) client = Kubeclient::Client.new( @@ -440,14 +444,15 @@ def test_api_basic_auth_back_comp_success assert_equal('Pod', pods.kind) assert_equal(1, pods.size) - assert_requested(:get, 'http://username:password@localhost:8080/api/v1/pods', times: 1) + assert_requested(:get, 'http://localhost:8080/api/v1/pods', times: 1) end def test_api_basic_auth_failure error_message = 'HTTP status code 401, 401 Unauthorized' response = OpenStruct.new(code: 401, message: '401 Unauthorized') - stub_request(:get, 'http://username:password@localhost:8080/api/v1') + stub_request(:get, 'http://localhost:8080/api/v1') + .with(basic_auth: %w(username password)) .to_raise(Kubeclient::HttpError.new(401, error_message, response)) client = Kubeclient::Client.new( @@ -459,7 +464,7 @@ def test_api_basic_auth_failure assert_equal(401, exception.error_code) assert_equal(error_message, exception.message) assert_equal(response, exception.response) - assert_requested(:get, 'http://username:password@localhost:8080/api/v1', times: 1) + assert_requested(:get, 'http://localhost:8080/api/v1', times: 1) end def test_init_username_no_password