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,123 +1,150 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- USER = 'user@example.com'.freeze
6
- BAD_USER = ('user' * 500).freeze
7
- PERMISSION = 'agent_management'.freeze
8
-
9
- USER_BODY = { emailAddress: USER, groups: %w[browse] }.freeze
10
-
11
- USERGROUP_LIST = %w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
12
- 2659191e-aad4-4302-a94e-9667e1517127].freeze
13
-
14
- USER_LIST = %w[user@example.com other@elsewhere.com].freeze
4
+ require_relative '../test_mixins/general'
15
5
 
16
6
  # Unit tests for User class
17
7
  #
18
8
  class WavefrontUserTest < WavefrontTestBase
9
+ attr_reader :users, :groups, :permission
10
+
11
+ include WavefrontTest::Delete
12
+ include WavefrontTest::Describe
13
+ include WavefrontTest::Update
14
+
19
15
  def test_list
20
- should_work(:list, nil, '')
16
+ assert_gets('/api/v2/user') { wf.list }
21
17
  end
22
18
 
23
19
  def test_create
24
- should_work(:create, [USER_BODY, true], '?sendEmail=true', :post,
25
- JSON_POST_HEADERS, USER_BODY.to_json)
26
- assert_raises(ArgumentError) { wf.create }
27
- assert_raises(ArgumentError) { wf.create('test') }
28
- end
29
-
30
- def test_delete
31
- should_work(:delete, USER, USER, :delete)
32
- should_be_invalid(:delete, BAD_USER)
33
- assert_raises(ArgumentError) { wf.delete }
34
- end
20
+ assert_posts('/api/v2/user?sendEmail=true', payload) do
21
+ wf.create(payload, true)
22
+ end
35
23
 
36
- def test_describe
37
- should_work(:describe, USER, USER)
38
- should_be_invalid(:describe, BAD_USER)
39
- assert_raises(ArgumentError) { wf.describe }
40
- end
24
+ assert_posts('/api/v2/user?sendEmail=false', payload) do
25
+ wf.create(payload)
26
+ end
41
27
 
42
- def test_update
43
- should_work(:update, [USER, USER_BODY, false], USER, :put,
44
- JSON_POST_HEADERS, USER_BODY.to_json)
45
- should_be_invalid(:update, [BAD_USER, USER_BODY])
46
- assert_raises(ArgumentError) { wf.update }
28
+ assert_raises(ArgumentError) { wf.create }
29
+ assert_raises(ArgumentError) { wf.create('test') }
47
30
  end
48
31
 
49
32
  def test_add_groups_to_user
50
- should_work(:add_groups_to_user, [USER, USERGROUP_LIST],
51
- [USER, :addUserGroups].uri_concat, :post,
52
- JSON_POST_HEADERS, USERGROUP_LIST.to_json)
53
-
54
- assert_raises(Wavefront::Exception::InvalidUserId) do
55
- wf.add_groups_to_user(BAD_USER, USERGROUP_LIST)
33
+ assert_posts("/api/v2/user/#{id}/addUserGroups", groups.to_json) do
34
+ wf.add_groups_to_user(id, groups)
56
35
  end
36
+
37
+ assert_invalid_id { wf.add_groups_to_user(invalid_id, groups) }
57
38
  end
58
39
 
59
40
  def test_remove_groups_from_user
60
- should_work(:remove_groups_from_user, [USER, USERGROUP_LIST],
61
- [USER, :removeUserGroups].uri_concat, :post,
62
- JSON_POST_HEADERS, USERGROUP_LIST.to_json)
63
-
64
- assert_raises(Wavefront::Exception::InvalidUserId) do
65
- wf.remove_groups_from_user(BAD_USER, USERGROUP_LIST)
41
+ assert_posts("/api/v2/user/#{id}/removeUserGroups", groups.to_json) do
42
+ wf.remove_groups_from_user(id, groups)
66
43
  end
44
+
45
+ assert_invalid_id { wf.remove_groups_from_user(invalid_id, groups) }
67
46
  end
68
47
 
69
48
  def test_grant
70
- should_work(:grant, [USER, PERMISSION], 'user%40example.com/grant',
71
- :post, JSON_POST_HEADERS.merge(
72
- 'Content-Type': 'application/x-www-form-urlencoded'
73
- ),
74
- "group=#{PERMISSION}")
75
- should_be_invalid(:grant, [BAD_USER, PERMISSION])
49
+ assert_posts("/api/v2/user/#{id}/grant", { group: permission },
50
+ :form) do
51
+ wf.grant(id, permission)
52
+ end
53
+
54
+ assert_invalid_id { wf.grant(invalid_id, permission) }
76
55
  assert_raises(ArgumentError) { wf.grant }
77
56
  end
78
57
 
79
58
  def test_revoke
80
- should_work(:revoke, [USER, PERMISSION], 'user%40example.com/revoke',
81
- :post, JSON_POST_HEADERS.merge(
82
- 'Content-Type': 'application/x-www-form-urlencoded'
83
- ),
84
- "group=#{PERMISSION}")
85
- should_be_invalid(:revoke, [BAD_USER, PERMISSION])
59
+ assert_posts("/api/v2/user/#{id}/revoke", { group: permission },
60
+ :form) do
61
+ wf.revoke(id, permission)
62
+ end
63
+
64
+ assert_invalid_id { wf.revoke(invalid_id, permission) }
86
65
  assert_raises(ArgumentError) { wf.revoke }
87
66
  end
88
67
 
89
68
  def test_delete_users
90
- should_work(:delete_users, [[USER, 'other@example.com']],
91
- 'deleteUsers', :post, JSON_POST_HEADERS,
92
- [USER, 'other@example.com'].to_json)
93
-
94
- assert_raises(Wavefront::Exception::InvalidUserId) do
95
- wf.delete_users([BAD_USER])
69
+ assert_posts('/api/v2/user/deleteUsers', users.to_json) do
70
+ wf.delete_users(users)
96
71
  end
97
72
 
98
- assert_raises(ArgumentError) { wf.delete_users('a@b.com') }
73
+ assert_invalid_id { wf.delete_users([invalid_id]) }
74
+ assert_raises(ArgumentError) { wf.delete_users(id) }
99
75
  end
100
76
 
101
77
  def test_grant_permission
102
- should_work(:grant_permission, [PERMISSION, USER_LIST],
103
- [:grant, PERMISSION].uri_concat, :post,
104
- JSON_POST_HEADERS, USER_LIST.to_json)
105
- should_be_invalid(:grant, [BAD_USER, PERMISSION])
78
+ assert_posts("/api/v2/user/grant/#{permission}", users.to_json) do
79
+ wf.grant_permission(permission, users)
80
+ end
81
+
82
+ assert_invalid_id { wf.grant_permission(permission, [invalid_id]) }
106
83
  assert_raises(ArgumentError) { wf.grant }
107
84
  end
108
85
 
109
86
  def test_revoke_permission
110
- should_work(:revoke_permission, [PERMISSION, USER_LIST],
111
- [:revoke, PERMISSION].uri_concat, :post,
112
- JSON_POST_HEADERS, USER_LIST.to_json)
113
- should_be_invalid(:revoke, [BAD_USER, PERMISSION])
87
+ assert_posts("/api/v2/user/revoke/#{permission}", users.to_json) do
88
+ wf.revoke_permission(permission, users)
89
+ end
90
+
91
+ assert_invalid_id { wf.revoke_permission(permission, [invalid_id]) }
114
92
  assert_raises(ArgumentError) { wf.grant }
115
93
  end
116
94
 
117
95
  def test_invite
118
- should_work(:invite, [[USER_BODY]], 'invite', :post,
119
- JSON_POST_HEADERS, [USER_BODY].to_json)
96
+ assert_posts('/api/v2/user/invite', [payload].to_json) do
97
+ wf.invite([payload])
98
+ end
99
+
120
100
  assert_raises(ArgumentError) { wf.invite }
121
101
  assert_raises(ArgumentError) { wf.invite('test') }
122
102
  end
103
+
104
+ def test_response_shim
105
+ (RESOURCE_DIR + 'user_responses').each_child do |input|
106
+ # Ugly hack for the 202 in the 'create' file
107
+ status = input.basename.to_s == 'create.json' ? 202 : 200
108
+ shimmed = wf.response_shim(IO.read(input), status)
109
+ assert_instance_of(String, shimmed)
110
+
111
+ ret_obj = JSON.parse(shimmed, symbolize_names: true)
112
+ assert_instance_of(Hash, ret_obj)
113
+ assert_equal(%i[response status], ret_obj.keys.sort)
114
+
115
+ ret_status = ret_obj[:status]
116
+ assert_instance_of(Hash, ret_status)
117
+ assert_equal(%i[result message code], ret_status.keys)
118
+
119
+ ret_resp = ret_obj[:response]
120
+ assert_instance_of(Hash, ret_resp)
121
+ assert ret_resp.key?(:items)
122
+ assert_instance_of(Array, ret_resp[:items])
123
+ end
124
+ end
125
+
126
+ def setup_fixtures
127
+ @users = %w[user@example.com other@elsewhere.com]
128
+ @groups = %w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
129
+ 2659191e-aad4-4302-a94e-9667e1517127]
130
+ @permission = 'agent_management'
131
+ end
132
+
133
+ private
134
+
135
+ def api_class
136
+ 'user'
137
+ end
138
+
139
+ def id
140
+ 'user@example.com'
141
+ end
142
+
143
+ def invalid_id
144
+ 'user' * 500
145
+ end
146
+
147
+ def payload
148
+ { emailAddress: id, groups: %w[browse] }
149
+ end
123
150
  end
@@ -1,98 +1,87 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- G_USERGROUP_ID = 'f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672'.freeze
6
- G_BAD_USERGROUP_ID = 'some_rubbish'.freeze
7
-
8
- G_USERGROUP_BODY = { name: 'test group',
9
- permissions: %w[alerts_management
10
- dashboard_management
11
- events_management] }.freeze
12
-
13
- G_USER_LIST = %w[someone@somewhere.com other@elsewhere.net].freeze
14
- G_BAD_USER_LIST = ['bad' * 500, ''].freeze
15
-
16
- G_PERMISSION = 'alerts_management'.freeze
17
-
18
- G_GROUP_LIST = %w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
19
- 2659191e-aad4-4302-a94e-9667e1517127].freeze
20
-
21
- G_BAD_GROUP_LIST = %w[some-nonsense more-nonsense].freeze
4
+ require_relative '../test_mixins/general'
22
5
 
23
6
  # Unit tests for WavefrontUserGroup
24
7
  #
25
8
  class WavefrontUserGroupTest < WavefrontTestBase
26
- def test_list
27
- should_work(:list, 10, '?offset=10&limit=100')
28
- end
9
+ attr_reader :users, :groups, :permission, :invalid_groups, :invalid_users
29
10
 
30
- def test_create
31
- should_work(:create, G_USERGROUP_BODY, '', :post,
32
- JSON_POST_HEADERS, G_USERGROUP_BODY.to_json)
33
- assert_raises(ArgumentError) { wf.create }
34
- assert_raises(ArgumentError) { wf.create('test') }
35
- end
36
-
37
- def test_delete
38
- should_work(:delete, G_USERGROUP_ID, G_USERGROUP_ID, :delete)
39
- should_be_invalid(:delete)
40
- end
41
-
42
- def test_describe
43
- should_work(:describe, G_USERGROUP_ID, G_USERGROUP_ID)
44
- assert_raises(ArgumentError) { wf.describe }
45
- end
46
-
47
- def test_update
48
- should_work(:update, [G_USERGROUP_ID, G_USERGROUP_BODY, false],
49
- G_USERGROUP_ID, :put, JSON_POST_HEADERS,
50
- G_USERGROUP_BODY.to_json)
51
- should_be_invalid(:update, ['!some rubbish!', G_USERGROUP_BODY])
52
- assert_raises(ArgumentError) { wf.update }
53
- end
11
+ include WavefrontTest::Create
12
+ include WavefrontTest::Delete
13
+ include WavefrontTest::Describe
14
+ include WavefrontTest::List
15
+ include WavefrontTest::Update
54
16
 
55
17
  def test_add_users_to_group
56
- should_work(:add_users_to_group, [G_USERGROUP_ID, G_USER_LIST],
57
- [G_USERGROUP_ID, :addUsers].uri_concat, :post)
18
+ assert_posts("/api/v2/usergroup/#{id}/addUsers", users.to_json) do
19
+ wf.add_users_to_group(id, users)
20
+ end
58
21
 
59
22
  assert_raises(Wavefront::Exception::InvalidUserId) do
60
- wf.add_users_to_group(G_USERGROUP_ID, G_BAD_USER_LIST)
23
+ wf.add_users_to_group(id, invalid_users)
61
24
  end
62
25
 
63
- assert_raises(Wavefront::Exception::InvalidUserGroupId) do
64
- wf.add_users_to_group(G_BAD_USERGROUP_ID, G_USER_LIST)
65
- end
26
+ assert_invalid_id { wf.add_users_to_group(invalid_id, users) }
66
27
  end
67
28
 
68
29
  def test_remove_users_from_group
69
- should_work(:remove_users_from_group, [G_USERGROUP_ID, G_USER_LIST],
70
- [G_USERGROUP_ID, :removeUsers].uri_concat, :post)
30
+ assert_posts("/api/v2/usergroup/#{id}/removeUsers", users.to_json) do
31
+ wf.remove_users_from_group(id, users)
32
+ end
71
33
 
72
34
  assert_raises(Wavefront::Exception::InvalidUserId) do
73
- wf.remove_users_from_group(G_USERGROUP_ID, G_BAD_USER_LIST)
35
+ wf.remove_users_from_group(id, invalid_users)
74
36
  end
75
37
 
76
- assert_raises(Wavefront::Exception::InvalidUserGroupId) do
77
- wf.remove_users_from_group(G_BAD_USERGROUP_ID, G_USER_LIST)
78
- end
38
+ assert_invalid_id { wf.remove_users_from_group(invalid_id, users) }
79
39
  end
80
40
 
81
41
  def test_grant
82
- should_work(:grant, [G_PERMISSION, G_GROUP_LIST],
83
- [:grant, G_PERMISSION].uri_concat, :post)
84
-
85
- assert_raises(Wavefront::Exception::InvalidUserGroupId) do
86
- wf.grant(G_PERMISSION, G_BAD_GROUP_LIST)
42
+ assert_posts("/api/v2/usergroup/grant/#{permission}",
43
+ groups.to_json) do
44
+ wf.grant(permission, groups)
87
45
  end
46
+
47
+ assert_invalid_id { wf.grant(permission, invalid_groups) }
88
48
  end
89
49
 
90
50
  def test_revoke
91
- should_work(:revoke, [G_PERMISSION, G_GROUP_LIST],
92
- [:revoke, G_PERMISSION].uri_concat, :post)
93
-
94
- assert_raises(Wavefront::Exception::InvalidUserGroupId) do
95
- wf.revoke(G_PERMISSION, G_BAD_GROUP_LIST)
51
+ assert_posts("/api/v2/usergroup/revoke/#{permission}",
52
+ groups.to_json) do
53
+ wf.revoke(permission, groups)
96
54
  end
55
+
56
+ assert_invalid_id { wf.revoke(permission, invalid_groups) }
57
+ end
58
+
59
+ def setup_fixtures
60
+ @permission = 'alerts_management'
61
+ @invalid_groups = %w[some-nonsense more-nonsense]
62
+ @groups = %w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
63
+ 2659191e-aad4-4302-a94e-9667e1517127]
64
+ @users = %w[someone@somewhere.com other@elsewhere.net]
65
+ @invalid_users = ['bad' * 500, '']
66
+ end
67
+
68
+ private
69
+
70
+ def api_class
71
+ 'usergroup'
72
+ end
73
+
74
+ def id
75
+ 'f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672'
76
+ end
77
+
78
+ def invalid_id
79
+ 'this is not what you call a group'
80
+ end
81
+
82
+ def payload
83
+ { name: 'test group',
84
+ permissions: %w[alerts_management dashboard_management
85
+ events_management] }
97
86
  end
98
87
  end
@@ -1,50 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- WEBHOOK = '9095WaGklE8Gy3M1'.freeze
6
-
7
- WEBHOOK_BODY = {
8
- description: 'WebHook Description',
9
- template: 'POST Body -- Mustache syntax',
10
- title: 'WebHook Title',
11
- triggers: %w[ALERT_OPENED],
12
- recipient: 'http://example.com',
13
- customHttpHeaders: {},
14
- contentType: 'text/plain'
15
- }.freeze
4
+ require_relative '../test_mixins/general'
16
5
 
17
6
  # Unit tests for Webhook class
18
7
  #
19
8
  class WavefrontWebhookTest < WavefrontTestBase
20
- def test_list
21
- should_work(:list, 10, '?offset=10&limit=100')
22
- should_work(:list, [20, 30], '?offset=20&limit=30')
23
- end
9
+ include WavefrontTest::Create
10
+ include WavefrontTest::Delete
11
+ include WavefrontTest::Describe
12
+ include WavefrontTest::List
13
+ include WavefrontTest::Update
14
+
15
+ private
24
16
 
25
- def test_describe
26
- should_work(:describe, WEBHOOK, WEBHOOK)
27
- should_be_invalid(:describe, 'abcdefg')
28
- assert_raises(ArgumentError) { wf.describe }
17
+ def api_class
18
+ 'webhook'
29
19
  end
30
20
 
31
- def test_create
32
- should_work(:create, WEBHOOK_BODY, '', :post,
33
- JSON_POST_HEADERS, WEBHOOK_BODY.to_json)
34
- assert_raises(ArgumentError) { wf.create }
35
- assert_raises(ArgumentError) { wf.create('test') }
21
+ def id
22
+ '9095WaGklE8Gy3M1'
36
23
  end
37
24
 
38
- def test_delete
39
- should_work(:delete, WEBHOOK, WEBHOOK, :delete)
40
- should_be_invalid(:delete, 'abcdefg')
41
- assert_raises(ArgumentError) { wf.delete }
25
+ def invalid_id
26
+ '+-+-+-+'
42
27
  end
43
28
 
44
- def test_update
45
- should_work(:update, [WEBHOOK, WEBHOOK_BODY, false], WEBHOOK, :put,
46
- JSON_POST_HEADERS, WEBHOOK_BODY.to_json)
47
- should_be_invalid(:update, ['abcde', WEBHOOK_BODY])
48
- assert_raises(ArgumentError) { wf.update }
29
+ def payload
30
+ { description: 'WebHook Description',
31
+ template: 'POST Body -- Mustache syntax',
32
+ title: 'WebHook Title',
33
+ triggers: %w[ALERT_OPENED],
34
+ recipient: 'http://example.com',
35
+ customHttpHeaders: {},
36
+ contentType: 'text/plain' }
49
37
  end
50
38
  end