wavefront-sdk 3.3.2 → 3.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +42 -35
  3. data/README.md +5 -5
  4. data/lib/wavefront-sdk/alert.rb +2 -0
  5. data/lib/wavefront-sdk/core/api_caller.rb +6 -3
  6. data/lib/wavefront-sdk/defs/version.rb +2 -2
  7. data/lib/wavefront-sdk/derivedmetric.rb +7 -0
  8. data/lib/wavefront-sdk/externallink.rb +2 -2
  9. data/lib/wavefront-sdk/maintenancewindow.rb +6 -2
  10. data/lib/wavefront-sdk/notificant.rb +7 -0
  11. data/lib/wavefront-sdk/paginator/base.rb +8 -0
  12. data/lib/wavefront-sdk/search.rb +11 -2
  13. data/lib/wavefront-sdk/user.rb +39 -8
  14. data/lib/wavefront-sdk/webhook.rb +1 -1
  15. data/spec/constants.rb +30 -0
  16. data/spec/spec_helper.rb +12 -237
  17. data/spec/support/bad_mocket.rb +15 -0
  18. data/spec/support/hash.rb +9 -0
  19. data/spec/support/minitest_assertions.rb +110 -0
  20. data/spec/support/mocket.rb +19 -0
  21. data/spec/test_mixins/acl.rb +78 -0
  22. data/spec/test_mixins/general.rb +120 -0
  23. data/spec/test_mixins/tag.rb +55 -0
  24. data/spec/test_mixins/update_keys.rb +11 -0
  25. data/spec/wavefront-sdk/alert_spec.rb +88 -136
  26. data/spec/wavefront-sdk/apitoken_spec.rb +26 -13
  27. data/spec/wavefront-sdk/cloudintegration_spec.rb +42 -44
  28. data/spec/wavefront-sdk/dashboard_spec.rb +53 -72
  29. data/spec/wavefront-sdk/derivedmetric_spec.rb +23 -49
  30. data/spec/wavefront-sdk/distribution_spec.rb +14 -14
  31. data/spec/wavefront-sdk/event_spec.rb +39 -48
  32. data/spec/wavefront-sdk/externallink_spec.rb +19 -50
  33. data/spec/wavefront-sdk/integration_spec.rb +33 -38
  34. data/spec/wavefront-sdk/maintenancewindow_spec.rb +18 -33
  35. data/spec/wavefront-sdk/message_spec.rb +19 -4
  36. data/spec/wavefront-sdk/metric_spec.rb +13 -9
  37. data/spec/wavefront-sdk/notificant_spec.rb +16 -15
  38. data/spec/wavefront-sdk/proxy_spec.rb +20 -25
  39. data/spec/wavefront-sdk/query_spec.rb +50 -24
  40. data/spec/wavefront-sdk/report_spec.rb +3 -6
  41. data/spec/wavefront-sdk/resources/user_responses/add_user_groups.json +1 -0
  42. data/spec/wavefront-sdk/resources/user_responses/create.json +28 -0
  43. data/spec/wavefront-sdk/resources/user_responses/delete_multiple.json +1 -0
  44. data/spec/wavefront-sdk/resources/user_responses/describe.json +1 -0
  45. data/spec/wavefront-sdk/resources/user_responses/grant.json +1 -0
  46. data/spec/wavefront-sdk/resources/user_responses/list.json +1 -0
  47. data/spec/wavefront-sdk/savedsearch_spec.rb +41 -35
  48. data/spec/wavefront-sdk/search_spec.rb +35 -29
  49. data/spec/wavefront-sdk/settings_spec.rb +18 -12
  50. data/spec/wavefront-sdk/source_spec.rb +29 -32
  51. data/spec/wavefront-sdk/user_spec.rb +101 -74
  52. data/spec/wavefront-sdk/usergroup_spec.rb +56 -67
  53. data/spec/wavefront-sdk/webhook_spec.rb +22 -34
  54. data/spec/wavefront-sdk/write_spec.rb +2 -0
  55. data/spec/wavefront-sdk/writers/core_spec.rb +2 -0
  56. data/spec/wavefront-sdk/writers/summary_spec.rb +2 -0
  57. data/wavefront-sdk.gemspec +5 -5
  58. metadata +44 -13
@@ -1,31 +1,44 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- API_TOKEN_ID = '17db4cc1-65f6-40a8-a1fa-6fcae460c4bd'.freeze
4
+ require_relative '../test_mixins/general'
6
5
 
7
6
  # Unit tests for API token class
8
7
  #
9
8
  class WavefrontApiTokenTest < WavefrontTestBase
9
+ include WavefrontTest::Delete
10
+
10
11
  def test_list
11
- should_work(:list, [], '')
12
+ assert_gets('/api/v2/apitoken') { wf.list }
12
13
  end
13
14
 
14
15
  def test_create
15
- should_work(:create, [], '', :post, JSON_POST_HEADERS, nil)
16
+ assert_posts('/api/v2/apitoken', 'null') { wf.create }
16
17
  assert_raises(ArgumentError) { wf.create('test') }
17
18
  end
18
19
 
19
- def test_delete
20
- should_work(:delete, API_TOKEN_ID, API_TOKEN_ID, :delete)
21
- should_be_invalid(:delete)
22
- end
23
-
24
20
  def test_rename
25
- should_work(:rename, [API_TOKEN_ID, 'token name'],
26
- API_TOKEN_ID, :put, JSON_POST_HEADERS,
27
- { tokenID: API_TOKEN_ID, tokenName: 'token name' }.to_json)
28
- should_be_invalid(:rename, ['!invalid token!', 'token name'])
21
+ assert_puts("/api/v2/apitoken/#{id}",
22
+ tokenID: id, tokenName: 'token name') do
23
+ wf.rename(id, 'token name')
24
+ end
25
+
26
+ assert_invalid_id { wf.rename(invalid_id, 'token name') }
29
27
  assert_raises(ArgumentError) { wf.rename }
28
+ assert_raises(ArgumentError) { wf.rename(id) }
29
+ end
30
+
31
+ private
32
+
33
+ def id
34
+ '17db4cc1-65f6-40a8-a1fa-6fcae460c4bd'
35
+ end
36
+
37
+ def invalid_id
38
+ '__rubbish__'
39
+ end
40
+
41
+ def api_class
42
+ 'apitoken'
30
43
  end
31
44
  end
@@ -1,66 +1,64 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- CLOUD = '3b56f61d-1a79-46f6-905c-d75a0f613d10'.freeze
6
- CLOUD_BODY = {
7
- name: 'SDK test Cloudwatch Integration',
8
- service: 'CLOUDWATCH',
9
- cloudWatch: {
10
- baseCredentials: {
11
- roleArn: 'arn:aws:iam::<accountid>:role/<rolename>',
12
- externalId: 'wave123'
13
- }
14
- },
15
- metricFilterRegex: '^aws.(sqs|ec2|ebs|elb).*$'
16
- }.freeze
4
+ require_relative '../test_mixins/general'
17
5
 
18
6
  # Unit tests for CloudIntegration class
19
7
  #
20
8
  class WavefrontCloudIntegrationTest < WavefrontTestBase
21
- def test_list
22
- should_work(:list, 10, '?offset=10&limit=100')
23
- end
9
+ include WavefrontTest::List
10
+ include WavefrontTest::Create
11
+ include WavefrontTest::Describe
12
+ include WavefrontTest::Update
13
+ include WavefrontTest::DeleteUndelete
14
+
15
+ def test_update
16
+ assert_puts("/api/v2/cloudintegration/#{id}", payload) do
17
+ wf.update(id, payload)
18
+ end
24
19
 
25
- def test_create
26
- should_work(:create, CLOUD_BODY, '', :post, JSON_POST_HEADERS,
27
- CLOUD_BODY.to_json)
28
- assert_raises(ArgumentError) { wf.create }
29
- assert_raises(ArgumentError) { wf.create('test') }
20
+ assert_invalid_id { wf.update(invalid_id, payload) }
21
+ assert_raises(ArgumentError) { wf.update }
30
22
  end
31
23
 
32
- def test_delete
33
- should_work(:delete, CLOUD, CLOUD, :delete)
34
- should_be_invalid(:delete)
24
+ def test_enable
25
+ assert_posts("/api/v2/cloudintegration/#{id}/enable") { wf.enable(id) }
26
+ assert_invalid_id { wf.enable(invalid_id) }
27
+ assert_raises(ArgumentError) { wf.enable }
35
28
  end
36
29
 
37
- def test_describe
38
- should_work(:describe, CLOUD, CLOUD)
39
- should_be_invalid(:describe)
30
+ def test_disable
31
+ assert_posts("/api/v2/cloudintegration/#{id}/disable") do
32
+ wf.disable(id)
33
+ end
34
+
35
+ assert_invalid_id { wf.disable(invalid_id) }
36
+ assert_raises(ArgumentError) { wf.disable }
40
37
  end
41
38
 
42
- def test_update
43
- should_work(:update, [CLOUD, CLOUD_BODY], CLOUD, :put,
44
- JSON_POST_HEADERS, CLOUD_BODY.to_json)
45
- should_be_invalid(:update, ['abcde', CLOUD_BODY])
46
- assert_raises(ArgumentError) { wf.update }
39
+ private
40
+
41
+ def id
42
+ '3b56f61d-1a79-46f6-905c-d75a0f613d10'
47
43
  end
48
44
 
49
- def test_undelete
50
- should_work(:undelete, CLOUD, ["#{CLOUD}/undelete", nil], :post,
51
- POST_HEADERS)
52
- should_be_invalid(:undelete)
45
+ def invalid_id
46
+ '__rubbish__'
53
47
  end
54
48
 
55
- def test_disable
56
- should_work(:disable, CLOUD, ["#{CLOUD}/disable", nil], :post,
57
- POST_HEADERS)
58
- should_be_invalid(:disable)
49
+ def payload
50
+ { name: 'SDK test Cloudwatch Integration',
51
+ service: 'CLOUDWATCH',
52
+ cloudWatch: {
53
+ baseCredentials: {
54
+ roleArn: 'arn:aws:iam::<accountid>:role/<rolename>',
55
+ externalId: 'wave123'
56
+ }
57
+ },
58
+ metricFilterRegex: '^aws.(sqs|ec2|ebs|elb).*$' }
59
59
  end
60
60
 
61
- def test_enable
62
- should_work(:enable, CLOUD, ["#{CLOUD}/enable", nil], :post,
63
- POST_HEADERS)
64
- should_be_invalid(:enable)
61
+ def api_class
62
+ 'cloudintegration'
65
63
  end
66
64
  end
@@ -1,95 +1,76 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- DASHBOARD = 'test_dashboard'.freeze
6
- DASHBOARD_BODY = {
7
- name: 'SDK Dashboard test',
8
- id: 'sdk-test',
9
- description: 'dummy test dashboard',
10
- sections: [
11
- name: 'Section 1',
12
- rows: [
13
- { charts: [
14
- name: 'S1 Chart1',
15
- description: 'chart',
16
- sources: [
17
- { name: 'S1 C1 Source 1',
18
- query: 'ts("some.series")' }
19
- ]
20
- ] }
21
- ]
22
- ]
23
- }.freeze
4
+ require_relative '../test_mixins/acl'
5
+ require_relative '../test_mixins/tag'
6
+ require_relative '../test_mixins/update_keys'
7
+ require_relative '../test_mixins/general'
24
8
 
25
9
  # Unit tests for dashboard class
26
10
  #
27
11
  class WavefrontDashboardTest < WavefrontTestBase
28
- def test_list
29
- should_work(:list, 10, '?offset=10&limit=100')
30
- end
12
+ include WavefrontTest::Acl
13
+ include WavefrontTest::Create
14
+ include WavefrontTest::DeleteUndelete
15
+ include WavefrontTest::Describe
16
+ include WavefrontTest::History
17
+ include WavefrontTest::List
18
+ include WavefrontTest::Tag
19
+ include WavefrontTest::Update
20
+ include WavefrontTest::UpdateKeys
31
21
 
32
- def test_create
33
- should_work(:create, DASHBOARD_BODY, '', :post,
34
- JSON_POST_HEADERS, DASHBOARD_BODY.to_json)
35
- assert_raises(ArgumentError) { wf.create }
36
- assert_raises(ArgumentError) { wf.create('test') }
37
- end
38
-
39
- def test_describe
40
- should_work(:describe, DASHBOARD, DASHBOARD)
41
- assert_raises(ArgumentError) { wf.describe }
42
- end
43
-
44
- def test_describe_v
45
- should_work(:describe, [DASHBOARD, 4], "#{DASHBOARD}/history/4")
22
+ def test_favorite
23
+ assert_posts("/api/v2/dashboard/#{id}/favorite") { wf.favorite(id) }
24
+ assert_invalid_id { wf.favorite(invalid_id) }
25
+ assert_raises(ArgumentError) { wf.favorite }
26
+ assert_posts("/api/v2/dashboard/#{id}/favorite") { wf.favourite(id) }
27
+ assert_invalid_id { wf.favourite(invalid_id) }
28
+ assert_raises(ArgumentError) { wf.favourite }
46
29
  end
47
30
 
48
- def test_delete
49
- should_work(:delete, DASHBOARD, DASHBOARD, :delete)
50
- should_be_invalid(:delete)
51
- end
31
+ def test_unfavorite
32
+ assert_posts("/api/v2/dashboard/#{id}/unfavorite") { wf.unfavorite(id) }
33
+ assert_invalid_id { wf.unfavorite(invalid_id) }
34
+ assert_raises(ArgumentError) { wf.unfavorite }
52
35
 
53
- def test_update
54
- should_work(:update, [DASHBOARD, DASHBOARD_BODY, false],
55
- DASHBOARD, :put, JSON_POST_HEADERS,
56
- DASHBOARD_BODY.to_json)
57
- should_be_invalid(:update, ['!invalid dash!', DASHBOARD_BODY])
58
- assert_raises(ArgumentError) { wf.update }
59
- end
36
+ assert_posts("/api/v2/dashboard/#{id}/unfavorite") do
37
+ wf.unfavourite(id)
38
+ end
60
39
 
61
- def test_favorite
62
- should_work(:favorite, DASHBOARD, ["#{DASHBOARD}/favorite",
63
- nil], :post, POST_HEADERS)
64
- should_work(:favourite, DASHBOARD, ["#{DASHBOARD}/favorite",
65
- nil], :post, POST_HEADERS)
66
- should_be_invalid(:favorite)
40
+ assert_invalid_id { wf.unfavourite(invalid_id) }
41
+ assert_raises(ArgumentError) { wf.unfavourite }
67
42
  end
68
43
 
69
- def test_history
70
- should_work(:history, DASHBOARD, "#{DASHBOARD}/history")
71
- should_be_invalid(:history)
72
- end
44
+ private
73
45
 
74
- def test_tags
75
- tag_tester(DASHBOARD)
46
+ def api_class
47
+ 'dashboard'
76
48
  end
77
49
 
78
- def test_acls
79
- acl_tester(DASHBOARD)
50
+ def id
51
+ 'test_dashboard'
80
52
  end
81
53
 
82
- def test_undelete
83
- should_work(:undelete, DASHBOARD, ["#{DASHBOARD}/undelete",
84
- nil], :post, POST_HEADERS)
85
- should_be_invalid(:undelete)
54
+ def invalid_id
55
+ 'a bad dashboard name'
86
56
  end
87
57
 
88
- def test_unfavorite
89
- should_work(:unfavorite, DASHBOARD, ["#{DASHBOARD}/unfavorite",
90
- nil], :post, POST_HEADERS)
91
- should_work(:unfavourite, DASHBOARD, ["#{DASHBOARD}/unfavorite",
92
- nil], :post, POST_HEADERS)
93
- should_be_invalid(:unfavorite)
58
+ def payload
59
+ { name: 'SDK Dashboard test',
60
+ id: 'sdk-test',
61
+ description: 'dummy test dashboard',
62
+ sections: [
63
+ name: 'Section 1',
64
+ rows: [
65
+ { charts: [
66
+ name: 'S1 Chart1',
67
+ description: 'chart',
68
+ sources: [
69
+ { name: 'S1 C1 Source 1',
70
+ query: 'ts("some.series")' }
71
+ ]
72
+ ] }
73
+ ]
74
+ ] }
94
75
  end
95
76
  end
@@ -1,66 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- DERIVED_METRIC = '1529926075038'.freeze
6
- DERIVED_METRIC_BODY = {
7
- minutes: 5,
8
- name: 'test_1',
9
- query: 'aliasMetric(ts("test.metric"), "derived.test_1")',
10
- tags: { customerTags: ['test'] },
11
- includeObsoleteMetrics: false,
12
- processRateMinutes: 1
13
- }.freeze
4
+ require_relative '../test_mixins/general'
5
+ require_relative '../test_mixins/tag'
14
6
 
15
7
  # Unit tests for derived metric class
16
8
  #
17
9
  class WavefrontDerivedMetricTest < WavefrontTestBase
18
- def test_list
19
- should_work(:list, 10, '?offset=10&limit=100')
20
- end
10
+ include WavefrontTest::Create
11
+ include WavefrontTest::DeleteUndelete
12
+ include WavefrontTest::Describe
13
+ include WavefrontTest::History
14
+ include WavefrontTest::List
15
+ include WavefrontTest::Tag
16
+ include WavefrontTest::Update
21
17
 
22
- def test_create
23
- should_work(:create, DERIVED_METRIC_BODY, '', :post,
24
- JSON_POST_HEADERS, DERIVED_METRIC_BODY.to_json)
25
- assert_raises(ArgumentError) { wf.create }
26
- assert_raises(ArgumentError) { wf.create('test') }
27
- end
28
-
29
- def test_describe
30
- should_work(:describe, DERIVED_METRIC, DERIVED_METRIC)
31
- assert_raises(ArgumentError) { wf.describe }
32
- end
33
-
34
- def test_describe_v
35
- should_work(:describe, [DERIVED_METRIC, 4], "#{DERIVED_METRIC}/history/4")
36
- end
37
-
38
- def test_delete
39
- should_work(:delete, DERIVED_METRIC, DERIVED_METRIC, :delete)
40
- should_be_invalid(:delete)
41
- end
18
+ private
42
19
 
43
- def test_history
44
- should_work(:history, DERIVED_METRIC, "#{DERIVED_METRIC}/history")
45
- should_be_invalid(:history)
20
+ def id
21
+ '1529926075038'
46
22
  end
47
23
 
48
- def test_update
49
- should_work(:update, [DERIVED_METRIC, DERIVED_METRIC_BODY, false],
50
- DERIVED_METRIC, :put, JSON_POST_HEADERS,
51
- DERIVED_METRIC_BODY.to_json)
52
- should_be_invalid(:update, ['!invalid derived metric!',
53
- DERIVED_METRIC_BODY])
54
- assert_raises(ArgumentError) { wf.update }
24
+ def invalid_id
25
+ '! invalid derived metric !'
55
26
  end
56
27
 
57
- def test_tags
58
- tag_tester(DERIVED_METRIC)
28
+ def payload
29
+ { minutes: 5,
30
+ name: 'test_1',
31
+ query: 'aliasMetric(ts("test.metric"), "derived.test_1")',
32
+ tags: { customerTags: ['test'] },
33
+ includeObsoleteMetrics: false,
34
+ processRateMinutes: 1 }
59
35
  end
60
36
 
61
- def test_undelete
62
- should_work(:undelete, DERIVED_METRIC, ["#{DERIVED_METRIC}/undelete",
63
- nil], :post, POST_HEADERS)
64
- should_be_invalid(:undelete)
37
+ def api_class
38
+ 'derivedmetric'
65
39
  end
66
40
  end
@@ -3,20 +3,11 @@
3
3
  require_relative '../spec_helper'
4
4
  require_relative '../../lib/wavefront-sdk/distribution'
5
5
 
6
- DIST = {
7
- interval: :m,
8
- path: 'test.distribution',
9
- value: [[5, 11], [15, 2.533], [8, -15], [12, 1e6]],
10
- ts: 1_538_865_613,
11
- source: 'minitest',
12
- tags: { tag1: 'val1', tag2: 'val2' }
13
- }.freeze
14
-
15
6
  # Most of the distribution methods are inherited from the Write
16
7
  # class so they aren't tested again here.
17
8
  #
18
9
  class WavefrontDistributionTest < MiniTest::Test
19
- attr_reader :wf, :wf_noop, :wf_tags
10
+ attr_reader :wf
20
11
 
21
12
  def setup
22
13
  @wf = Wavefront::Distribution.new(W_CREDS)
@@ -39,19 +30,19 @@ class WavefrontDistributionTest < MiniTest::Test
39
30
  end
40
31
 
41
32
  def test_hash_to_wf
42
- assert_equal(wf.hash_to_wf(DIST),
33
+ assert_equal(wf.hash_to_wf(distribution),
43
34
  '!M 1538865613 #5 11 #15 2.533 #8 -15 #12 1000000.0 ' \
44
35
  'test.distribution source=minitest ' \
45
36
  'tag1="val1" tag2="val2"')
46
37
 
47
- d2 = DIST.dup
38
+ d2 = distribution.dup
48
39
  d2[:tags] = {}
49
40
 
50
41
  assert_equal(wf.hash_to_wf(d2),
51
42
  '!M 1538865613 #5 11 #15 2.533 #8 -15 #12 1000000.0 ' \
52
43
  'test.distribution source=minitest')
53
44
 
54
- d3 = DIST.dup
45
+ d3 = distribution.dup
55
46
  d3[:ts] = Time.at(1_538_865_613)
56
47
  d3 = d3.tap { |d| d.delete(:source) }
57
48
 
@@ -60,7 +51,7 @@ class WavefrontDistributionTest < MiniTest::Test
60
51
  "test.distribution source=#{Socket.gethostname} " \
61
52
  'tag1="val1" tag2="val2"')
62
53
 
63
- bad_dist = DIST.dup
54
+ bad_dist = distribution.dup
64
55
  bad_dist.delete(:interval)
65
56
 
66
57
  assert_raises(Wavefront::Exception::InvalidDistribution) do
@@ -72,4 +63,13 @@ class WavefrontDistributionTest < MiniTest::Test
72
63
  assert_equal(wf.array2dist([[1, 4], [6, 5]]), '#1 4 #6 5')
73
64
  assert_equal(wf.array2dist([[12, 4.235]]), '#12 4.235')
74
65
  end
66
+
67
+ def distribution
68
+ { interval: :m,
69
+ path: 'test.distribution',
70
+ value: [[5, 11], [15, 2.533], [8, -15], [12, 1e6]],
71
+ ts: 1_538_865_613,
72
+ source: 'minitest',
73
+ tags: { tag1: 'val1', tag2: 'val2' } }
74
+ end
75
75
  end