Skip to content
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

fixed test driver for dbaas changes #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions ruby/test_driver.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby


$LOAD_PATH << '.'

require 'json'
Expand All @@ -20,6 +21,16 @@ def underscore_string(str)
.downcase
end

def underscore_keys(hash)
hash.transform_keys! { |key| underscore_string(key.to_s).to_sym}
hash.each_key do
|key|
underscore_keys(hash[key]) if hash[key].is_a?(Hash)
hash[key].each { |el| underscore_keys(el) } if hash[key].is_a?(Array)
end
hash
end

def get_class(operation)
Ionoscloud.constants.select do |c|
Ionoscloud.const_get(c).is_a? Class and Ionoscloud.const_get(c).name.end_with? 'Api'
Expand All @@ -46,15 +57,22 @@ def get_class(operation)

cls = get_class method_name

special_params_names = %w[pretty depth XContractNumber contractNumber offset limit]
special_params_names = %w[pretty depth XContractNumber contractNumber offset limit start end]

normal_params, special_params = testing_data['params'].partition do |el|
normal_params, special_params = testing_data['params'].nil? ? [[], []] : testing_data['params'].partition do |el|
special_params_names.none? do |special_param_name|
special_param_name == el['name']
end
end

normal_params = normal_params.map { |el| el['value'] }
normal_params = normal_params.map do |el|
el['name'][0].capitalize!
begin
Ionoscloud.const_get(el['name']).new._deserialize(el['name'], underscore_keys(el['value']))
rescue NameError
el['value']
end
end

special_params = special_params.each_with_object({}) do |current, total|
total[current['name'].to_sym] = current['value']
Expand All @@ -66,7 +84,10 @@ def get_class(operation)
special_params
)

response = response.to_hash unless response.nil?
begin
response = response.to_hash unless response.nil?
rescue NoMethodError
end

headers = headers.transform_values do |value|
value.split(',', -1)
Expand Down