All Files
(90.17%
covered at
4.02
hits/line)
6 files in total.
346 relevant lines.
312 lines covered and
34 lines missed
-
# Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
-
# SPDX-License-Identifier: MIT
-
-
# DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
-
-
# runtime - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
-
-
-
# Common files
-
1
require 'vsphere-automation-runtime/api_client'
-
1
require 'vsphere-automation-runtime/api_error'
-
1
require 'vsphere-automation-runtime/configuration'
-
1
require 'vsphere-automation-runtime/version'
-
-
# Models
-
-
# APIs
-
-
1
module VSphereAutomation
-
1
class << self
-
# Customize default settings for the SDK using block.
-
# VSphereAutomation.configure do |config|
-
# config.username = "xxx"
-
# config.password = "xxx"
-
# end
-
# If no block given, return the default Configuration object.
-
1
def configure
-
if block_given?
-
yield(Configuration.default)
-
else
-
Configuration.default
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require 'json'
-
1
require 'logger'
-
1
require 'net/http'
-
1
require 'openssl'
-
1
require 'uri'
-
1
require 'vsphere-automation-runtime/configuration'
-
1
require 'vsphere-automation-runtime/version'
-
-
1
module VSphereAutomation
-
# The client responsible for communicating with the API.
-
1
class ApiClient
-
# The Configuration object holding settings to be used in the API client.
-
1
attr_accessor :config
-
-
# Defines the headers to be used in HTTP requests of all API calls by
-
# default.
-
#
-
# @return [Hash]
-
1
attr_reader :default_headers
-
-
# Creates a new instance
-
#
-
# @param config [Configuration] configuration object with values to use
-
1
def initialize(config = Configuration.default)
-
21
@config = config
-
21
@http = create_http
-
21
@user_agent = default_user_agent
-
21
@default_headers = { 'Content-Type' => 'application/json',
-
'User-Agent' => @user_agent }
-
end
-
-
# Retrieves an instance of the object in it's default state
-
#
-
# @return [ApiClient] an instance of the object in it's default state
-
1
def self.default
-
3
DEFAULT
-
end
-
-
# Build the collection of parameters
-
1
def build_collection_param(params, format)
-
1
params
-
end
-
-
# Make a request to an API endpoint with the given options
-
#
-
# @param http_method [Symbol] the HTTP method to be used
-
# @param path [String] the path request will be made to
-
# @param opts [Hash] any additional options needed
-
# @return [Array<(Object, Fixnum, Hash)>] the deserialized body, status
-
# code, and headers.
-
1
def call_api(http_method, path, opts = {})
-
11
query_params = opts.fetch(:query_params, {})
-
11
header_params = opts.fetch(:header_params, {})
-
11
form_params = opts.fetch(:form_params, {})
-
11
add_auth(query_params, header_params, opts.fetch(:auth_names, []))
-
-
11
uri = build_request_uri(path, query_params)
-
11
request = Net::HTTP.const_get(http_method.capitalize).new(uri)
-
-
11
add_form_params(request, form_params)
-
11
add_header_params(request, header_params)
-
11
request.body = opts[:body] if opts[:body]
-
11
request.content_type = request['Content-Type'] if request['Content-Type']
-
-
11
if @config.debugging
-
@config.logger.debug("Request Body:\n#{request.body}\n")
-
end
-
-
11
response = @http.request(request)
-
11
@cookie = cookie_from_response(response)
-
11
api_key_from_response(response)
-
-
11
return_type = opts.fetch(:return_type, {}).fetch(response.code, nil)
-
11
data = deserialize(response, return_type)
-
11
[data, Integer(response.code), response.each_header.to_h]
-
end
-
-
# Takes an object and returns the object as an HTTP body
-
#
-
# @param object [Object] object to transform
-
# @return [String] object as JSON string
-
1
def object_to_http_body(object)
-
6
return object.map { |o| object_to_http_body(o) } if object.is_a?(Array)
-
-
4
return object unless object.respond_to?(:to_hash)
-
-
2
object.to_hash.to_json
-
end
-
-
# Select an Accept header to use
-
#
-
# @param types [Array] a list of suggested types
-
# @return [String] the Accept header value
-
1
def select_header_accept(types)
-
5
return DEFAULT_MIME_TYPE unless types.is_a?(Array)
-
-
6
types.find { |t| t.include?('json') } || types.join(', ')
-
end
-
-
# Select an Content-Type header to use
-
#
-
# @param types [Array] a list of suggested types
-
# @return [String] the Content-Type header value
-
1
def select_header_content_type(types)
-
5
return DEFAULT_MIME_TYPE unless types.is_a?(Array)
-
-
6
types.find { |t| t.include?('json') } || types.first
-
end
-
-
1
private
-
-
1
def add_auth(query_params, header_params, auth_names)
-
11
auth_names.map do |name|
-
4
settings = @config.auth_settings.fetch(name, {})
-
4
case settings[:in]
-
when 'header'
-
4
header_params[settings[:key]] = settings[:value]
-
4
api_key_from_cookie(header_params, settings) unless settings[:value]
-
when 'query'
-
query_params[settings[:key]] = settings[:value]
-
end
-
end
-
end
-
-
1
def add_form_params(request, form_params)
-
11
request.set_form_data(form_params) unless form_params.empty?
-
end
-
-
1
def add_header_params(request, headers)
-
11
header_params = @default_headers.merge(headers, Hash(@cookie))
-
39
header_params.map { |name, value| request[name] = value }
-
end
-
-
1
def add_query_params(uri, query_params)
-
32
uri.query = URI.encode_www_form(query_params)
-
end
-
-
1
def build_request_uri(path = '', query_params = {})
-
32
path = "/#{path}".gsub(%r{/+}, '/')
-
32
uri = URI.parse(@config.base_url + path)
-
32
add_query_params(uri, query_params)
-
32
uri
-
end
-
-
1
def create_http
-
21
uri = build_request_uri
-
21
http = Net::HTTP.new(uri.host, uri.port)
-
21
http.use_ssl = @config.scheme == 'https'
-
21
http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @config.verify_ssl_host
-
21
http
-
end
-
-
# The default user agent
-
#
-
# @return [String] the default user agent
-
1
def default_user_agent
-
21
"SDK/#{VSphereAutomation::Runtime::VERSION} "\
-
"Ruby/#{RUBY_VERSION} "\
-
"(#{Gem::Platform.local.os}; "\
-
"#{Gem::Platform.local.version}; "\
-
"#{Gem::Platform.local.cpu})"
-
end
-
-
# Deserialize the response to the given return type
-
#
-
# @param [Response] response the HTTP response
-
# @param [String] return_type the type to return
-
# @return [Object] the response represented as the return type
-
1
def deserialize(response, return_type)
-
11
body = response.body
-
-
11
return nil if body.nil? || body.empty? || return_type.nil?
-
-
begin
-
data = JSON.parse("[#{body}]", symbolize_names: true).first
-
rescue JSON::ParserError => e
-
raise e unless %w[String Date DateTime].include?(return_type)
-
-
data = body
-
end
-
-
convert_to_type(data, return_type)
-
end
-
-
1
def convert_to_type(data, return_type)
-
return nil if data.nil?
-
case return_type
-
when 'String'
-
data.to_s
-
when 'Integer'
-
data.to_i
-
when 'Float'
-
data.to_f
-
when 'BOOLEAN'
-
data == true
-
when 'DateTime'
-
# parse date time (expecting ISO 8601 format)
-
DateTime.parse data
-
when 'Date'
-
# parse date time (expecting ISO 8601 format)
-
Date.parse data
-
when 'Object'
-
# generic object (usually a Hash), return directly
-
data
-
when /\AArray<(.+)>\z/
-
# e.g. Array<Pet>
-
sub_type = $1
-
data.map { |item| convert_to_type(item, sub_type) }
-
when /\AHash\<String, (.+)\>\z/
-
# e.g. Hash<String, Integer>
-
sub_type = $1
-
{}.tap do |hash|
-
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
-
end
-
else
-
# models, e.g. Pet
-
VSphereAutomation.const_get(return_type).new.tap do |model|
-
model.build_from_hash data
-
end
-
end
-
end
-
-
# Create the Cookie header from a response
-
#
-
# @param response [Net::HTTPResponse] the response
-
# @return [Hash, nil] the Cookie header
-
1
def cookie_from_response(response)
-
11
{ 'Cookie' => response['set-cookie'] } if response['set-cookie']
-
end
-
-
1
def api_key_from_response(response)
-
11
key = @config.auth_settings['api_key'][:key]
-
11
@config.api_key[key] = response[key] if response[key]
-
end
-
-
1
def api_key_from_cookie(headers, auth)
-
1
return if @cookie.nil?
-
-
1
regex = /(?<key>#{auth[:key]})=(?<value>\w+)/
-
1
matches = Hash(@cookie)['Cookie'].match(regex)
-
1
headers[matches[:key]] = matches[:value] if matches
-
end
-
-
# An instance of the object in it's default state
-
1
DEFAULT = new
-
-
# The default MIME type for Content-Type and Accept headers
-
1
DEFAULT_MIME_TYPE = 'application/json'
-
-
1
private_constant :DEFAULT, :DEFAULT_MIME_TYPE
-
end
-
end
-
# Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
-
# SPDX-License-Identifier: MIT
-
-
# DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
-
-
# runtime - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
-
-
-
1
module VSphereAutomation
-
1
class ApiError < StandardError
-
1
attr_reader :code, :response_headers, :response_body
-
-
# Usage examples:
-
# ApiError.new
-
# ApiError.new("message")
-
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
-
# ApiError.new(:code => 404, :message => "Not Found")
-
1
def initialize(arg = nil)
-
if arg.is_a? Hash
-
if arg.key?(:message) || arg.key?('message')
-
super(arg[:message] || arg['message'])
-
else
-
super arg
-
end
-
-
arg.each do |k, v|
-
instance_variable_set "@#{k}", v
-
end
-
else
-
super arg
-
end
-
end
-
end
-
end
-
# Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
-
# SPDX-License-Identifier: MIT
-
-
# DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
-
-
# runtime - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
-
-
-
1
require 'uri'
-
-
1
module VSphereAutomation
-
1
class Configuration
-
# Defines url scheme
-
1
attr_accessor :scheme
-
-
# Defines url host
-
1
attr_accessor :host
-
-
# Defines url base path
-
1
attr_accessor :base_path
-
-
# Defines API keys used with API Key authentications.
-
#
-
# @return [Hash] key: parameter name, value: parameter value (API key)
-
#
-
# @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
-
# config.api_key['api_key'] = 'xxx'
-
1
attr_accessor :api_key
-
-
# Defines API key prefixes used with API Key authentications.
-
#
-
# @return [Hash] key: parameter name, value: API key prefix
-
#
-
# @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
-
# config.api_key_prefix['api_key'] = 'Token'
-
1
attr_accessor :api_key_prefix
-
-
# Defines the username used with HTTP basic authentication.
-
#
-
# @return [String]
-
1
attr_accessor :username
-
-
# Defines the password used with HTTP basic authentication.
-
#
-
# @return [String]
-
1
attr_accessor :password
-
-
# Defines the access token (Bearer) used with OAuth2.
-
1
attr_accessor :access_token
-
-
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
-
# details will be logged with `logger.debug` (see the `logger` attribute).
-
# Default to false.
-
#
-
# @return [true, false]
-
1
attr_accessor :debugging
-
-
# Defines the logger used for debugging.
-
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
-
#
-
# @return [#debug]
-
1
attr_accessor :logger
-
-
# Defines the temporary folder to store downloaded files
-
# (for API endpoints that have file response).
-
# Default to use `Tempfile`.
-
#
-
# @return [String]
-
1
attr_accessor :temp_folder_path
-
-
# The time limit for HTTP request in seconds.
-
# Default to 0 (never times out).
-
1
attr_accessor :timeout
-
-
# Set this to false to skip client side validation in the operation.
-
# Default to true.
-
# @return [true, false]
-
1
attr_accessor :client_side_validation
-
-
### TLS/SSL setting
-
# Set this to false to skip verifying SSL certificate when calling API from https server.
-
# Default to true.
-
#
-
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
-
#
-
# @return [true, false]
-
1
attr_accessor :verify_ssl
-
-
### TLS/SSL setting
-
# Set this to false to skip verifying SSL host name
-
# Default to true.
-
#
-
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
-
#
-
# @return [true, false]
-
1
attr_accessor :verify_ssl_host
-
-
### TLS/SSL setting
-
# Set this to customize the certificate file to verify the peer.
-
#
-
# @return [String] the path to the certificate file
-
#
-
# @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
-
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
-
1
attr_accessor :ssl_ca_cert
-
-
### TLS/SSL setting
-
# Client certificate file (for client certificate)
-
1
attr_accessor :cert_file
-
-
### TLS/SSL setting
-
# Client private key file (for client certificate)
-
1
attr_accessor :key_file
-
-
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
-
# Default to nil.
-
#
-
# @see The params_encoding option of Ethon. Related source code:
-
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
-
1
attr_accessor :params_encoding
-
-
1
attr_accessor :inject_format
-
-
1
attr_accessor :force_ending_format
-
-
1
def initialize
-
10
@scheme = 'https'
-
10
@host = '<vcenter>'
-
10
@base_path = '/rest'
-
10
@api_key = {}
-
10
@api_key_prefix = {}
-
10
@timeout = 0
-
10
@client_side_validation = true
-
10
@verify_ssl = true
-
10
@verify_ssl_host = true
-
10
@params_encoding = :multi
-
10
@cert_file = nil
-
10
@key_file = nil
-
10
@debugging = false
-
10
@inject_format = false
-
10
@force_ending_format = false
-
10
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
-
-
10
yield(self) if block_given?
-
end
-
-
# The default Configuration object.
-
1
def self.default
-
13
@@default ||= Configuration.new
-
end
-
-
1
def configure
-
yield(self) if block_given?
-
end
-
-
1
def scheme=(scheme)
-
# remove :// from scheme
-
9
@scheme = scheme.sub(/:\/\//, '')
-
end
-
-
1
def host=(host)
-
# remove http(s):// and anything after a slash
-
9
@host = host.sub(/https?:\/\//, '').split('/').first
-
end
-
-
1
def base_path=(base_path)
-
# Add leading and trailing slashes to base_path
-
4
@base_path = "/#{base_path}".gsub(/\/+/, '/')
-
4
@base_path = '' if @base_path == '/'
-
end
-
-
1
def base_url
-
32
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
-
32
URI.encode(url)
-
end
-
-
# Gets API key (with prefix if set).
-
# @param [String] param_name the parameter name of API key auth
-
1
def api_key_with_prefix(param_name)
-
22
if @api_key_prefix[param_name]
-
"#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
-
else
-
22
@api_key[param_name]
-
end
-
end
-
-
# Gets Basic Auth token string
-
1
def basic_auth_token
-
22
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
-
end
-
-
# Returns Auth Settings hash for api client.
-
1
def auth_settings
-
{
-
22
'api_key' =>
-
{
-
type: 'api_key',
-
in: 'header',
-
key: 'vmware-api-session-id',
-
value: api_key_with_prefix('vmware-api-session-id')
-
},
-
'basic_auth' =>
-
{
-
type: 'basic',
-
in: 'header',
-
key: 'Authorization',
-
value: basic_auth_token
-
},
-
}
-
end
-
end
-
end
-
1
require 'spec_helper'
-
-
1
describe VSphereAutomation::ApiClient do
-
1
describe '.default' do
-
1
it 'returns the same instance every time' do
-
1
first_instance = VSphereAutomation::ApiClient.default
-
1
second_instance = VSphereAutomation::ApiClient.default
-
1
third_instance = VSphereAutomation::ApiClient.default
-
1
expect(first_instance).to be(second_instance)
-
1
expect(first_instance).to be(third_instance)
-
end
-
end
-
-
1
describe '#build_collection_param' do
-
1
context 'when called with format :multi' do
-
1
it 'returns the collection' do
-
1
params = { foo: 'bar', baz: 'quux' }
-
1
expect(subject.build_collection_param(params, :multi)).to eq(params)
-
end
-
end
-
end
-
-
1
describe '#call_api' do
-
10
let(:host) { 'example.com' }
-
1
let(:config) do
-
9
VSphereAutomation::Configuration.new.tap do |c|
-
9
c.scheme = 'https'
-
9
c.host = host
-
end
-
end
-
10
let(:url) { 'https://example.com/rest/test' }
-
10
subject { VSphereAutomation::ApiClient.new(config) }
-
-
1
it 'adds headers to request' do
-
1
headers = { 'foo' => 'bar' }
-
1
stub_request(:get, url).with(headers: headers)
-
-
1
subject.call_api(:GET, '/test', header_params: headers)
-
-
1
expect(a_request(:get, url).with(headers: headers)).to have_been_made
-
end
-
-
1
it 'adds query parameters to request' do
-
1
query_params = { 'foo' => 'bar' }
-
1
stub_request(:get, url).with(query: query_params)
-
-
1
subject.call_api(:GET, '/test', query_params: query_params)
-
-
1
expect(a_request(:get, url).with(query: query_params)).to have_been_made
-
end
-
-
1
it 'adds form parameters to the request body' do
-
1
form_params = { 'foo' => 'bar' }
-
2
body = form_params.to_a.map { |e| e.join('=') }.join('&')
-
1
stub_request(:get, url).with(body: body)
-
-
1
subject.call_api(:GET, '/test', form_params: form_params)
-
-
1
expect(a_request(:get, url).with(body: body)).to have_been_made
-
end
-
-
1
it 'uses basic auth information from configuration' do
-
1
auth_name = 'basic_auth'
-
1
auth_header = { config.auth_settings[auth_name][:key] =>
-
config.auth_settings[auth_name][:value] }
-
1
stub_request(:get, url).with(headers: auth_header)
-
-
1
subject.call_api(:GET, '/test', auth_names: [auth_name])
-
-
1
expect(a_request(:get, url)
-
.with(headers: auth_header)).to have_been_made
-
end
-
-
1
it 'use API key information from configuration' do
-
1
auth_name = 'api_key'
-
1
config.api_key[config.auth_settings[auth_name][:key]] = 'foo'
-
1
auth_header = { config.auth_settings[auth_name][:key] =>
-
config.auth_settings[auth_name][:value] }
-
1
stub_request(:get, url).with(headers: auth_header)
-
-
1
subject.call_api(:GET, '/test', auth_names: [auth_name])
-
-
1
expect(a_request(:get, url)
-
.with(headers: auth_header)).to have_been_made
-
end
-
-
1
it 'updates api_key from responses with set-cookie header' do
-
1
key = config.auth_settings['api_key'][:key]
-
1
value = 'foo'
-
1
cookie = "#{key}=#{value};Path=/rest;Secure;HttpOnly"
-
1
set_cookie_header = { 'set-cookie' => cookie }
-
1
auth_header = { key => value }
-
1
stub_request(:get, url + '1').to_return(headers: set_cookie_header)
-
1
stub_request(:get, url + '2').with(headers: auth_header)
-
-
1
subject.call_api(:GET, '/test1')
-
1
subject.call_api(:GET, '/test2', auth_names: ['api_key'])
-
-
1
expect(a_request(:get, url + '1')).to have_been_made
-
1
expect(a_request(:get, url + '2')
-
.with(headers: auth_header)).to have_been_made
-
end
-
-
1
it 'updates api_key from responses with api_key header' do
-
1
key = config.auth_settings['api_key'][:key]
-
1
value = 'foo'
-
1
auth_header = { key => value }
-
-
1
stub_request(:get, url + '1').to_return(headers: auth_header)
-
1
stub_request(:get, url + '2').with(headers: auth_header)
-
-
1
subject.call_api(:GET, '/test1')
-
1
subject.call_api(:GET, '/test2', auth_names: ['api_key'])
-
-
1
expect(a_request(:get, url + '1')).to have_been_made
-
1
expect(a_request(:get, url + '2')
-
.with(headers: auth_header)).to have_been_made
-
end
-
-
1
it 'adds the body to requests when available' do
-
1
body = { foo: 'bar' }.to_json
-
1
stub_request(:post, url).with(body: body)
-
-
1
subject.call_api(:POST, '/test', body: body)
-
-
1
expect(a_request(:post, url).with(body: body)).to have_been_made
-
end
-
-
1
it 'sets the Content-Type on requests when available' do
-
1
content_type = { 'Content-Type' => 'application/json' }
-
1
body = { foo: 'bar' }.to_json
-
-
1
stub_request(:post, url).with(body: body, headers: content_type)
-
-
1
subject.call_api(:POST, '/test', body: body, header_params: content_type)
-
-
1
expect(a_request(:post, url)
-
.with(body: body, headers: content_type)).to have_been_made
-
end
-
end
-
-
1
describe '#object_to_http_body' do
-
1
context 'when given nil' do
-
1
it 'returns the object as is' do
-
1
expect(subject.object_to_http_body(nil)).to be_nil
-
end
-
end
-
-
1
context 'when given a string' do
-
1
it 'returns the object as is' do
-
1
expect(subject.object_to_http_body('asdf')).to eq('asdf')
-
end
-
end
-
-
1
context 'when given an object that responds to `to_hash`' do
-
1
it 'returns that object as JSON' do
-
1
obj = OpenStruct.new(foo: 'bar', baz: 'quux')
-
1
obj.to_hash = obj.to_h
-
1
json = obj.to_hash.to_json
-
-
1
expect(subject.object_to_http_body(obj)).to eq(json)
-
end
-
end
-
-
1
context 'when given an array' do
-
1
it 'returns a JSON array of objects' do
-
1
obj = OpenStruct.new(foo: 'bar', baz: 'quux')
-
1
obj.to_hash = obj.to_h
-
1
json = obj.to_hash.to_json
-
-
1
expect(subject.object_to_http_body([obj])).to eq([json])
-
end
-
end
-
end
-
-
1
describe '#select_header_accept' do
-
1
context 'when given anything other than an array' do
-
1
it 'returns application/json as a default' do
-
1
expect(subject.select_header_accept(nil)).to eq('application/json')
-
1
expect(subject.select_header_accept('')).to eq('application/json')
-
1
expect(subject.select_header_accept(1)).to eq('application/json')
-
end
-
end
-
-
1
context 'when given a list of types' do
-
1
context 'that includes a JSON type' do
-
1
it 'returns the first type containing JSON' do
-
1
xml = 'application/xml'
-
1
json = 'application/json'
-
-
1
expect(subject.select_header_accept([xml, json])).to eq(json)
-
end
-
end
-
-
1
context 'that does not include a JSON type' do
-
1
it 'returns the all of the types' do
-
1
xml = 'application/xml'
-
1
html = 'text/html'
-
1
result = [xml, html].join(', ')
-
-
1
expect(subject.select_header_accept([xml, html])).to eq(result)
-
end
-
end
-
end
-
end
-
-
1
describe '#select_header_content_type' do
-
1
context 'when given anything other than an array' do
-
1
it 'returns application/json as a default' do
-
1
expect(subject.select_header_content_type(nil)).to eq('application/json')
-
1
expect(subject.select_header_content_type('')).to eq('application/json')
-
1
expect(subject.select_header_content_type(1)).to eq('application/json')
-
end
-
end
-
-
1
context 'when given a list of types' do
-
1
context 'that includes a JSON type' do
-
1
it 'returns the first type containing JSON' do
-
1
xml = 'application/xml'
-
1
json = 'application/json'
-
-
1
expect(subject.select_header_content_type([xml, json])).to eq(json)
-
end
-
end
-
-
1
context 'that does not include a JSON type' do
-
1
it 'returns the first type' do
-
1
xml = 'application/xml'
-
1
html = 'text/html'
-
-
1
expect(subject.select_header_content_type([xml, html])).to eq(xml)
-
end
-
end
-
end
-
end
-
end
-
# Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
-
# SPDX-License-Identifier: MIT
-
-
# DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
-
-
# runtime - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
-
-
-
1
require 'spec_helper'
-
-
1
describe VSphereAutomation::Configuration do
-
2
let(:config) { VSphereAutomation::Configuration.default }
-
-
1
before(:each) do
-
# uncomment below to setup host and base_path
-
# require 'URI'
-
# uri = URI.parse("https://<vcenter>/rest")
-
# VSphereAutomation.configure do |c|
-
# c.host = uri.host
-
# c.base_path = uri.path
-
# end
-
end
-
-
1
describe '#base_url' do
-
1
it 'should have the default value' do
-
# uncomment below to test default value of the base path
-
# expect(config.base_url).to eq("https://<vcenter>/rest")
-
end
-
-
1
it 'should remove trailing slashes' do
-
1
[nil, '', '/', '//'].each do |base_path|
-
4
config.base_path = base_path
-
# uncomment below to test trailing slashes
-
# expect(config.base_url).to eq("https://<vcenter>/rest")
-
end
-
end
-
end
-
end