wavefront-client 3.4.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,14 +98,4 @@ describe Wavefront::Events do
98
98
  'key1=val1&key2=val2&h=host1&h=host2&h=host3')
99
99
  end
100
100
  end
101
-
102
- describe '#hash_to_qs' do
103
- it 'makes a proper query string' do
104
- k = Wavefront::Events.new(TEST_TOKEN)
105
- expect(k.hash_to_qs({
106
- key1: 'val1',
107
- key2: 'value 2'
108
- })).to eq('key1=val1&key2=value%202')
109
- end
110
- end
111
101
  end
@@ -1,4 +1,4 @@
1
- =begin
1
+ =begin
2
2
  Copyright 2015 Wavefront Inc.
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -18,6 +18,16 @@ require 'spec_helper'
18
18
  require 'pathname'
19
19
 
20
20
  describe Wavefront::Metadata do
21
+ attr_reader :wf, :host, :path, :post_headers
22
+
23
+ before do
24
+ @wf = Wavefront::Metadata.new(TEST_TOKEN)
25
+ @host = Wavefront::Metadata::DEFAULT_HOST
26
+ @path = Wavefront::Metadata::DEFAULT_PATH
27
+ @post_headers = wf.headers.merge(
28
+ { :'Content-Type' => 'text/plain', :Accept => 'application/json' })
29
+
30
+ end
21
31
 
22
32
  it 'has some defaults' do
23
33
  expect(Wavefront::Metadata::DEFAULT_HOST).to_not be_nil
@@ -34,5 +44,143 @@ describe Wavefront::Metadata do
34
44
  expect(wave.headers).to eq headers
35
45
  end
36
46
  end
37
-
47
+
48
+ describe "#initialize" do
49
+ it 'enables rest-client debugging if instructed to do so' do
50
+ wf = Wavefront::Metadata.new(TEST_TOKEN, 'somehost', true)
51
+ expect RestClient.log == 'stdout'
52
+ end
53
+ end
54
+
55
+ describe '#delete_tags' do
56
+ it 'makes API request with default options' do
57
+ expect(RestClient).to receive(:delete).with(
58
+ concat_url(host, path, 'mysource', 'tags'), wf.headers
59
+ )
60
+ wf.delete_tags('mysource')
61
+ end
62
+
63
+ it 'raises an exception on an invalid source' do
64
+ expect{wf.delete_tags('!INVALID!')}.
65
+ to raise_exception(Wavefront::Exception::InvalidSource)
66
+ end
67
+ end
68
+
69
+ describe '#delete_tag' do
70
+ it 'makes API request with default options' do
71
+ expect(RestClient).to receive(:delete).with(
72
+ concat_url(host, path, 'mysource', 'tags', 'mytag'), wf.headers
73
+ )
74
+ wf.delete_tag('mysource', 'mytag')
75
+ end
76
+
77
+ it 'raises an exception on an invalid source' do
78
+ expect{wf.delete_tag('INVALID!', 'mytag')}.
79
+ to raise_exception(Wavefront::Exception::InvalidSource)
80
+ end
81
+
82
+ it 'raises an exception on an invalid tag' do
83
+ expect{wf.delete_tag('mysource', 'INVALID!')}.
84
+ to raise_exception(Wavefront::Exception::InvalidString)
85
+ end
86
+ end
87
+
88
+ describe '#show_sources' do
89
+ it 'makes API request with default options' do
90
+ expect(RestClient).to receive(:get).with(
91
+ concat_url(host, path, '?'), wf.headers
92
+ )
93
+ wf.show_sources
94
+ end
95
+
96
+ it 'makes API request with options' do
97
+ expect(RestClient).to receive(:get).with(
98
+ concat_url(host, path, '?limit=100&pattern=test-*'), wf.headers
99
+ )
100
+ wf.show_sources({ limit: 100, pattern: 'test-*' })
101
+ end
102
+
103
+ it 'raises an exception on an invalid lastEntityId' do
104
+ expect{wf.show_sources({lastEntityId: nil})}.
105
+ to raise_exception(TypeError)
106
+ end
107
+
108
+ it 'raises an exception on an invalid desc' do
109
+ expect{wf.show_sources({desc: 1234})}.
110
+ to raise_exception(TypeError)
111
+ end
112
+
113
+ it 'raises an exception on an invalid limit' do
114
+ expect{wf.show_sources({limit: 'abcdef'})}.
115
+ to raise_exception(TypeError)
116
+
117
+ expect{wf.show_sources({limit: 10000})}.
118
+ to raise_exception(Wavefront::Exception::ValueOutOfRange)
119
+
120
+ expect{wf.show_sources({limit: -1})}.
121
+ to raise_exception(Wavefront::Exception::ValueOutOfRange)
122
+ end
123
+
124
+ it 'raises an exception on an invalid pattern' do
125
+ expect{wf.show_sources({pattern: [1, 2, 3]})}.
126
+ to raise_exception(TypeError)
127
+ end
128
+ end
129
+
130
+ describe '#show_source' do
131
+ it 'makes API request with default options' do
132
+ expect(RestClient).to receive(:get).with(
133
+ concat_url(host, path, 'mysource'), wf.headers
134
+ )
135
+ wf.show_source('mysource')
136
+ end
137
+
138
+ it 'raises an exception on an invalid source' do
139
+ expect{wf.show_source('!INVALID!')}.
140
+ to raise_exception(Wavefront::Exception::InvalidSource)
141
+ end
142
+ end
143
+
144
+ describe '#set_description' do
145
+ it 'makes API request with default options' do
146
+ expect(RestClient).to receive(:post).with(
147
+ concat_url(host, path, 'mysource', 'description'),
148
+ 'my description', post_headers)
149
+ wf.set_description('mysource', 'my description')
150
+ end
151
+
152
+ it 'raises an exception on an invalid source' do
153
+ expect{wf.set_description('!INVALID!', 'my description')}.
154
+ to raise_exception(Wavefront::Exception::InvalidSource)
155
+ end
156
+
157
+ it 'raises an exception on an invalid description' do
158
+ expect{wf.set_description('my_source', '!INVALID!')}.
159
+ to raise_exception(Wavefront::Exception::InvalidString)
160
+ end
161
+ end
162
+
163
+ describe '#set_tag' do
164
+ it 'makes API request with default options' do
165
+ expect(RestClient).to receive(:post).with(
166
+ concat_url(host, path, 'my_source', 'tags', 'my_tag'),
167
+ nil, post_headers)
168
+ wf.set_tag('my_source', 'my_tag')
169
+ end
170
+
171
+ it 'raises an exception on an invalid source' do
172
+ expect{wf.set_tag('!INVALID!', 'my_tag')}.
173
+ to raise_exception(Wavefront::Exception::InvalidSource)
174
+ end
175
+
176
+ it 'raises an exception on an invalid description' do
177
+ expect{wf.set_tag('my_source', '!INVALID!')}.
178
+ to raise_exception(Wavefront::Exception::InvalidString)
179
+ end
180
+
181
+ it 'raises an exception on an invalid tag' do
182
+ expect{wf.set_tag('my_source', '!INVALID!')}.
183
+ to raise_exception(Wavefront::Exception::InvalidString)
184
+ end
185
+ end
38
186
  end
@@ -41,4 +41,11 @@ describe Wavefront::Mixins do
41
41
  expect(time_to_ms(1469711187)).to eq(1469711187000)
42
42
  expect(time_to_ms('1469711187')).to be(false)
43
43
  end
44
+
45
+ it 'makes a proper query string' do
46
+ expect(hash_to_qs({
47
+ key1: 'val1',
48
+ key2: 'value 2'
49
+ })).to eq('key1=val1&key2=value%202')
50
+ end
44
51
  end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wavefront::Validators do
4
+ include Wavefront::Validators
5
+
6
+ describe '#valid_path?' do
7
+ it 'accepts a-z, 0-9, _ and -' do
8
+ expect(valid_path?('a.l33t.metric_path-passes')).to be(true)
9
+ end
10
+
11
+ it 'accepts nearly very long paths' do
12
+ expect(valid_path?('a' * 1023)).to be(true)
13
+ end
14
+
15
+ it 'rejects very long paths' do
16
+ expect{valid_path?('a' * 1024)}.to raise_exception(
17
+ Wavefront::Exception::InvalidMetricName)
18
+ end
19
+
20
+ it 'rejects upper-case letters' do
21
+ expect{valid_path?('NO.NEED.TO.SHOUT')}.to raise_exception(
22
+ Wavefront::Exception::InvalidMetricName)
23
+ end
24
+
25
+ it 'rejects odd characters' do
26
+ expect{valid_path?('metric.is.(>_<)')}.to raise_exception(
27
+ Wavefront::Exception::InvalidMetricName)
28
+ end
29
+ end
30
+
31
+ describe '#valid_value?' do
32
+ it 'accepts integers' do
33
+ expect(valid_value?(123456)).to be(true)
34
+ end
35
+
36
+ it 'accepts 0' do
37
+ expect(valid_value?(0)).to be(true)
38
+ end
39
+
40
+ it 'accepts negative integers' do
41
+ expect(valid_value?(-10)).to be(true)
42
+ end
43
+
44
+ it 'accepts decimals' do
45
+ expect(valid_value?(1.2345678)).to be(true)
46
+ end
47
+
48
+ it 'accepts exponential notation' do
49
+ expect(valid_value?(1.23e04)).to be(true)
50
+ end
51
+
52
+ it 'rejects strings which look like numbers' do
53
+ expect { valid_value?('1.23')}.to raise_exception(
54
+ Wavefront::Exception::InvalidMetricValue)
55
+ end
56
+ end
57
+
58
+ describe '#valid_ts?' do
59
+ it 'rejects integers' do
60
+ expect { valid_ts?(Time.now.to_i) }.to raise_exception(
61
+ Wavefront::Exception::InvalidTimestamp)
62
+ end
63
+
64
+ it 'accepts Times' do
65
+ expect(valid_ts?(Time.now)).to be(true)
66
+ end
67
+
68
+ it 'accepts DateTimes' do
69
+ expect(valid_ts?(DateTime.now)).to be(true)
70
+ end
71
+
72
+ it 'accepts Dates' do
73
+ expect(valid_ts?(Date.today)).to be(true)
74
+ end
75
+ end
76
+
77
+ describe '#valid_tags?' do
78
+ it 'accepts zero tags' do
79
+ expect(valid_tags?({})).to be(true)
80
+ end
81
+
82
+ it 'accepts nice sensible tags' do
83
+ expect(valid_tags?({tag1: 'val1', tag2: 'val2'})).to be(true)
84
+ end
85
+
86
+ it 'accepts spaces and symbols in values' do
87
+ expect(valid_tags?({tag1: 'val 1', tag2: 'val 2'})).to be(true)
88
+ expect(valid_tags?({tag1: '(>_<)', tag2: '^_^'})).to be(true)
89
+ end
90
+
91
+ it 'rejects spaces and symbols in keys' do
92
+ expect { valid_tags?({'tag 1' => 'val1',
93
+ 'tag 2' => 'val2'}) }.to raise_exception(
94
+ Wavefront::Exception::InvalidTag)
95
+ expect { valid_tags?({'(>_<)' => 'val1',
96
+ '^_^' => 'val2'}) }.to raise_exception(
97
+ Wavefront::Exception::InvalidTag)
98
+ end
99
+
100
+ it 'rejects long keys and/or values' do
101
+ expect { valid_tags?({tag1: 'v' * 255}) }.to raise_exception(
102
+ Wavefront::Exception::InvalidTag)
103
+ expect { valid_tags?({'k' * 255 => 'val1'}) }.to raise_exception(
104
+ Wavefront::Exception::InvalidTag)
105
+ expect { valid_tags?({'k' * 130 => 'v' * 130}) }.to raise_exception(
106
+ Wavefront::Exception::InvalidTag)
107
+ end
108
+ end
109
+ end
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "bundler", "~> 1.3"
38
38
  spec.add_development_dependency "rake"
39
39
  spec.add_development_dependency "rspec", "~> 3.5.0"
40
+ spec.add_development_dependency 'yard', '~> 0.9.5'
40
41
 
41
42
  spec.add_dependency "rest-client", ">= 1.6.7", "< 1.8"
42
43
  spec.add_dependency "docopt", "~> 0.5.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pointer
@@ -13,82 +13,96 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2016-10-19 00:00:00.000000000 Z
16
+ date: 2016-11-07 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - ~>
22
+ - - "~>"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '1.3'
25
25
  type: :development
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - ~>
29
+ - - "~>"
30
30
  - !ruby/object:Gem::Version
31
31
  version: '1.3'
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: rake
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - ! '>='
36
+ - - ">="
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ! '>='
43
+ - - ">="
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - ~>
50
+ - - "~>"
51
51
  - !ruby/object:Gem::Version
52
52
  version: 3.5.0
53
53
  type: :development
54
54
  prerelease: false
55
55
  version_requirements: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ~>
57
+ - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: 3.5.0
60
+ - !ruby/object:Gem::Dependency
61
+ name: yard
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 0.9.5
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 0.9.5
60
74
  - !ruby/object:Gem::Dependency
61
75
  name: rest-client
62
76
  requirement: !ruby/object:Gem::Requirement
63
77
  requirements:
64
- - - ! '>='
78
+ - - ">="
65
79
  - !ruby/object:Gem::Version
66
80
  version: 1.6.7
67
- - - <
81
+ - - "<"
68
82
  - !ruby/object:Gem::Version
69
83
  version: '1.8'
70
84
  type: :runtime
71
85
  prerelease: false
72
86
  version_requirements: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - ! '>='
88
+ - - ">="
75
89
  - !ruby/object:Gem::Version
76
90
  version: 1.6.7
77
- - - <
91
+ - - "<"
78
92
  - !ruby/object:Gem::Version
79
93
  version: '1.8'
80
94
  - !ruby/object:Gem::Dependency
81
95
  name: docopt
82
96
  requirement: !ruby/object:Gem::Requirement
83
97
  requirements:
84
- - - ~>
98
+ - - "~>"
85
99
  - !ruby/object:Gem::Version
86
100
  version: 0.5.0
87
101
  type: :runtime
88
102
  prerelease: false
89
103
  version_requirements: !ruby/object:Gem::Requirement
90
104
  requirements:
91
- - - ~>
105
+ - - "~>"
92
106
  - !ruby/object:Gem::Version
93
107
  version: 0.5.0
94
108
  - !ruby/object:Gem::Dependency
@@ -114,9 +128,9 @@ executables:
114
128
  extensions: []
115
129
  extra_rdoc_files: []
116
130
  files:
117
- - .gitignore
118
- - .ruby-version
119
- - .travis.yml
131
+ - ".gitignore"
132
+ - ".ruby-version"
133
+ - ".travis.yml"
120
134
  - Gemfile
121
135
  - LICENSE
122
136
  - NOTICE
@@ -130,6 +144,7 @@ files:
130
144
  - lib/wavefront/cli/alerts.rb
131
145
  - lib/wavefront/cli/batch_write.rb
132
146
  - lib/wavefront/cli/events.rb
147
+ - lib/wavefront/cli/sources.rb
133
148
  - lib/wavefront/cli/ts.rb
134
149
  - lib/wavefront/cli/write.rb
135
150
  - lib/wavefront/client.rb
@@ -140,6 +155,7 @@ files:
140
155
  - lib/wavefront/metadata.rb
141
156
  - lib/wavefront/mixins.rb
142
157
  - lib/wavefront/response.rb
158
+ - lib/wavefront/validators.rb
143
159
  - lib/wavefront/writer.rb
144
160
  - spec/example_response.json
145
161
  - spec/spec_helper.rb
@@ -154,6 +170,7 @@ files:
154
170
  - spec/wavefront/cli/resources/alert.raw
155
171
  - spec/wavefront/cli/resources/alert.ruby
156
172
  - spec/wavefront/cli/resources/write.parabola
173
+ - spec/wavefront/cli/sources_spec.rb
157
174
  - spec/wavefront/cli/write_spec.rb
158
175
  - spec/wavefront/cli_spec.rb
159
176
  - spec/wavefront/client_spec.rb
@@ -161,6 +178,7 @@ files:
161
178
  - spec/wavefront/metadata_spec.rb
162
179
  - spec/wavefront/mixins_spec.rb
163
180
  - spec/wavefront/response_spec.rb
181
+ - spec/wavefront/validators_spec.rb
164
182
  - spec/wavefront/writer_spec.rb
165
183
  - wavefront-client.gemspec
166
184
  homepage: https://github.com/wavefrontHQ/ruby-client
@@ -173,12 +191,12 @@ require_paths:
173
191
  - lib
174
192
  required_ruby_version: !ruby/object:Gem::Requirement
175
193
  requirements:
176
- - - ! '>='
194
+ - - ">="
177
195
  - !ruby/object:Gem::Version
178
196
  version: 1.9.3
179
197
  required_rubygems_version: !ruby/object:Gem::Requirement
180
198
  requirements:
181
- - - ! '>='
199
+ - - ">="
182
200
  - !ruby/object:Gem::Version
183
201
  version: '0'
184
202
  requirements: []
@@ -201,6 +219,7 @@ test_files:
201
219
  - spec/wavefront/cli/resources/alert.raw
202
220
  - spec/wavefront/cli/resources/alert.ruby
203
221
  - spec/wavefront/cli/resources/write.parabola
222
+ - spec/wavefront/cli/sources_spec.rb
204
223
  - spec/wavefront/cli/write_spec.rb
205
224
  - spec/wavefront/cli_spec.rb
206
225
  - spec/wavefront/client_spec.rb
@@ -208,4 +227,5 @@ test_files:
208
227
  - spec/wavefront/metadata_spec.rb
209
228
  - spec/wavefront/mixins_spec.rb
210
229
  - spec/wavefront/response_spec.rb
230
+ - spec/wavefront/validators_spec.rb
211
231
  - spec/wavefront/writer_spec.rb