wavefront-sdk 5.4.4 → 7.0.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +3 -3
- data/.github/workflows/test.yml +2 -2
- data/.rubocop.yml +1 -3
- data/HISTORY.md +17 -0
- data/README.md +5 -5
- data/lib/wavefront-sdk/api_mixins/acl.rb +1 -1
- data/lib/wavefront-sdk/core/api.rb +1 -1
- data/lib/wavefront-sdk/core/api_caller.rb +1 -7
- data/lib/wavefront-sdk/core/exception.rb +2 -0
- data/lib/wavefront-sdk/core/response.rb +1 -1
- data/lib/wavefront-sdk/credentials.rb +3 -5
- data/lib/wavefront-sdk/defs/version.rb +1 -1
- data/lib/wavefront-sdk/event.rb +64 -1
- data/lib/wavefront-sdk/maintenancewindow.rb +1 -1
- data/lib/wavefront-sdk/metric.rb +2 -2
- data/lib/wavefront-sdk/metric_helper.rb +1 -1
- data/lib/wavefront-sdk/metricspolicy.rb +57 -0
- data/lib/wavefront-sdk/paginator/base.rb +1 -1
- data/lib/wavefront-sdk/search.rb +3 -3
- data/lib/wavefront-sdk/spy.rb +22 -0
- data/lib/wavefront-sdk/support/mixins.rb +1 -1
- data/lib/wavefront-sdk/support/parse_time.rb +1 -1
- data/lib/wavefront-sdk/user.rb +1 -1
- data/lib/wavefront-sdk/validators.rb +18 -3
- data/lib/wavefront-sdk/write.rb +2 -2
- data/lib/wavefront-sdk/writers/api.rb +1 -1
- data/lib/wavefront-sdk/writers/core.rb +1 -1
- data/lib/wavefront-sdk/writers/proxy.rb +71 -0
- data/lib/wavefront-sdk/writers/socket.rb +15 -27
- data/lib/wavefront_sdk.rb +1 -1
- data/spec/constants.rb +2 -2
- data/spec/test_mixins/general.rb +1 -1
- data/spec/wavefront-sdk/core/api_spec.rb +1 -1
- data/spec/wavefront-sdk/core/response_spec.rb +2 -2
- data/spec/wavefront-sdk/credentials_spec.rb +9 -13
- data/spec/wavefront-sdk/event_spec.rb +46 -0
- data/spec/wavefront-sdk/metric_helper_spec.rb +2 -0
- data/spec/wavefront-sdk/metricspolicy_spec.rb +94 -0
- data/spec/wavefront-sdk/misc_spec.rb +2 -2
- data/spec/wavefront-sdk/savedsearch_spec.rb +2 -2
- data/spec/wavefront-sdk/spy_spec.rb +27 -0
- data/spec/wavefront-sdk/user_spec.rb +2 -2
- data/spec/wavefront-sdk/validators_spec.rb +10 -0
- data/spec/wavefront-sdk/write_spec.rb +1 -1
- data/spec/wavefront-sdk/writers/{unix_spec.rb → proxy_spec.rb} +29 -31
- data/spec/wavefront-sdk/writers/socket_spec.rb +26 -24
- data/wavefront-sdk.gemspec +10 -11
- metadata +27 -97
- data/lib/wavefront-sdk/writers/unix.rb +0 -59
@@ -1,70 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'socket'
|
3
4
|
require_relative 'core'
|
4
5
|
|
5
6
|
module Wavefront
|
6
7
|
module Writer
|
7
8
|
#
|
8
|
-
# Everything specific to writing points to a
|
9
|
-
# native Wavefront format, to a socket. (The original and,
|
10
|
-
# once, only way to send points.)
|
9
|
+
# Everything specific to writing points to a Unix datagram socket.
|
11
10
|
#
|
12
11
|
class Socket < Core
|
13
|
-
#
|
14
|
-
# in instance variable @conn.
|
15
|
-
#
|
12
|
+
# Make a connection to a Unix datagram socket, putting the
|
13
|
+
# descriptor in instance variable @conn.
|
14
|
+
# This requires the name of the socket file in creds[:socket]
|
15
|
+
# @return [UnixSocket]
|
16
16
|
#
|
17
17
|
def open
|
18
18
|
if opts[:noop]
|
19
|
-
logger.log('No-op requested. Not opening connection
|
19
|
+
logger.log('No-op requested. Not opening socket connection.')
|
20
20
|
return true
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
open_socket(creds[:proxy], port)
|
23
|
+
logger.log("Connecting to #{creds[:socket]}.", :debug)
|
24
|
+
open_socket(creds[:socket])
|
26
25
|
end
|
27
26
|
|
28
|
-
# Close the connection described by the @conn instance variable.
|
29
|
-
#
|
30
27
|
def close
|
31
28
|
return if opts[:noop]
|
32
29
|
|
33
|
-
logger.log('Closing connection
|
30
|
+
logger.log('Closing socket connection.', :debug)
|
34
31
|
conn.close
|
35
32
|
end
|
36
33
|
|
37
34
|
def validate_credentials(creds)
|
38
|
-
return if creds.key?(:
|
35
|
+
return true if creds.key?(:socket) && creds[:socket]
|
39
36
|
|
40
37
|
raise(Wavefront::Exception::CredentialError,
|
41
|
-
'credentials must contain
|
38
|
+
'credentials must contain socket file path')
|
42
39
|
end
|
43
40
|
|
44
41
|
private
|
45
42
|
|
46
|
-
def open_socket(
|
47
|
-
@conn =
|
43
|
+
def open_socket(socket)
|
44
|
+
@conn = UNIXSocket.new(socket)
|
48
45
|
rescue StandardError => e
|
49
46
|
logger.log(e, :error)
|
50
47
|
raise Wavefront::Exception::InvalidEndpoint
|
51
48
|
end
|
52
49
|
|
53
50
|
# @param point [String] point or points in native Wavefront format.
|
54
|
-
# @raise [SocketError] if point cannot be written
|
55
51
|
#
|
56
52
|
def _send_point(point)
|
57
53
|
return if opts[:noop]
|
58
54
|
|
59
|
-
conn.
|
60
|
-
rescue StandardError
|
61
|
-
raise Wavefront::Exception::SocketError
|
62
|
-
end
|
63
|
-
|
64
|
-
# return [Integer] the port to connect to, if none is supplied
|
65
|
-
#
|
66
|
-
def default_port
|
67
|
-
2878
|
55
|
+
conn.write(point)
|
68
56
|
end
|
69
57
|
end
|
70
58
|
end
|
data/lib/wavefront_sdk.rb
CHANGED
data/spec/constants.rb
CHANGED
@@ -19,8 +19,8 @@ DUMMY_RESPONSE = '{"status":{"result":"OK","message":"","code":200},' \
|
|
19
19
|
'"response":{"items":[{"name":"test data"}],"offset":0,' \
|
20
20
|
'"limit":100,"totalItems":3,"moreItems":false}}'
|
21
21
|
|
22
|
-
RESOURCE_DIR =
|
23
|
-
|
22
|
+
RESOURCE_DIR = Pathname.new(__FILE__).dirname.join('wavefront-sdk',
|
23
|
+
'resources').freeze
|
24
24
|
|
25
25
|
U_ACL_1 = 'someone@example.com'
|
26
26
|
U_ACL_2 = 'other@elsewhere.com'
|
data/spec/test_mixins/general.rb
CHANGED
@@ -7,8 +7,8 @@ require_relative '../../../lib/wavefront-sdk/core/exception'
|
|
7
7
|
require_relative '../../../lib/wavefront-sdk/core/response'
|
8
8
|
|
9
9
|
GOOD_RESP = '{"status":{"result":"OK","message":"","code":200},' \
|
10
|
-
|
11
|
-
|
10
|
+
'"response":{"items":[{"name":"test agent"}],"offset":0,' \
|
11
|
+
'"limit":100,"totalItems":3,"moreItems":false}}'
|
12
12
|
|
13
13
|
BAD_RESP = "error='not_found'
|
14
14
|
message='resource cannot be found'
|
@@ -5,8 +5,8 @@ require 'pathname'
|
|
5
5
|
require_relative '../spec_helper'
|
6
6
|
require_relative '../../lib/wavefront-sdk/credentials'
|
7
7
|
|
8
|
-
CONF1 = RESOURCE_DIR
|
9
|
-
CONF2 = RESOURCE_DIR
|
8
|
+
CONF1 = RESOURCE_DIR.join('test.conf')
|
9
|
+
CONF2 = RESOURCE_DIR.join('test2.conf')
|
10
10
|
|
11
11
|
# Test SDK base class end-to-end
|
12
12
|
#
|
@@ -60,11 +60,7 @@ end
|
|
60
60
|
# Test individual methods. We must override the constructor to do
|
61
61
|
# this.
|
62
62
|
#
|
63
|
-
|
64
|
-
class Giblets < Wavefront::Credentials
|
65
|
-
def initialize; end
|
66
|
-
end
|
67
|
-
# rubocop:enable Lint/MissingSuper
|
63
|
+
class Giblets < Wavefront::Credentials; end
|
68
64
|
|
69
65
|
# And here are the tests
|
70
66
|
#
|
@@ -119,9 +115,9 @@ class GibletsTest < MiniTest::Test
|
|
119
115
|
|
120
116
|
def test_populate
|
121
117
|
wf.populate(raw)
|
122
|
-
config = wf.instance_variable_get(
|
123
|
-
creds = wf.instance_variable_get(
|
124
|
-
proxy = wf.instance_variable_get(
|
118
|
+
config = wf.instance_variable_get(:@config)
|
119
|
+
creds = wf.instance_variable_get(:@creds)
|
120
|
+
proxy = wf.instance_variable_get(:@proxy)
|
125
121
|
|
126
122
|
assert_instance_of(Map, config)
|
127
123
|
assert_equal('raw_proxy', config.proxy)
|
@@ -143,8 +139,8 @@ class GibletsTest < MiniTest::Test
|
|
143
139
|
assert_equal(3, x.length)
|
144
140
|
x.each { |p| assert_instance_of(Pathname, p) }
|
145
141
|
assert_includes(x, Pathname.new('/etc/wavefront/credentials'))
|
146
|
-
assert_includes(x, Pathname.new(
|
147
|
-
assert_includes(x, Pathname.new(
|
142
|
+
assert_includes(x, Pathname.new(Dir.home).join('.wavefront'))
|
143
|
+
assert_includes(x, Pathname.new(Dir.home).join('.wavefront.conf'))
|
148
144
|
end
|
149
145
|
|
150
146
|
def test_cred_files_opts
|
@@ -197,7 +193,7 @@ class GibletsTest < MiniTest::Test
|
|
197
193
|
end
|
198
194
|
|
199
195
|
assert_raises Wavefront::Exception::InvalidConfigFile do
|
200
|
-
wf.load_profile(RESOURCE_DIR
|
196
|
+
wf.load_profile(RESOURCE_DIR.join('malformed.conf'))
|
201
197
|
end
|
202
198
|
end
|
203
199
|
end
|
@@ -43,12 +43,58 @@ class WavefrontEventTest < WavefrontTestBase
|
|
43
43
|
assert_raises(ArgumentError) { wf.close }
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_alert_firing_details
|
47
|
+
assert_gets("/api/v2/event/#{id}/alertFiringDetails") do
|
48
|
+
wf.alert_firing_details(id)
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_raises(Wavefront::Exception::InvalidEventId) do
|
52
|
+
wf.alert_firing_details(invalid_id)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_alert_queries_slug
|
57
|
+
assert_gets("/api/v2/event/#{id}/alertQueriesSlug") do
|
58
|
+
wf.alert_queries_slug(id)
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_raises(Wavefront::Exception::InvalidEventId) do
|
62
|
+
wf.alert_queries_slug(invalid_id)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_events
|
67
|
+
assert_gets(
|
68
|
+
"/api/v2/event/#{id}/events?isOverlapped=false&renderingMethod=HOST"
|
69
|
+
) do
|
70
|
+
wf.events(id)
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_raises(Wavefront::Exception::InvalidEventId) do
|
74
|
+
wf.events(invalid_id)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_alert_firings
|
79
|
+
assert_gets("/api/v2/event/alertFirings?alertId=#{alert_id}&asc=true") do
|
80
|
+
wf.alert_firings(alert_id, asc: true)
|
81
|
+
end
|
82
|
+
|
83
|
+
assert_raises(Wavefront::Exception::InvalidAlertId) do
|
84
|
+
wf.alert_firings(invalid_id)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
46
88
|
private
|
47
89
|
|
48
90
|
def id
|
49
91
|
'1481553823153:testev'
|
50
92
|
end
|
51
93
|
|
94
|
+
def alert_id
|
95
|
+
'1481553823153'
|
96
|
+
end
|
97
|
+
|
52
98
|
def invalid_id
|
53
99
|
'nonsense'
|
54
100
|
end
|
@@ -4,6 +4,8 @@
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
require_relative '../spec_helper'
|
6
6
|
require_relative '../../lib/wavefront-sdk/metric_helper'
|
7
|
+
require_relative '../support/mocket'
|
8
|
+
require_relative '../support/bad_mocket'
|
7
9
|
|
8
10
|
ND_CREDS = { proxy: 'wavefront' }.freeze
|
9
11
|
WH_TAGS = { t1: 'v1', t2: 'v2' }.freeze
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../spec_helper'
|
5
|
+
require_relative '../test_mixins/general'
|
6
|
+
|
7
|
+
# Unit tests for MetricsPolicy class
|
8
|
+
#
|
9
|
+
class WavefrontMetricsPolicyTest < WavefrontTestBase
|
10
|
+
def test_describe
|
11
|
+
assert_gets('/api/v2/metricspolicy') { wf.describe }
|
12
|
+
|
13
|
+
assert_gets('/api/v2/metricspolicy/history/5') { wf.describe(5) }
|
14
|
+
|
15
|
+
assert_raises(Wavefront::Exception::InvalidVersion) do
|
16
|
+
wf.describe('v5')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_history
|
21
|
+
assert_gets('/api/v2/metricspolicy/history?offset=10&limit=100') do
|
22
|
+
wf.history(10)
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_gets('/api/v2/metricspolicy/history?offset=12&limit=34') do
|
26
|
+
wf.history(12, 34)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_revert
|
31
|
+
assert_posts('/api/v2/metricspolicy/revert/5', nil, :json) do
|
32
|
+
wf.revert(5)
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_raises(Wavefront::Exception::InvalidVersion) do
|
36
|
+
wf.revert('v5')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_update
|
41
|
+
assert_puts('/api/v2/metricspolicy', payload.to_json) do
|
42
|
+
wf.update(payload)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def api_class
|
49
|
+
'metricspolicy'
|
50
|
+
end
|
51
|
+
|
52
|
+
def id
|
53
|
+
'a7d2e651-cec1-4154-a5e8-1946f57ef5b3'
|
54
|
+
end
|
55
|
+
|
56
|
+
def invalid_id
|
57
|
+
'+-+-+-+'
|
58
|
+
end
|
59
|
+
|
60
|
+
def payload
|
61
|
+
{
|
62
|
+
policyRules: [
|
63
|
+
{
|
64
|
+
name: 'Policy rule1 name',
|
65
|
+
description: 'Policy rule1 description',
|
66
|
+
prefixes: ['revenue.*'],
|
67
|
+
tags: [
|
68
|
+
{
|
69
|
+
key: 'sensitive',
|
70
|
+
value: 'false'
|
71
|
+
},
|
72
|
+
{
|
73
|
+
key: 'source',
|
74
|
+
value: 'app1'
|
75
|
+
}
|
76
|
+
],
|
77
|
+
tagsAnded: 'true',
|
78
|
+
accessType: 'ALLOW',
|
79
|
+
accounts: %w[accountId1 accountId2],
|
80
|
+
userGroups: ['userGroupId1'],
|
81
|
+
roles: ['roleId']
|
82
|
+
},
|
83
|
+
{
|
84
|
+
name: 'Policy rule2 name',
|
85
|
+
description: 'Policy rule2 description',
|
86
|
+
prefixes: ['revenue.*'],
|
87
|
+
accessType: 'BLOCK',
|
88
|
+
accounts: ['accountId3'],
|
89
|
+
userGroups: ['userGroupId1']
|
90
|
+
}
|
91
|
+
]
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|
@@ -11,8 +11,8 @@ class WavefrontMiscTest < MiniTest::Test
|
|
11
11
|
# defines itself as.
|
12
12
|
#
|
13
13
|
def test_version_vs_history
|
14
|
-
history_file = WF_SDK_LOCATION
|
15
|
-
history_vers =
|
14
|
+
history_file = WF_SDK_LOCATION.join('HISTORY.md')
|
15
|
+
history_vers = File.read(history_file).match(/^## (\d+\.\d+\.\d+) \(/)
|
16
16
|
assert_equal(WF_SDK_VERSION, history_vers.captures.first)
|
17
17
|
end
|
18
18
|
end
|
@@ -54,8 +54,8 @@ class WavefrontSavedSearchTest < WavefrontTestBase
|
|
54
54
|
|
55
55
|
def payload
|
56
56
|
{ query: {
|
57
|
-
|
58
|
-
|
57
|
+
foo: '{"searchTerms":[{"type":"freetext","value":"foo"}]}'
|
58
|
+
},
|
59
59
|
entityType: 'DASHBOARD' }
|
60
60
|
end
|
61
61
|
end
|
@@ -38,6 +38,33 @@ class WavefrontSpyTest < MiniTest::Test
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_deltas
|
42
|
+
capture_io do
|
43
|
+
assert_gets('/api/spy/deltas?sampling=0.01') { wf.deltas }
|
44
|
+
assert_gets('/api/spy/deltas?sampling=0.05') { wf.deltas(0.05) }
|
45
|
+
|
46
|
+
assert_gets('/api/spy/deltas?sampling=0.05&counter=my_prefix') do
|
47
|
+
wf.deltas(0.05, prefix: 'my_prefix')
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_gets(
|
51
|
+
'/api/spy/deltas?sampling=0.05&counter=my_prefix&host=h1'
|
52
|
+
) do
|
53
|
+
wf.deltas(0.05, prefix: 'my_prefix', host: 'h1')
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_gets('/api/spy/deltas?sampling=0.02&counter=my_prefix&' \
|
57
|
+
'counterTagKey=the_tag') do
|
58
|
+
wf.deltas(0.02, prefix: 'my_prefix', tag_key: 'the_tag')
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_gets('/api/spy/deltas?sampling=0.02&counter=my_prefix&' \
|
62
|
+
'counterTagKey=tag1&counterTagKey=tag2') do
|
63
|
+
wf.deltas(0.02, prefix: 'my_prefix', tag_key: %w[tag1 tag2])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
41
68
|
def test_histograms
|
42
69
|
capture_io do
|
43
70
|
assert_gets('/api/spy/histograms?sampling=0.01') { wf.histograms }
|
@@ -127,10 +127,10 @@ class WavefrontUserTest < WavefrontTestBase
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_response_shim
|
130
|
-
(
|
130
|
+
RESOURCE_DIR.join('user_responses').each_child do |input|
|
131
131
|
# Ugly hack for the 202 in the 'create' file
|
132
132
|
status = input.basename.to_s == 'create.json' ? 202 : 200
|
133
|
-
shimmed = wf.response_shim(
|
133
|
+
shimmed = wf.response_shim(File.read(input), status)
|
134
134
|
assert_instance_of(String, shimmed)
|
135
135
|
|
136
136
|
ret_obj = JSON.parse(shimmed, symbolize_names: true)
|
@@ -417,4 +417,14 @@ class WavefrontValidatorsTest < MiniTest::Test
|
|
417
417
|
bad = %w[h5Z9dkr46jbvLtJ HqOM4mru5svd3uFp3 c!lBx!LC*NxLKdx*]
|
418
418
|
good_and_bad('wf_aws_external_id?', 'InvalidAwsExternalId', good, bad)
|
419
419
|
end
|
420
|
+
|
421
|
+
def test_wf_metricspolicy_id
|
422
|
+
good = %w[2bfdcac7-1c9c-4c4b-9b56-c41c22c586dc
|
423
|
+
a7d2e651-cec1-4154-a5e8-1946f57ef5b3
|
424
|
+
fca312fb-5ff4-420d-862d-5d6d99ed6bcf
|
425
|
+
3a1957e0-459e-49e5-9209-3888a4e8ac5b]
|
426
|
+
|
427
|
+
bad = %w[fa312fb-5ff4-420d-862d-5d6d99ed6bcf thing 123]
|
428
|
+
good_and_bad('wf_metricspolicy_id?', 'InvalidMetricsPolicyId', good, bad)
|
429
|
+
end
|
420
430
|
end
|
@@ -27,7 +27,7 @@ class WavefrontWriteTest < MiniTest::Test
|
|
27
27
|
refute(wf.opts[:noop])
|
28
28
|
assert(wf_noop.opts[:noop])
|
29
29
|
assert_equal(wf_tags.opts[:tags], TAGS)
|
30
|
-
assert_instance_of(Wavefront::Writer::
|
30
|
+
assert_instance_of(Wavefront::Writer::Proxy, wf.writer)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_composite_response
|
@@ -11,36 +11,34 @@ require_relative '../../spec_helper'
|
|
11
11
|
require_relative '../../../lib/wavefront-sdk/write'
|
12
12
|
require_relative '../../../spec/support/mocket'
|
13
13
|
|
14
|
-
|
14
|
+
WS_CREDS = { proxy: 'wavefront-proxy' }.freeze
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
# Test UNIX Datagram socket writing
|
16
|
+
# The Proxy class writes to a proxy TCP socket
|
19
17
|
#
|
20
|
-
class
|
18
|
+
class WavefrontWriterSocketTest < MiniTest::Test
|
21
19
|
attr_reader :wf, :wf_noop
|
22
20
|
|
23
21
|
def setup
|
24
|
-
@wf = Wavefront::Write.new(
|
25
|
-
@wf_noop = Wavefront::Write.new(
|
22
|
+
@wf = Wavefront::Write.new(WS_CREDS, writer: :proxy)
|
23
|
+
@wf_noop = Wavefront::Write.new(WS_CREDS, writer: :proxy, noop: true)
|
26
24
|
end
|
27
25
|
|
28
26
|
def test_writer_class
|
29
|
-
assert_instance_of(Wavefront::Writer::
|
27
|
+
assert_instance_of(Wavefront::Writer::Proxy, wf.writer)
|
30
28
|
end
|
31
29
|
|
32
30
|
def test_write_openclose
|
33
31
|
mocket = Mocket.new
|
34
|
-
Spy.on(
|
35
|
-
mocket_spy = Spy.on(mocket, :
|
32
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
33
|
+
mocket_spy = Spy.on(mocket, :puts)
|
36
34
|
wf.write(POINT)
|
37
35
|
assert mocket_spy.has_been_called?
|
38
36
|
end
|
39
37
|
|
40
38
|
def test_write_noop
|
41
39
|
mocket = Mocket.new
|
42
|
-
Spy.on(
|
43
|
-
mocket_spy = Spy.on(mocket, :
|
40
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
41
|
+
mocket_spy = Spy.on(mocket, :puts)
|
44
42
|
wf_noop.open
|
45
43
|
wf_noop.write(POINT, false)
|
46
44
|
refute mocket_spy.has_been_called?
|
@@ -48,16 +46,16 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
48
46
|
|
49
47
|
def test_write_noop_openclose
|
50
48
|
mocket = Mocket.new
|
51
|
-
Spy.on(
|
52
|
-
mocket_spy = Spy.on(mocket, :
|
49
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
50
|
+
mocket_spy = Spy.on(mocket, :puts)
|
53
51
|
wf_noop.write(POINT)
|
54
52
|
refute mocket_spy.has_been_called?
|
55
53
|
end
|
56
54
|
|
57
55
|
def test_write
|
58
56
|
mocket = Mocket.new
|
59
|
-
Spy.on(
|
60
|
-
mocket_spy = Spy.on(mocket, :
|
57
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
58
|
+
mocket_spy = Spy.on(mocket, :puts)
|
61
59
|
wf.open
|
62
60
|
wf.write(POINT, false)
|
63
61
|
assert mocket_spy.has_been_called?
|
@@ -65,8 +63,8 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
65
63
|
|
66
64
|
def test_write_array
|
67
65
|
mocket = Mocket.new
|
68
|
-
Spy.on(
|
69
|
-
mocket_spy = Spy.on(mocket, :
|
66
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
67
|
+
mocket_spy = Spy.on(mocket, :puts)
|
70
68
|
wf.open
|
71
69
|
wf.write(POINT_A, false)
|
72
70
|
assert mocket_spy.has_been_called?
|
@@ -74,32 +72,32 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
74
72
|
|
75
73
|
def test_noop_send_point
|
76
74
|
mocket = Mocket.new
|
77
|
-
Spy.on(
|
78
|
-
mocket_spy = Spy.on(mocket, :
|
75
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
76
|
+
mocket_spy = Spy.on(mocket, :puts)
|
79
77
|
wf_noop.open
|
80
78
|
wf_noop.send_point(POINT_L)
|
81
79
|
refute mocket_spy.has_been_called?
|
82
80
|
end
|
83
81
|
|
84
82
|
def test_open
|
85
|
-
tcp_spy = Spy.on(
|
83
|
+
tcp_spy = Spy.on(TCPSocket, :new)
|
86
84
|
wf.open
|
87
85
|
assert tcp_spy.has_been_called?
|
88
|
-
assert_equal([
|
86
|
+
assert_equal(['wavefront-proxy', 2878], tcp_spy.calls.first.args)
|
89
87
|
end
|
90
88
|
|
91
89
|
def test_noop_open
|
92
|
-
tcp_spy = Spy.on(
|
90
|
+
tcp_spy = Spy.on(TCPSocket, :new)
|
93
91
|
log_spy = Spy.on(wf_noop.logger, :log)
|
94
92
|
wf_noop.open
|
95
93
|
refute tcp_spy.has_been_called?
|
96
|
-
assert_equal(['No-op requested. Not opening
|
94
|
+
assert_equal(['No-op requested. Not opening connection to proxy.'],
|
97
95
|
log_spy.calls.last.args)
|
98
96
|
assert_equal(1, log_spy.calls.size)
|
99
97
|
end
|
100
98
|
|
101
99
|
def test_noop_close
|
102
|
-
tcp_spy = Spy.on(
|
100
|
+
tcp_spy = Spy.on(TCPSocket, :new)
|
103
101
|
log_spy = Spy.on(wf_noop.logger, :log)
|
104
102
|
wf_noop.close
|
105
103
|
refute tcp_spy.has_been_called?
|
@@ -107,25 +105,25 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
107
105
|
end
|
108
106
|
|
109
107
|
def test_validate_credentials
|
110
|
-
assert(Wavefront::Write.new(
|
108
|
+
assert(Wavefront::Write.new(WS_CREDS, writer: :proxy))
|
111
109
|
|
112
110
|
assert_instance_of(Wavefront::Write,
|
113
|
-
Wavefront::Write.new(
|
111
|
+
Wavefront::Write.new(WS_CREDS, writer: :proxy))
|
114
112
|
|
115
113
|
assert_raises(Wavefront::Exception::CredentialError) do
|
116
|
-
Wavefront::Write.new({}, writer: :
|
114
|
+
Wavefront::Write.new({}, writer: :proxy)
|
117
115
|
end
|
118
116
|
|
119
117
|
assert_raises(Wavefront::Exception::CredentialError) do
|
120
|
-
Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :
|
118
|
+
Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :proxy)
|
121
119
|
end
|
122
120
|
|
123
121
|
assert_raises(Wavefront::Exception::CredentialError) do
|
124
|
-
Wavefront::Write.new({ token: 'abcdef' }, writer: :
|
122
|
+
Wavefront::Write.new({ token: 'abcdef' }, writer: :proxy)
|
125
123
|
end
|
126
124
|
|
127
125
|
assert_raises(Wavefront::Exception::CredentialError) do
|
128
|
-
Wavefront::Write.new({ proxy: nil }, writer: :
|
126
|
+
Wavefront::Write.new({ proxy: nil }, writer: :proxy)
|
129
127
|
end
|
130
128
|
end
|
131
129
|
end
|