From 8b15c2428b1352775b1cc604eff6284119f4d062 Mon Sep 17 00:00:00 2001 From: Vishrut Shah Date: Wed, 29 Jun 2016 21:48:42 -0700 Subject: [PATCH] Increase ruby test coverage bar (#1188) Ruby test coverage bar increased Ruby 90% & Azure.Ruby to 95% --- .../RspecTests/azure_report_spec.rb | 2 +- .../azure_special_properties_spec.rb | 32 +- .../Azure.Ruby.Tests/RspecTests/lro_spec.rb | 375 ++++++++++++++---- .../RspecTests/parameter_grouping_spec.rb | 0 .../Ruby/Ruby.Tests/RspecTests/array_spec.rb | 25 ++ .../Ruby.Tests/RspecTests/complex_spec.rb | 32 ++ .../RspecTests/custom_base_uri_more_spec.rb | 0 .../RspecTests/custom_base_uri_spec.rb | 0 .../Ruby.Tests/RspecTests/duration_spec.rb | 37 ++ .../Ruby/Ruby.Tests/RspecTests/header_spec.rb | 58 +-- .../Ruby/Ruby.Tests/RspecTests/query_spec.rb | 32 ++ .../Ruby/Ruby.Tests/RspecTests/report_spec.rb | 2 +- .../Ruby/Ruby.Tests/RspecTests/string_spec.rb | 9 + .../Ruby.Tests/RspecTests/validation_spec.rb | 30 ++ .../Ruby/Ruby/ClientModelExtensions.cs | 8 +- .../ms_rest_azure/async_operation_status.rb | 3 +- .../lib/ms_rest_azure/azure_service_client.rb | 10 +- .../lib/ms_rest_azure/polling_state.rb | 21 +- .../spec/azure_service_client_spec.rb | 3 + .../Ruby/ms-rest-azure/spec/resource_spec.rb | 2 - .../lib/ms_rest/http_operation_request.rb | 6 +- .../Ruby/ms-rest/lib/ms_rest/serialization.rb | 20 +- gulpfile.js | 7 +- 23 files changed, 576 insertions(+), 138 deletions(-) rename AutoRest/Generators/Ruby/{Ruby.Tests => Azure.Ruby.Tests}/RspecTests/parameter_grouping_spec.rb (100%) rename AutoRest/Generators/Ruby/{Azure.Ruby.Tests => Ruby.Tests}/RspecTests/custom_base_uri_more_spec.rb (100%) rename AutoRest/Generators/Ruby/{Azure.Ruby.Tests => Ruby.Tests}/RspecTests/custom_base_uri_spec.rb (100%) create mode 100644 AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/duration_spec.rb create mode 100644 AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/validation_spec.rb diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb index b0f8ec0d72983..582537768f8cc 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_report_spec.rb @@ -28,6 +28,6 @@ end puts "Test Coverage is #{count_of_calls}/#{count_of_methods}" - expect(count_of_calls / count_of_methods.to_f > 0.4).to be_truthy + expect(count_of_calls / count_of_methods.to_f > 0.95).to be_truthy end end diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb index 45d7abcd09ada..0bac5f72710cd 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/azure_special_properties_spec.rb @@ -153,7 +153,29 @@ headers['x-ms-client-request-id'] = @validClientId result = @client.xms_client_request_id.get_async(headers).value! expect(result.response.status).to eq(200) - expect(result.request_id).to eq("123") + expect(result.response.headers['x-ms-request-id']).to eq("123") + end + + # it 'should not overwrite x-ms-client-request-id' do + # test_client = AutoRestAzureSpecialParametersTestClient.new(@credentials, @base_url) + # test_client.subscription_id = @validSubscription + # test_client.generate_client_request_id = false + # + # result = test_client.xms_client_request_id.get_async().value! + # expect(result.response.status).to eq(200) + # expect(result.response.headers['x-ms-request-id']).to eq("123") + # end + + it 'should have x-ms-request-id in the error object' do + headers = Hash.new + headers['x-ms-client-request-id'] = '123' + + begin + @client.xms_client_request_id.get_async(headers).value! + fail 'should have thrown MsRestAzure::AzureOperationError' + rescue MsRestAzure::AzureOperationError => error + expect(error.response.headers['x-ms-request-id']).to eq("123") + end end it 'should overwrite hard coded headers with custom headers from parameters' do @@ -163,11 +185,15 @@ end it 'should allow custom-named request-id headers to be used with parameter grouping' do - pending 'Ruby does not support parameter grouping yet' - fail result = @client.header.custom_named_request_id_async(@validClientId).value! expect(result.response.status).to eq(200) expect(result.request_id).to eq("123") end + # OData filters Tests + it 'should support OData filter' do + filter = "id gt 5 and name eq 'foo'" + result = @client.odata.get_with_filter_async(filter, 10, 'id').value! + expect(result.response.status).to eq(200) + end end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb index d5701bc983b8d..df15722f5d98e 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb +++ b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/lro_spec.rb @@ -8,221 +8,424 @@ include LroModule include LroModule::Models -describe 'LongRunningOperation' do - +describe 'Long Running Operation' do before(:all) do - @base_url = ENV['StubServerURI'] + base_url = ENV['StubServerURI'] dummyToken = 'dummy12321343423' - @credentials = MsRest::TokenCredentials.new(dummyToken) + credentials = MsRest::TokenCredentials.new(dummyToken) + + test_client = AutoRestLongRunningOperationTestService.new(credentials, base_url) + test_client.long_running_operation_retry_timeout = 0 + @lros_client = test_client.lros - @client = AutoRestLongRunningOperationTestService.new(@credentials, @base_url) - @client.long_running_operation_retry_timeout = 0 @product = Product.new @product.location = "West US" + + @sku = Sku.new + @sku.name = 'doesNotMatter' + @sku.id = 'doesNotMatter' end # Happy path tests it 'should wait for succeeded status for create operation' do - result = @client.lros.put201creating_succeeded200(@product).value! + result = @lros_client.put201creating_succeeded200(@product).value! expect(result.body.provisioning_state).to eq("Succeeded") end it 'should rise error on "failed" operation result' do - expect { @client.lros.put201creating_failed200(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) + expect { @lros_client.put201creating_failed200(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) end it 'should wait for succeeded status for update operation' do - result = @client.lros.put200updating_succeeded204(@product).value! + result = @lros_client.put200updating_succeeded204(@product).value! expect(result.body.provisioning_state).to eq("Succeeded") end it 'should rise error on "canceled" operation result' do - expect { @client.lros.put200acceptedcanceled200(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) + expect { @lros_client.put200acceptedcanceled200(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) end - it 'should retry on 200 server responce in POST request' do - result = @client.lros.post202retry200(@product).value! + it 'should retry on 202 server response in POST request' do + result = @lros_client.post202retry200(@product).value! expect(result.response.status).to eq(200) end - it 'should serve success responce on initial PUT request' do - result = @client.lros.put200succeeded(@product).value! + it 'should not retry on 202 server response in POST request' do + result = @lros_client.post202no_retry204(@product).value! + expect(result.response.status).to eq(204) + end + + it 'should serve success response on initial PUT request' do + result = @lros_client.put200succeeded(@product).value! expect(result.body.provisioning_state).to eq("Succeeded") end - it 'should serve success responce on initial request without provision state' do - result = @client.lros.put200succeeded_no_state(@product).value! + it 'should serve success response on initial request without provision state' do + result = @lros_client.put200succeeded_no_state(@product).value! expect(result.body.id).to eq("100") expect(result.body.provisioning_state).to eq(nil) end - it 'should serve 202 on initial responce and status responce without provision state' do - result = @client.lros.put202retry200(@product).value! + it 'should serve 202 on initial response and status response without provision state' do + result = @lros_client.put202retry200(@product).value! expect(result.body.id).to eq("100") expect(result.body.provisioning_state).to eq(nil) end - it 'should retry on 500 server responce in PUT request' do - result = @client.lroretrys.put_async_relative_retry_succeeded(@product).value! + it 'should serve success response on initial DELETE request' do + result = @lros_client.delete204succeeded().value! + expect(result.response.status).to eq(204) + end + + it 'should return payload on POST async request' do + result = @lros_client.post200with_payload().value! + expect(result.body.id).to eq(1) + end + + it 'should succeed for put async retry' do + result = @lros_client.put_async_retry_succeeded(@product).value! + expect(result.response.status).to eq(200) expect(result.body.provisioning_state).to eq("Succeeded") end - # TODO: Fix flakey test - #it 'should serve async PUT operation failed' do - # expect { @client.lrosads.put_async_relative_retry400_async(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) - #end + it 'should succeed for put async no retry' do + result = @lros_client.put_async_no_retry_succeeded(@product).value! + expect(result.response.status).to eq(200) + end + + it 'should fail for put async retry' do + expect { @lros_client.put_async_retry_failed(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) + end + + it 'should fail for put async no retry canceled' do + expect { @lros_client.put_async_no_retrycanceled(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) + end + + it 'should succeed for post async retry' do + result = @lros_client.post_async_retry_succeeded(@product).value! + expect(result.response.status).to eq(200) + end + + it 'should succeed for post async no retry' do + result = @lros_client.post_async_no_retry_succeeded(@product).value! + expect(result.response.status).to eq(200) + end + + it 'should fail for post async retry' do + expect { @lros_client.post_async_retry_failed(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) + end - it 'should serve success responce on initial DELETE request' do - result = @client.lros.delete204succeeded().value! + it 'should fail for post async retry canceled' do + expect { @lros_client.post_async_retrycanceled(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) + end + + it 'should succeed for put no header in retry' do + result = @lros_client.put_no_header_in_retry(@product).value! + expect(result.response.status).to eq(200) + expect(result.body.provisioning_state).to eq("Succeeded") + end + + it 'should succeed for put async no header in retry' do + result = @lros_client.put_async_no_header_in_retry(@product).value! + expect(result.response.status).to eq(200) + expect(result.body.provisioning_state).to eq("Succeeded") + end + + it 'should succeed for delete no header in retry' do + result = @lros_client.delete_no_header_in_retry().value! expect(result.response.status).to eq(204) end - it 'should retry on 500 server responce in DELETE request' do - result = @client.lroretrys.delete_async_relative_retry_succeeded().value! + it 'should succeed for delete async no header in retry' do + result = @lros_client.delete_async_no_header_in_retry().value! expect(result.response.status).to eq(200) end - it 'should serve async POST operation' do - result = @client.lroretrys.post_async_relative_retry_succeeded(@product).value! + it 'should succeed for put sub resource' do + result = @lros_client.put_sub_resource(@product).value! expect(result.response.status).to eq(200) + expect(result.body.provisioning_state).to eq("Succeeded") end - it 'should return payload on POST async request' do - result = @client.lros.post200with_payload().value! - expect(result.body.id).to eq(1) + it 'should succeed for put async sub resource' do + result = @lros_client.put_async_sub_resource(@product).value! + expect(result.response.status).to eq(200) + expect(result.body.provisioning_state).to eq("Succeeded") + end + + it 'should succeed for put non resource' do + result = @lros_client.put_non_resource(@sku).value! + expect(result.response.status).to eq(200) + expect(result.body.id).to eq('100') + expect(result.body.name).to eq('sku') + end + + it 'should succeed for put async non resource' do + result = @lros_client.put_async_non_resource(@sku).value! + expect(result.response.status).to eq(200) + expect(result.body.id).to eq('100') + expect(result.body.name).to eq('sku') + end + + it 'should succeed for delete provisioning 202 accepted 200' do + result = @lros_client.delete_provisioning202accepted200succeeded().value! + expect(result.response.status).to eq(200) + expect(result.body.provisioning_state).to eq("Succeeded") + end + + it 'should succeed for delete provisioning 202 deleting failed 200' do + result = @lros_client.delete_provisioning202deleting_failed200().value! + expect(result.response.status).to eq(200) + expect(result.body.provisioning_state).to eq("Failed") + end + + it 'should succeed for delete provisioning 202 deleting canceled 200' do + result = @lros_client.delete_provisioning202deletingcanceled200().value! + expect(result.response.status).to eq(200) + expect(result.body.provisioning_state).to eq("Canceled") + end + + it 'should succeed for delete 204' do + result = @lros_client.delete204succeeded().value! + expect(result.response.status).to eq(204) + end + + it 'should succeed for delete 202 retry 200' do + result = @lros_client.delete202retry200().value! + expect(result.response.status).to eq(200) + end + + it 'should succeed for delete 202 no retry 204' do + result = @lros_client.delete202no_retry204().value! + expect(result.response.status).to eq(204) + end + + it 'should succeed for delete async retry' do + result = @lros_client.delete_async_retry_succeeded().value! + expect(result.response.status).to eq(200) + end + + it 'should succeed for delete async no retry' do + result = @lros_client.delete_async_no_retry_succeeded().value! + expect(result.response.status).to eq(200) + end + + it 'should fail for delete async retry failed' do + expect { @lros_client.delete_async_retry_failed().value! }.to raise_error(MsRestAzure::AzureOperationError) + end + + it 'should fail for delete async retry canceled' do + expect { @lros_client.delete_async_retrycanceled().value! }.to raise_error(MsRestAzure::AzureOperationError) + end +end + +describe 'Long Running Operation with retry' do + before(:all) do + base_url = ENV['StubServerURI'] + + dummyToken = 'dummy12321343423' + credentials = MsRest::TokenCredentials.new(dummyToken) + + test_client = AutoRestLongRunningOperationTestService.new(credentials, base_url) + test_client.long_running_operation_retry_timeout = 0 + @lroretrys_client = test_client.lroretrys + @product = Product.new + @product.location = "West US" end # Retryable errors - it 'should retry PUT request on 500 responce' do - result = @client.lroretrys.put201creating_succeeded200(@product).value! + it 'should retry PUT request on 500 response' do + result = @lroretrys_client.put201creating_succeeded200(@product).value! expect(result.body.provisioning_state).to eq("Succeeded") end - it 'should retry PUT request on 500 responce for async operation' do - result = @client.lroretrys.put_async_relative_retry_succeeded(@product).value! + it 'should retry PUT request on 500 response for async operation' do + result = @lroretrys_client.put_async_relative_retry_succeeded(@product).value! expect(result.body.provisioning_state).to eq("Succeeded") end it 'should retry DELETE request for provisioning status' do - result = @client.lroretrys.delete_provisioning202accepted200succeeded().value! + result = @lroretrys_client.delete_provisioning202accepted200succeeded().value! expect(result.response.status).to eq(200) end - it 'should retry DELETE request on 500 responce' do - result = @client.lroretrys.delete202retry200().value! + it 'should retry DELETE request on 500 response' do + result = @lroretrys_client.delete202retry200().value! expect(result.response.status).to eq(200) end - it 'should retry POST request on 500 responce' do - result = @client.lroretrys.post202retry200(@product).value! + it 'should retry POST request on 500 response' do + result = @lroretrys_client.post202retry200(@product).value! expect(result.response.status).to eq(200) end - it 'should retry POST request on 500 responce for async operation' do - result = @client.lroretrys.post_async_relative_retry_succeeded(@product).value! + it 'should retry POST request on 500 response for async operation' do + result = @lroretrys_client.post_async_relative_retry_succeeded(@product).value! expect(result.response.status).to eq(200) end + it 'should retry on 500 server response in PUT request' do + result = @lroretrys_client.put_async_relative_retry_succeeded(@product).value! + expect(result.body.provisioning_state).to eq("Succeeded") + end + + it 'should retry on 500 server response in DELETE request' do + result = @lroretrys_client.delete_async_relative_retry_succeeded().value! + expect(result.response.status).to eq(200) + end +end + +describe 'Long Running Operation with ads' do + before(:all) do + base_url = ENV['StubServerURI'] + + dummyToken = 'dummy12321343423' + credentials = MsRest::TokenCredentials.new(dummyToken) + + test_client = AutoRestLongRunningOperationTestService.new(credentials, base_url) + test_client.long_running_operation_retry_timeout = 0 + @lroads_client = test_client.lrosads + @product = Product.new + @product.location = "West US" + end + # Sad path tests - it 'should rise error on responce 400 for PUT request' do - expect { @client.lrosads.put_non_retry400(@product).value! }.to raise_exception(MsRest::HttpOperationError) + it 'should rise error on response 400 for PUT request' do + expect { @lroads_client.put_non_retry400(@product).value! }.to raise_exception(MsRest::HttpOperationError) end - it 'should rise error if 400 responce comes in the middle of PUT operation' do - expect { @client.lrosads.put_non_retry201creating400(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) + it 'should rise error if 400 response comes in the middle of PUT operation' do + expect { @lroads_client.put_non_retry201creating400(@product).value! }.to raise_error(MsRestAzure::AzureOperationError) end - it 'should rise error if 400 responce comes in the middle of async PUT operation' do - expect { @client.lrosads.put_async_relative_retry400(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + it 'should rise error if 400 response comes in the middle of async PUT operation' do + expect { @lroads_client.put_async_relative_retry400(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end - it 'should rise error on responce 400 for DELETE request' do - expect { @client.lrosads.delete_non_retry400().value! }.to raise_exception(MsRest::HttpOperationError) + it 'should rise error on response 400 for DELETE request' do + expect { @lroads_client.delete_non_retry400().value! }.to raise_exception(MsRest::HttpOperationError) end - it 'should rise error if 400 responce comes in the middle of DELETE operation' do - expect{ @client.lrosads.delete_async_relative_retry400().value! }.to raise_exception(MsRestAzure::AzureOperationError) + it 'should rise error if 400 response comes in the middle of DELETE operation' do + expect{ @lroads_client.delete_async_relative_retry400().value! }.to raise_exception(MsRestAzure::AzureOperationError) end - it 'should rise error if 400 responce comes from POST request' do - expect{ @client.lrosads.post_non_retry400(@product).value! }.to raise_exception(MsRest::HttpOperationError) + it 'should rise error if 400 response comes from POST request' do + expect{ @lroads_client.post_non_retry400(@product).value! }.to raise_exception(MsRest::HttpOperationError) end - it 'should rise error on responce 400 for POST request' do - expect{ @client.lrosads.post202non_retry400(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + it 'should rise error on response 400 for POST request' do + expect{ @lroads_client.post202non_retry400(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end - it 'should rise error if 400 responce comes in the middle of async POST operation' do - expect{ @client.lrosads.post_async_relative_retry400(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + it 'should rise error if 400 response comes in the middle of async POST operation' do + expect{ @lroads_client.post_async_relative_retry400(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end it 'should rise error if no provisioning state in payload provided on PUT request' do - expect{ @client.lrosads.put_error201no_provisioning_state_payload(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.put_error201no_provisioning_state_payload(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end it 'should rise error if no state provided on PUT request' do - expect{ @client.lrosads.put_async_relative_retry_no_status(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.put_async_relative_retry_no_status(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end it 'should rise error if no provisioning state in payload provided on async PUT request' do - expect{ @client.lrosads.put_async_relative_retry_no_status_payload(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.put_async_relative_retry_no_status_payload(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end - it 'should rise error on invalid JSON responce on initial request' do - expect{ @client.lrosads.put200invalid_json(@product).value! }.to raise_exception(MsRest::DeserializationError) + it 'should rise error on invalid JSON response on initial request' do + expect{ @lroads_client.put200invalid_json(@product).value! }.to raise_exception(MsRest::DeserializationError) end it 'should rise error on invalid endpoint received in initial PUT request' do - expect{ @client.lrosads.put_async_relative_retry_invalid_header(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.put_async_relative_retry_invalid_header(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end - it 'should rise error on invalid JSON responce in status polling request during PUT operation' do - expect{ @client.lrosads.put_async_relative_retry_invalid_json_polling(@product).value! }.to raise_exception(MsRest::DeserializationError) + it 'should rise error on invalid JSON response in status polling request during PUT operation' do + expect{ @lroads_client.put_async_relative_retry_invalid_json_polling(@product).value! }.to raise_exception(MsRest::DeserializationError) end it 'should rise error on invalid Location and Retry-After headers during DELETE operation' do - expect{ @client.lrosads.delete202retry_invalid_header().value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.delete202retry_invalid_header().value! }.to raise_exception(MsRestAzure::AzureOperationError) end it 'should rise error on invalid endpoint received in initial DELETE request' do - expect{ @client.lrosads.delete_async_relative_retry_invalid_header().value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.delete_async_relative_retry_invalid_header().value! }.to raise_exception(MsRestAzure::AzureOperationError) end - # TODO: Fix flakey test - #it 'should rise error on invalid JSON responce in status polling request during DELETE operation' do - # expect{ @client.lrosads.delete_async_relative_retry_invalid_json_polling_async().value! }.to raise_exception(MsRest::DeserializationError) - #end + it 'should rise error on invalid JSON response in status polling request during DELETE operation' do + expect{ @lroads_client.delete_async_relative_retry_invalid_json_polling().value! }.to raise_exception(MsRest::DeserializationError) + end it 'should rise error on invalid Location and Retry-After headers during POST operation' do - expect{ @client.lrosads.post202retry_invalid_header(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.post202retry_invalid_header(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end it 'should rise error on invalid endpoint received in initial POST request' do - expect{ @client.lrosads.post_async_relative_retry_invalid_header(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.post_async_relative_retry_invalid_header(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end - it 'should rise error on invalid JSON responce in status polling request during POST operation' do - expect{ @client.lrosads.post_async_relative_retry_invalid_json_polling(@product).value! }.to raise_exception(MsRest::DeserializationError) + it 'should rise error on invalid JSON response in status polling request during POST operation' do + expect{ @lroads_client.post_async_relative_retry_invalid_json_polling(@product).value! }.to raise_exception(MsRest::DeserializationError) end - it 'should not rise error on DELETE operation with 204 responce without location provided' do - result = @client.lrosads.delete204succeeded().value! + it 'should not rise error on DELETE operation with 204 response without location provided' do + result = @lroads_client.delete204succeeded().value! expect(result.response.status).to eq(204) end - # TODO: Fix flakey test - #it 'should rise error on no status provided for DELETE async operation' do - # expect{ @client.lrosads.delete_async_relative_retry_no_status_async().value! }.to raise_exception(MsRestAzure::AzureOperationError) - #end + it 'should rise error on no status provided for DELETE async operation' do + expect{ @lroads_client.delete_async_relative_retry_no_status().value! }.to raise_exception(MsRestAzure::AzureOperationError) + end it 'should rise error if no location provided' do pending 'fails for in travis' fail - expect { @client.lrosads.post202no_location(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect { @lroads_client.post202no_location(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) end it 'should rise error if no payload provided on POST async retry request' do - expect{ @client.lrosads.post_async_relative_retry_no_payload(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + expect{ @lroads_client.post_async_relative_retry_no_payload(@product).value! }.to raise_exception(MsRestAzure::AzureOperationError) + end + + it 'should rise error if no payload provided on DELETE non retry request' do + expect{ @lroads_client.delete202non_retry400().value! }.to raise_exception(MsRestAzure::AzureOperationError) end end + +describe 'Long Running Operation with custom header' do + before(:all) do + base_url = ENV['StubServerURI'] + dummyToken = 'dummy12321343423' + credentials = MsRest::TokenCredentials.new(dummyToken) + + test_client = AutoRestLongRunningOperationTestService.new(credentials, base_url) + test_client.long_running_operation_retry_timeout = 0 + @lros_custom_header_client = test_client.lros_custom_header + @product = Product.new + @product.location = "West US" + @custom_header = { 'x-ms-client-request-id' => '9C4D50EE-2D56-4CD3-8152-34347DC9F2B0' } + end + + it 'should succeed for custom header put async' do + result = @lros_custom_header_client.put_async_retry_succeeded(@product, @custom_header).value! + expect(result.body.provisioning_state).to eq("Succeeded") + end + + it 'should succeed for custom header post async' do + result = @lros_custom_header_client.post_async_retry_succeeded(@product, @custom_header).value! + expect(result.response.status).to eq(200) + end + + it 'should succeed for custom header put' do + result = @lros_custom_header_client.put201creating_succeeded200(@product, @custom_header).value! + expect(result.body.provisioning_state).to eq("Succeeded") + end + + it 'should succeed for custom header post' do + result = @lros_custom_header_client.post202retry200(@product, @custom_header).value! + expect(result.response.status).to eq(200) + end +end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/parameter_grouping_spec.rb b/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/parameter_grouping_spec.rb similarity index 100% rename from AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/parameter_grouping_spec.rb rename to AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/parameter_grouping_spec.rb diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb index c78494c9ec7e3..c91e7c8f61b8b 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/array_spec.rb @@ -309,6 +309,12 @@ module ArrayModule end end + it 'should get complex array empty' do + result = @array_client.get_complex_empty_async().value! + expect(result.response.status).to eq(200) + expect(result.body.count).to eq(0) + end + it 'should get complex item empty' do result = @array_client.get_complex_item_empty_async().value! expect(result.response.status).to eq(200) @@ -339,6 +345,10 @@ module ArrayModule expect(result.body).to be_nil end + it 'should handle invalid value for arrays' do + expect { @array_client.get_invalid_async().value! }.to raise_error(MsRest::DeserializationError) + end + it 'should get array empty' do result = @array_client.get_array_empty_async().value! expect(result.response.status).to eq(200) @@ -403,6 +413,21 @@ module ArrayModule result = @array_client.put_dictionary_valid_async(@arr_dict).value! expect(result.response.status).to eq(200) end + + it 'should get uuid arrays' do + result = @array_client.get_uuid_valid_async().value! + expect(result.response.status).to eq(200) + expect(result.body.count).to eq(3) + expect(result.body[0]).to eq('6dcc7237-45fe-45c4-8a6b-3a8a3f625652') + expect(result.body[1]).to eq('d1399005-30f7-40d6-8da6-dd7c89ad34db') + expect(result.body[2]).to eq('f42f6aa1-a5bc-4ddf-907e-5f915de43205') + end + + it 'should put uuid arrays' do + array_body = ['6dcc7237-45fe-45c4-8a6b-3a8a3f625652', 'd1399005-30f7-40d6-8da6-dd7c89ad34db', 'f42f6aa1-a5bc-4ddf-907e-5f915de43205'] + result = @array_client.put_uuid_valid_async(array_body).value! + expect(result.response.status).to eq(200) + end end end diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb index 2274cc9edeaae..fc48113a73f20 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/complex_spec.rb @@ -462,6 +462,38 @@ module ComplexModule result = @client.primitive.put_byte_async(@byte_wrapper).value! expect(result.response.status).to eq(200) end + + it 'should get complex primitive string type' do + result = @client.primitive.get_string_async().value! + expect(result.response.status).to eq(200) + + string_wrapper = result.body + expect(string_wrapper).to be_instance_of(StringWrapper) + expect(string_wrapper.field).to eq('goodrequest') + expect(string_wrapper.empty).to eq('') + end + + it 'should put complex primitive string type' do + string_wrapper = StringWrapper.new + string_wrapper.field = 'goodrequest' + string_wrapper.empty = '' + + result = @client.primitive.put_string_async(string_wrapper).value! + expect(result.response.status).to eq(200) + end + + it 'should get & put complex readonly property valid' do + result = @client.readonlyproperty.get_valid_async().value! + expect(result.response.status).to eq(200) + + readonly_obj = result.body + expect(readonly_obj).to be_instance_of(ReadonlyObj) + expect(readonly_obj.id).to eq('1234') + expect(readonly_obj.size).to eq(2) + + result = @client.readonlyproperty.put_valid_async(readonly_obj).value! + expect(result.response.status).to eq(200) + end end end diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb similarity index 100% rename from AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb rename to AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/custom_base_uri_more_spec.rb diff --git a/AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/custom_base_uri_spec.rb similarity index 100% rename from AutoRest/Generators/Ruby/Azure.Ruby.Tests/RspecTests/custom_base_uri_spec.rb rename to AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/custom_base_uri_spec.rb diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/duration_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/duration_spec.rb new file mode 100644 index 0000000000000..2e8b968a6a38a --- /dev/null +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/duration_spec.rb @@ -0,0 +1,37 @@ +# encoding: utf-8 + +$: << 'RspecTests' +$: << 'RspecTests/Generated/duration' + +require 'generated/body_duration' + +module DurationModule + + describe DurationModule::Duration do + before(:all) do + @base_url = ENV['StubServerURI'] + + dummyToken = 'dummy12321343423' + @credentials = MsRest::TokenCredentials.new(dummyToken) + + client = DurationModule::AutoRestDurationTestService.new(@credentials, @base_url) + @duration_client = DurationModule::Duration.new(client) + end + + it 'should create test service' do + expect { DurationModule::AutoRestDurationTestService.new(@credentials, @base_url) }.not_to raise_error + end + + it 'should properly handle null value for Duration' do + result = @duration_client.get_null_async().value! + expect(result.response.status).to eq(200) + end + + it 'should properly handle invalid value for Duration' do + result = @duration_client.get_invalid_async().value! + expect(result.response.status).to eq(200) + puts result.body.to_s + end + end + +end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb index 91e2bcbced96d..d58072db25b2b 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/header_spec.rb @@ -172,6 +172,11 @@ def to_bool(str) expect(result.response.status).to eq(200) end + it 'should post empty param string' do + result = @header_client.param_string_async('empty', '').value! + expect(result.response.status).to eq(200) + end + it 'should get valid response string' do result = @header_client.response_string_async("valid").value! expect(result.response.status).to eq(200) @@ -207,41 +212,31 @@ def to_bool(str) end it 'should get response min date' do - pending('proper working with datetime isnt implemented yet') - fail - # result = @header_client.response_date_async("min").value! - # expect(result.response.status).to eq(200) - # expect(Date.parse(result.response['value'])).to eq(Date.parse('0001-01-01')) + result = @header_client.response_date_async("min").value! + expect(result.response.status).to eq(200) + expect(Date.parse(result.response.headers['value'])).to eq(Date.parse('0001-01-01')) end it 'should post valid param dateTime' do - pending('proper working with datetime isnt implemented yet') - fail - # result = @header_client.param_datetime_async("valid", DateTime.new(2010, 1, 1, 12, 34, 56)).value! - # expect(result.response.status).to eq(200) + result = @header_client.param_datetime_async("valid", DateTime.new(2010, 1, 1, 12, 34, 56)).value! + expect(result.response.status).to eq(200) end it 'should post min param dateTime' do - pending('proper working with datetime isnt implemented yet') - fail - # result = @header_client.param_datetime_async("min", DateTime.new(1, 1, 1, 0, 0, 0)).value! - # expect(result.response.status).to eq(200) + result = @header_client.param_datetime_async("min", DateTime.new(1, 1, 1, 0, 0, 0)).value! + expect(result.response.status).to eq(200) end it 'should get response valid dateTime' do - pending('proper working with datetime isnt implemented yet') - fail - # result = @header_client.response_datetime_async("valid").value! - # expect(result.response.status).to eq(200) - # expect(Date.parse(result.response['value'])).to eq(Date.parse('2010-01-01T12:34:56Z')) + result = @header_client.response_datetime_async("valid").value! + expect(result.response.status).to eq(200) + expect(Date.parse(result.response.headers['value'])).to eq(Date.parse('2010-01-01T12:34:56Z')) end it 'should get response min dateTime' do - pending('proper working with datetime isnt implemented yet') - fail - # result = @header_client.response_datetime_async("min").value! - # expect(result.response.status).to eq(200) - # expect(Date.parse(result.response['value'])).to eq(Date.parse('0001-01-01T00:00:00Z')) + result = @header_client.response_datetime_async("min").value! + expect(result.response.status).to eq(200) + expect(Date.parse(result.response.headers['value'])).to eq(Date.parse('0001-01-01T00:00:00Z')) end it 'should post valid param dateTimeRfc1123' do @@ -281,6 +276,23 @@ def to_bool(str) # expect(result.response.status).to eq(200) # expect(Base64.strict_decode64(result.response['value']).unpack('C*')).to eq("啊齄丂狛狜隣郎隣兀﨩".bytes.pack('U*')) end + + it 'should post valid enum' do + result = @header_client.param_enum_async('valid', GreyscaleColors::GREY).value! + expect(result.response.status).to eq(200) + end + + it 'should get valid enum' do + result = @header_client.response_enum_async('valid').value! + expect(result.response.status).to eq(200) + expect(result.response.headers['value']).to eq(GreyscaleColors::GREY) + end + + it 'should get null enum' do + result = @header_client.response_enum_async('null').value! + expect(result.response.status).to eq(200) + expect(result.response.headers['value']).to eq('') + end end end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb index 2e1e206340953..c44b2fa418f2c 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/query_spec.rb @@ -17,6 +17,8 @@ client = AutoRestUrlTestService.new(@credentials, @base_url) @queries_client = Queries.new(client) + + @test_array = ['ArrayQuery1', 'begin!*\'();:@ &=+$,/?#[]end', nil, ''] end it 'should create test service' do @@ -135,4 +137,34 @@ result = @queries_client.date_time_null_async().value! expect(result.response.status).to eq(200) end + + it 'should work with null array string with csv format' do + result = @queries_client.array_string_csv_null_async().value! + expect(result.response.status).to eq(200) + end + + it 'should work with empty array string with csv format' do + result = @queries_client.array_string_csv_empty_async([]).value! + expect(result.response.status).to eq(200) + end + + it 'should work with empty array string with csv format' do + result = @queries_client.array_string_csv_valid_async(@test_array).value! + expect(result.response.status).to eq(200) + end + + it 'should work with empty array string with pipes format' do + result = @queries_client.array_string_pipes_valid_async(@test_array).value! + expect(result.response.status).to eq(200) + end + + it 'should work with empty array string with ssv format' do + result = @queries_client.array_string_ssv_valid_async(@test_array).value! + expect(result.response.status).to eq(200) + end + + it 'should work with empty array string with tsv format' do + result = @queries_client.array_string_tsv_valid_async(@test_array).value! + expect(result.response.status).to eq(200) + end end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb index 72c5b92f9d11b..2542f11db7274 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/report_spec.rb @@ -26,6 +26,6 @@ end end puts "Test Coverage is #{count_of_calls}/#{count_of_methods}" - expect(count_of_calls/count_of_methods.to_f > 0.5).to be_truthy + expect(count_of_calls/count_of_methods.to_f > 0.90).to be_truthy end end diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb index 3ee8fa777d434..644d2533a9b9e 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/string_spec.rb @@ -72,4 +72,13 @@ it 'should correctly handle invalid values for enum' do expect { @enum_client.put_not_expandable_async('orange color').value! }.to raise_error(MsRest::ValidationError) end + it 'should get non-expandable enum' do + result = @enum_client.get_not_expandable_async().value! + expect(result.response.status).to eq(200) + expect(result.body).to eq(StringModule::Models::Colors::Redcolor) + end + it 'should put non-expandable enum' do + result = @enum_client.put_not_expandable_async(StringModule::Models::Colors::Redcolor).value! + expect(result.response.status).to eq(200) + end end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/validation_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/validation_spec.rb new file mode 100644 index 0000000000000..be7d577b4bb61 --- /dev/null +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/validation_spec.rb @@ -0,0 +1,30 @@ +# encoding: utf-8 + +$: << 'RspecTests/Generated/validation' + +require 'rspec' +require 'generated/validation' + +describe 'Validation Module' do + + before(:all) do + @base_url = ENV['StubServerURI'] + + dummyToken = 'dummy12321343423' + @credentials = MsRest::TokenCredentials.new(dummyToken) + + @client = ValidationModule::AutoRestValidationTest.new(@credentials, @base_url) + end + + it 'should work with constant in path' do + result = @client.get_with_constant_in_path_async().value! + expect(result.response.status).to eq(200) + end + + it 'should work with constant in body' do + product = ValidationModule::Models::Product.new + product.child = Hash.new + result = @client.post_with_constant_in_body_async({ 'child' => {} }).value! + expect(result.response.status).to eq(200) + end +end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs b/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs index 3268f6a2e84f4..ab94471d162f8 100644 --- a/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs +++ b/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs @@ -39,10 +39,14 @@ public static string ToString(this IType type, string reference) string result = string.Format("{0}.to_s", reference); if (known != null) { - if (known.Type == KnownPrimaryType.String || known.Type == KnownPrimaryType.DateTime) + if (known.Type == KnownPrimaryType.String) { result = reference; } + else if (known.Type == KnownPrimaryType.DateTime) + { + result = string.Format("{0}.new_offset(0).strftime('%FT%TZ')", reference); + } else if (known.Type == KnownPrimaryType.DateTimeRfc1123) { result = string.Format("{0}.strftime('%a, %d %b %Y %H:%M:%S GMT')", reference); @@ -199,7 +203,7 @@ public static string GetFormattedReferenceValue(this Parameter parameter) "non-string array parameter {0}", parameter)); } - return string.Format("{0}.join('{1}')", parameter.Name, parameter.CollectionFormat.GetSeparator()); + return string.Format("{0}.nil? ? nil : {0}.join('{1}')", parameter.Name, parameter.CollectionFormat.GetSeparator()); } /// diff --git a/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/async_operation_status.rb b/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/async_operation_status.rb index 57870a081ff5a..6d3f8b0b10146 100644 --- a/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/async_operation_status.rb +++ b/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/async_operation_status.rb @@ -7,13 +7,14 @@ module MsRestAzure # Defines values for AsyncOperationStatus enum. # class AsyncOperationStatus + ACCEPTED = 'Accepted' IN_PROGRESS_STATUS = 'InProgress' RUNNING = 'Running' SUCCESS_STATUS = 'Succeeded' FAILED_STATUS = 'Failed' CANCELED_STATUS = 'Canceled' - ALL_STATUSES = [FAILED_STATUS, CANCELED_STATUS, SUCCESS_STATUS, IN_PROGRESS_STATUS, RUNNING] + ALL_STATUSES = [ACCEPTED, FAILED_STATUS, CANCELED_STATUS, SUCCESS_STATUS, IN_PROGRESS_STATUS, RUNNING] FAILED_STATUSES = [FAILED_STATUS, CANCELED_STATUS] TERMINAL_STATUSES = [FAILED_STATUS, CANCELED_STATUS, SUCCESS_STATUS] diff --git a/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/azure_service_client.rb b/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/azure_service_client.rb index 0dc6edd7f97a7..64cbed1e5067e 100644 --- a/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/azure_service_client.rb +++ b/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/azure_service_client.rb @@ -36,7 +36,7 @@ def get_long_running_operation_result(azure_response, custom_deserialization_blo elsif !polling_state.location_header_link.nil? update_state_from_location_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri), polling_state, custom_deserialization_block) elsif http_method === :put - get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, query_params: request.query_params) + get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers}) update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block) else task.shutdown @@ -64,7 +64,7 @@ def get_long_running_operation_result(azure_response, custom_deserialization_blo end if (http_method === :put || http_method === :patch) && AsyncOperationStatus.is_successful_status(polling_state.status) && polling_state.resource.nil? - get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, query_params: request.query_params) + get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers}) update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block) end @@ -181,6 +181,8 @@ def update_state_from_azure_async_operation_header(request, polling_state) polling_state.response = result.response polling_state.request = result.request polling_state.resource = nil + + polling_state end # @@ -212,6 +214,7 @@ def get_async_with_async_operation_deserialization(request) result = get_async_common(request) result.body = AsyncOperationStatus.deserialize_object(result.body) + result end @@ -224,7 +227,8 @@ def get_async_common(request) fail ValidationError, 'Request cannot be nil' if request.nil? request.middlewares = [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]] - request.headers.merge!({'x-ms-client-request-id' => SecureRandom.uuid, 'Content-Type' => 'application/json'}) + request.headers.merge!({'x-ms-client-request-id' => SecureRandom.uuid}) unless request.headers.key?('x-ms-client-request-id') + request.headers.merge!({'Content-Type' => 'application/json'}) unless request.headers.key?('Content-Type') # Send Request http_response = request.run_promise do |req| diff --git a/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/polling_state.rb b/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/polling_state.rb index 28d4bffab9ff0..18dbdd0ab99a2 100644 --- a/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/polling_state.rb +++ b/ClientRuntimes/Ruby/ms-rest-azure/lib/ms_rest_azure/polling_state.rb @@ -35,7 +35,7 @@ def initialize(azure_response, retry_timeout) update_response(azure_response.response) @resource = azure_response.body - if (!@resource.nil? && @resource.respond_to?(:provisioning_state) && !@resource.provisioning_state.nil?) + if !@resource.nil? && @resource.respond_to?(:provisioning_state) && !@resource.provisioning_state.nil? @status = @resource.provisioning_state else case @response.status @@ -56,7 +56,7 @@ def initialize(azure_response, retry_timeout) def get_delay return @retry_timeout unless @retry_timeout.nil? - if (!response.nil? && !response.headers['Retry-After'].nil?) + if !response.nil? && !response.headers['Retry-After'].nil? return response.headers['Retry-After'].to_i end @@ -69,7 +69,7 @@ def get_delay def update_response(response) @response = response - if (!response.nil?) + unless response.nil? @azure_async_operation_header_link = response.headers['Azure-AsyncOperation'] unless response.headers['Azure-AsyncOperation'].nil? @location_header_link = response.headers['Location'] unless response.headers['Location'].nil? end @@ -94,6 +94,7 @@ def get_operation_error def get_request(options = {}) link = @azure_async_operation_header_link || @location_header_link + options[:connection] = create_connection(options[:base_uri]) MsRest::HttpOperationRequest.new(nil, link, :get, options) end @@ -101,6 +102,20 @@ def get_request(options = {}) # @return [Integer] retry timeout. attr_accessor :retry_timeout + + attr_accessor :connection + + def create_connection(base_url) + @connection ||= Faraday.new(:url => base_url) do |faraday| + [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]].each{ |args| faraday.use(*args) } + faraday.adapter Faraday.default_adapter + faraday.headers = request.headers + logging = ENV['AZURE_HTTP_LOGGING'] || request.log + if logging + faraday.response :logger, nil, { :bodies => logging == 'full' } + end + end + end end end \ No newline at end of file diff --git a/ClientRuntimes/Ruby/ms-rest-azure/spec/azure_service_client_spec.rb b/ClientRuntimes/Ruby/ms-rest-azure/spec/azure_service_client_spec.rb index e3c0eee6afe5f..d14c7aed14af0 100644 --- a/ClientRuntimes/Ruby/ms-rest-azure/spec/azure_service_client_spec.rb +++ b/ClientRuntimes/Ruby/ms-rest-azure/spec/azure_service_client_spec.rb @@ -36,6 +36,7 @@ module MsRestAzure azure_service_client = AzureServiceClient.new nil azure_service_client.long_running_operation_retry_timeout = 0 + allow_any_instance_of(MsRestAzure::PollingState).to receive(:create_connection).and_return(nil) allow(azure_service_client).to receive(:update_state_from_azure_async_operation_header) do |request, polling_state| polling_state.status = AsyncOperationStatus::SUCCESS_STATUS polling_state.resource = 'resource' @@ -62,6 +63,7 @@ module MsRestAzure azure_service_client = AzureServiceClient.new nil azure_service_client.long_running_operation_retry_timeout = 0 + allow_any_instance_of(MsRestAzure::PollingState).to receive(:create_connection).and_return(nil) allow(azure_service_client).to receive(:update_state_from_location_header) do |request, polling_state| polling_state.status = AsyncOperationStatus::SUCCESS_STATUS polling_state.resource = 'resource' @@ -84,6 +86,7 @@ module MsRestAzure azure_service_client = AzureServiceClient.new nil azure_service_client.long_running_operation_retry_timeout = 0 + allow_any_instance_of(MsRestAzure::PollingState).to receive(:create_connection).and_return(nil) allow(azure_service_client).to receive(:update_state_from_azure_async_operation_header) do |request, polling_state| polling_state.status = AsyncOperationStatus::FAILED_STATUS end diff --git a/ClientRuntimes/Ruby/ms-rest-azure/spec/resource_spec.rb b/ClientRuntimes/Ruby/ms-rest-azure/spec/resource_spec.rb index f02355b1371d9..ba47eb32092b1 100644 --- a/ClientRuntimes/Ruby/ms-rest-azure/spec/resource_spec.rb +++ b/ClientRuntimes/Ruby/ms-rest-azure/spec/resource_spec.rb @@ -31,8 +31,6 @@ class Helper expect(res).to be_a(Hash) expect(res['id']).to eq('id') - expect(res['name']).to eq('name') - expect(res['type']).to eq('type') expect(res['location']).to eq('location') expect(res['tags']).to eq({ 'tag1' => 'tag1_value', 'tag2' => 'tag2_value' }) end diff --git a/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/http_operation_request.rb b/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/http_operation_request.rb index 0a09ffa3e0f63..e4d4d8baf8bc6 100644 --- a/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/http_operation_request.rb +++ b/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/http_operation_request.rb @@ -68,8 +68,8 @@ def initialize(base_uri, path_template, method, options = {}) # @return [URI] body the HTTP response body. def run_promise(&block) Concurrent::Promise.new do - connection = Faraday.new(:url => base_uri) do |faraday| - middlewares.each{ |args| faraday.use(*args) } + @connection ||= Faraday.new(:url => base_uri) do |faraday| + middlewares.each{ |args| faraday.use(*args) } unless middlewares.nil? faraday.adapter Faraday.default_adapter logging = ENV['AZURE_HTTP_LOGGING'] || log if logging @@ -77,7 +77,7 @@ def run_promise(&block) end end - connection.run_request(:"#{method}", build_path, body, {'User-Agent' => user_agent}.merge(headers)) do |req| + @connection.run_request(:"#{method}", build_path, body, {'User-Agent' => user_agent}.merge(headers)) do |req| req.params = query_params.reject{|_, v| v.nil?} unless query_params.nil? yield(req) if block_given? end diff --git a/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/serialization.rb b/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/serialization.rb index a24f02e690ef6..327d2a4f3a377 100644 --- a/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/serialization.rb +++ b/ClientRuntimes/Ruby/ms-rest/lib/ms_rest/serialization.rb @@ -206,6 +206,13 @@ def deserialize_sequence_type(mapper, response_body, object_name) def serialize(mapper, object, object_name) object_name = mapper[:serialized_name] unless object_name.nil? + # Set defaults + unless mapper[:default_value].nil? + object = mapper[:default_value] if object.nil? + end + object = mapper[:default_value] if mapper[:is_constant] + + # Throw if required & non-constant object is nil if mapper[:required] && object.nil? && !mapper[:is_constant] fail ValidationError, "#{object_name} is required and cannot be nil" end @@ -214,12 +221,6 @@ def serialize(mapper, object, object_name) return object end - # Set defaults - unless mapper[:default_value].nil? - object = mapper[:default_value] if object.nil? - end - object = mapper[:default_value] if mapper[:is_constant] - payload = Hash.new mapper_type = mapper[:type][:name] if !mapper_type.match(/^(Number|Double|ByteArray|Boolean|Date|DateTime|DateTimeRfc1123|UnixTime|Enum|String|Object|Stream)$/i).nil? @@ -319,10 +320,15 @@ def serialize_composite_type(mapper, object, object_name) instance_variable.validate end + # Read only properties should not be sent on wire + if !model_props[key][:read_only].nil? && model_props[key][:read_only] + next + end + sub_payload = serialize(value, instance_variable, object_name) unless value[:serialized_name].to_s.include? '.' - payload[value[:serialized_name].to_s] = sub_payload unless instance_variable.nil? + payload[value[:serialized_name].to_s] = sub_payload unless sub_payload.nil? else # Flattened properties will be discovered at higher levels in model class but must be serialized to deeper level in payload levels = split_serialized_name(value[:serialized_name].to_s) diff --git a/gulpfile.js b/gulpfile.js index bd525b9d98d12..496fdd12bc6cd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -88,7 +88,9 @@ var rubyMappings = { 'report':['../../../TestServer/swagger/report.json','ReportModule'], 'model_flattening':['../../../TestServer/swagger/model-flattening.json', 'ModelFlatteningModule'], 'parameter_flattening':['../../../TestServer/swagger/parameter-flattening.json', 'ParameterFlatteningModule'], - 'parameter_grouping':['../../../TestServer/swagger/azure-parameter-grouping.json', 'ParameterGroupingModule'], + 'validation':['../../../TestServer/swagger/validation.json', 'ValidationModule'], + 'custom_base_uri':['../../../TestServer/swagger/custom-baseUrl.json', 'CustomBaseUriModule'], + 'custom_base_uri_more':['../../../TestServer/swagger/custom-baseUrl-more-options.json', 'CustomBaseUriMoreModule'], }; var defaultAzureMappings = { @@ -129,8 +131,7 @@ var rubyAzureMappings = { 'azure_url':['../../../TestServer/swagger/subscriptionId-apiVersion.json', 'AzureUrlModule'], 'azure_special_properties': ['../../../TestServer/swagger/azure-special-properties.json', 'AzureSpecialPropertiesModule'], 'azure_report':['../../../TestServer/swagger/azure-report.json', 'AzureReportModule'], - 'custom_base_uri':['../../../TestServer/swagger/custom-baseUrl.json', 'CustomBaseUriModule'], - 'custom_base_uri_more':['../../../TestServer/swagger/custom-baseUrl-more-options.json', 'CustomBaseUriMoreModule'], + 'parameter_grouping':['../../../TestServer/swagger/azure-parameter-grouping.json', 'ParameterGroupingModule'], }; gulp.task('regenerate:expected', function(cb){