-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathconfiguration_spec.rb
More file actions
102 lines (82 loc) · 3.15 KB
/
configuration_spec.rb
File metadata and controls
102 lines (82 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
=begin
#Datadog API V1 Collection
#Collection of all Datadog Public endpoints.
The version of the OpenAPI document: 1.0
Contact: support@datadoghq.com
Generated by: https://openapi-generator.tech
Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2020-Present Datadog, Inc.
=end
require 'spec_helper'
describe DatadogAPIClient::Configuration do
let(:config) { DatadogAPIClient::Configuration.default }
before(:each) do
# uncomment below to setup host and base_path
# require 'URI'
# uri = URI.parse("https://api.datadoghq.com")
# DatadogAPIClient.configure do |c|
# c.host = uri.host
# c.base_path = uri.path
# end
end
describe '#base_url' do
it 'should have the default value' do
# uncomment below to test default value of the base path
# expect(config.base_url).to eq("https://api.datadoghq.com")
end
it 'should remove trailing slashes' do
[nil, '', '/', '//'].each do |base_path|
config.base_path = base_path
# uncomment below to test trailing slashes
# expect(config.base_url).to eq("https://api.datadoghq.com")
end
end
end
describe '#backoff_base' do
context 'when setting a valid backoff_base value > 2' do
it 'sets the backoff_base attribute' do
config.backoff_base = 3
expect(config.backoff_base).to eq(3)
end
end
end
context 'when setting an invalid backoff_base value < 2' do
it 'raises an ArgumentError' do
expect { config.backoff_base = 1 }.to raise_error(ArgumentError, 'backoff_base cannot be smaller than 2')
end
end
describe '#access_token (bearer auth)' do
let(:config) { DatadogAPIClient::Configuration.new }
it 'defaults to nil' do
expect(config.access_token).to be_nil
end
it 'can be set directly' do
config.access_token = 'ddpat_test_token_123'
expect(config.access_token).to eq('ddpat_test_token_123')
end
it 'loads from DD_BEARER_TOKEN environment variable' do
allow(ENV).to receive(:key?).and_call_original
allow(ENV).to receive(:key?).with('DD_BEARER_TOKEN').and_return(true)
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('DD_BEARER_TOKEN').and_return('ddpat_env_token')
new_config = DatadogAPIClient::Configuration.new
expect(new_config.access_token).to eq('ddpat_env_token')
end
end
describe '#auth_settings' do
let(:config) { DatadogAPIClient::Configuration.new }
it 'includes bearerAuth with nil value when token not set' do
expect(config.auth_settings[:bearerAuth]).not_to be_nil
expect(config.auth_settings[:bearerAuth][:value]).to be_nil
end
it 'includes bearerAuth with Bearer token when access_token is set' do
config.access_token = 'ddpat_my_token'
auth = config.auth_settings[:bearerAuth]
expect(auth[:type]).to eq('http')
expect(auth[:in]).to eq('header')
expect(auth[:key]).to eq('Authorization')
expect(auth[:value]).to eq('Bearer ddpat_my_token')
end
end
end