-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process JSON Body of ListObjects using streaming json parser #254
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,7 +209,57 @@ def test_nonjson_exception_raw | |
assert_equal(404, exception.error_code) | ||
end | ||
|
||
def test_entity_list | ||
def test_entity_list_with_block | ||
stub_request(:get, %r{/api/v1$}) | ||
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200) | ||
stub_request(:get, %r{/services}) | ||
.to_return(body: open_test_file('entity_list.json'), status: 200) | ||
|
||
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') | ||
services = [] | ||
metadata_object = client.get_services do |service| | ||
services << service | ||
end | ||
|
||
assert_equal(metadata_object, resourceVersion: 59, kind: 'ServiceList') | ||
refute_empty(services) | ||
assert_equal(2, services.size) | ||
assert_instance_of(Kubeclient::Service, services[0]) | ||
assert_instance_of(Kubeclient::Service, services[1]) | ||
|
||
assert_requested(:get, 'http://localhost:8080/api/v1/services', times: 1) | ||
end | ||
|
||
def test_entity_list_with_block_404 | ||
stub_request(:get, %r{/api/v1$}) | ||
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200) | ||
stub_request(:get, %r{/services}) | ||
.to_return(status: 404) | ||
|
||
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') | ||
|
||
exception = assert_raises(Kubeclient::ResourceNotFoundError) do | ||
client.get_services {} | ||
end | ||
assert(exception.message.include?('Not Found')) | ||
assert_equal(404, exception.error_code) | ||
end | ||
|
||
def test_entity_list_with_block_http_err | ||
stub_request(:get, %r{/api/v1$}) | ||
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200) | ||
stub_request(:get, %r{/services}) | ||
.to_return(body: '{"err": "I\'m a teapot!"}', status: 418) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 🍵 👍 |
||
|
||
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') | ||
|
||
exception = assert_raises(Kubeclient::HttpError) do | ||
client.get_services {} | ||
end | ||
assert_equal(418, exception.error_code) | ||
end | ||
|
||
def test_entity_list_without_block | ||
stub_request(:get, %r{/api/v1$}) | ||
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200) | ||
stub_request(:get, %r{/services}) | ||
|
@@ -573,10 +623,13 @@ def test_api_basic_auth_back_comp_success | |
auth_options: { user: 'username', password: 'password' } | ||
) | ||
|
||
pods = client.get_pods | ||
pods = [] | ||
client.get_pods do |pod| | ||
pods << pod | ||
end | ||
|
||
assert_equal('Pod', pods.kind) | ||
assert_equal(1, pods.size) | ||
assert_equal('Kubeclient::Pod', pods[0].class.to_s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a kubernetes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh so this is for the old code |
||
assert_requested(:get, 'http://localhost:8080/api/v1/pods', times: 1) | ||
end | ||
|
||
|
@@ -704,10 +757,14 @@ def test_api_bearer_token_file_success | |
auth_options: { bearer_token_file: file } | ||
) | ||
|
||
pods = client.get_pods | ||
pods = [] | ||
metadata_object = client.get_pods do |pod| | ||
pods << pod | ||
end | ||
|
||
assert_equal('Pod', pods.kind) | ||
assert_equal(metadata_object, resourceVersion: 1315, kind: 'PodList') | ||
assert_equal(1, pods.size) | ||
assert_equal('Kubeclient::Pod', pods[0].class.to_s) | ||
end | ||
|
||
def test_proxy_url | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: To avoid confusion let's call it
block_response
everywhere.Because
Request.execute
supports both regular ruby block and a:block_response
param, with different semantics (regular block gets RestClient::Response after redirect/error processing/decoding).https://github.com/rest-client/rest-client/blob/v2.0.2/lib/restclient/request.rb#L718-L726