Skip to content

Commit

Permalink
v2.x: backport required changes
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Simoncelli <[email protected]>
  • Loading branch information
simon3z committed Oct 11, 2017
1 parent 88d2b00 commit 263ff40
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
5 changes: 3 additions & 2 deletions lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ 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, ns = nil, opts = {}|
get_entity(klass, entity.resource_name, name, ns, opts)
define_singleton_method("get_#{entity.method_names[0]}") \
do |name, namespace = nil, opts = {}|
get_entity(klass, entity.resource_name, name, namespace, opts)
end

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

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

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

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

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

exception = assert_raises(Kubeclient::HttpError) { client.get_services(as: :raw) }
exception = assert_raises(KubeException) { client.get_services(as: :raw) }
assert_equal('500 Internal Server Error', exception.message)
assert_equal(500, exception.error_code)
end
Expand Down Expand Up @@ -457,11 +457,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 @@ -535,14 +535,14 @@ def test_api_bearer_token_failure_raw

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

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

exception = assert_raises(Kubeclient::HttpError) { client.get_pods(as: :raw) }
exception = assert_raises(KubeException) { 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 @@ -620,21 +620,22 @@ 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://localhost:8080/api/v1')
.with(basic_auth: %w[username password])
.to_raise(Kubeclient::HttpError.new(401, error_message, response))
stub_request(:get, 'http://username:password@localhost:8080/api/v1')
.to_raise(KubeException.new(401, error_message, response))

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

exception = assert_raises(Kubeclient::HttpError) { client.get_pods(as: :raw) }
exception = assert_raises(KubeException) { 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://localhost:8080/api/v1', times: 1)
assert_requested(:get,
'http://username:password@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 @@ -60,11 +60,11 @@ def test_get_from_json_v1_raw_error

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

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

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

0 comments on commit 263ff40

Please sign in to comment.