Skip to content

Commit

Permalink
Revert "v2.x: backport required changes"
Browse files Browse the repository at this point in the history
This reverts commit 263ff40 from ManageIQ#271.
Those backport changes are no longer needed:
- after backporting ManageIQ#195 and ManageIQ#233, v2.x now has
  Kubeclient::HttpError and Kubeclient::ResourceNotFoundError.
- after backporting ManageIQ#247, v2.x now tests with webmock 2.x,
  it takes `basic_auth` rather than user:pw in URL.
- ns/namespace change was just cosmetic.

In other words, v2.x branch is now closer to original ManageIQ#262.
  • Loading branch information
cben committed Jan 22, 2018
1 parent e1e39f5 commit 2381575
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
5 changes: 2 additions & 3 deletions lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,8 @@ def define_entity_methods
end

# get a single entity of a specific type by name
define_singleton_method("get_#{entity.method_names[0]}") \
do |name, namespace = nil, opts = {}|
get_entity(klass, entity.resource_name, name, namespace, opts)
define_singleton_method("get_#{entity.method_names[0]}") do |name, ns = nil, opts = {}|
get_entity(klass, entity.resource_name, name, ns, opts)
end

define_singleton_method("delete_#{entity.method_names[0]}") do |name, namespace = nil|
Expand Down
23 changes: 11 additions & 12 deletions test/test_kubeclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_nonjson_exception_raw

client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')

exception = assert_raises(KubeException) do
exception = assert_raises(Kubeclient::ResourceNotFoundError) do
client.get_services(as: :raw)
end

Expand Down Expand Up @@ -251,7 +251,7 @@ def test_entity_list_raw_failure

client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')

exception = assert_raises(KubeException) { client.get_services(as: :raw) }
exception = assert_raises(Kubeclient::HttpError) { client.get_services(as: :raw) }
assert_equal('500 Internal Server Error', exception.message)
assert_equal(500, exception.error_code)
end
Expand Down Expand Up @@ -444,11 +444,11 @@ def test_get_all_raw
result = client.all_entities(as: :raw)
assert_equal(16, result.keys.size)

%w(
%w[
component_status config_map endpoint event limit_range namespace node
persistent_volume persistent_volume_claim pod replication_controller
resource_quota secret service service_account
).each do |entity|
].each do |entity|
assert_equal(open_test_file("#{entity}_list.json").read, result[entity])
end
end
Expand Down Expand Up @@ -523,14 +523,14 @@ def test_api_bearer_token_failure_raw

stub_request(:get, 'http://localhost:8080/api/v1')
.with(headers: { Authorization: 'Bearer invalid_token' })
.to_raise(KubeException.new(403, error_message, response))
.to_raise(Kubeclient::HttpError.new(403, error_message, response))

client = Kubeclient::Client.new(
'http://localhost:8080/api/',
auth_options: { bearer_token: 'invalid_token' }
)

exception = assert_raises(KubeException) { client.get_pods(as: :raw) }
exception = assert_raises(Kubeclient::HttpError) { client.get_pods(as: :raw) }
assert_equal(403, exception.error_code)
assert_equal(error_message, exception.message)
assert_equal(response, exception.response)
Expand Down Expand Up @@ -604,22 +604,21 @@ def test_api_basic_auth_failure_raw
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')
.to_raise(KubeException.new(401, error_message, response))
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(
'http://localhost:8080/api/',
auth_options: { username: 'username', password: 'password' }
)

exception = assert_raises(KubeException) { client.get_pods(as: :raw) }
exception = assert_raises(Kubeclient::HttpError) { client.get_pods(as: :raw) }
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
Expand Down
4 changes: 2 additions & 2 deletions test/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def test_get_from_json_v1_raw_error

client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')

exception = assert_raises(KubeException) do
exception = assert_raises(Kubeclient::HttpError) do
client.get_node('127.0.0.1', nil, as: :raw)
end

assert_instance_of(KubeException, exception)
assert_instance_of(Kubeclient::HttpError, exception)
assert_equal('500 Internal Server Error', exception.message)
end
end

0 comments on commit 2381575

Please sign in to comment.