Skip to content

Commit 5133e9c

Browse files
committed
add tests
1 parent aa40c88 commit 5133e9c

3 files changed

Lines changed: 148 additions & 1 deletion

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ gem 'faraday'
1010

1111
group :test do
1212
gem 'coveralls'
13-
gem 'fakeweb'
1413
gem 'json', '< 2.0' if ruby_version?('< 2.0')
1514
gem 'rack', '< 2.0' if ruby_version?('< 2.2.2')
1615
gem 'rack-test'
@@ -20,4 +19,5 @@ group :test do
2019
gem 'term-ansicolor', '< 1.4' if ruby_version?('< 2.0')
2120
gem 'tins', '< 1.7' if ruby_version?('< 2.0')
2221
gem 'vcr'
22+
gem 'webmock'
2323
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# encoding: UTF-8
2+
3+
require 'prometheus/api_client'
4+
require 'webmock'
5+
require 'vcr'
6+
7+
VCR.configure do |c|
8+
c.cassette_library_dir = 'spec/vcr_cassettes'
9+
c.hook_into :webmock
10+
end
11+
12+
describe Prometheus::ApiClient::Cadvisor do
13+
token = 'topSecret'
14+
url = 'https://prometheus.example.com:443'
15+
instance = 'example.com'
16+
17+
describe 'Node' do
18+
it 'reads metrics' do
19+
VCR.use_cassette('prometheus/api_client/cadvisor_node') do # , record: :new_episodes) do
20+
prometheus = Prometheus::ApiClient::Cadvisor::Node.new(
21+
instance: instance,
22+
url: url,
23+
credentials: { token: token },
24+
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
25+
)
26+
27+
response = prometheus.query(
28+
query: 'sum(container_cpu_usage_seconds_total)',
29+
time: '2017-08-07T06:10:30.781Z',
30+
)
31+
32+
expect(response).to be_a(Hash)
33+
end
34+
end
35+
36+
it 'reads metrics range' do
37+
VCR.use_cassette('prometheus/api_client/cadvisor_node') do # , record: :new_episodes) do
38+
prometheus = Prometheus::ApiClient::Cadvisor::Node.new(
39+
instance: instance,
40+
url: url,
41+
credentials: { token: token },
42+
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
43+
)
44+
45+
response = prometheus.query_range(
46+
query: 'sum(container_cpu_usage_seconds_total)',
47+
start: '2017-08-07T06:10:30.781Z',
48+
end: '2017-08-07T06:14:30.781Z',
49+
step: '120s',
50+
)
51+
52+
expect(response).to be_a(Hash)
53+
end
54+
end
55+
end
56+
end

spec/vcr_cassettes/prometheus/api_client/cadvisor_node.yml

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)