azure_application_insights 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +34 -0
  3. data/.gitignore +40 -0
  4. data/.travis.yml +22 -0
  5. data/CHANGELOG.md +17 -0
  6. data/CONTRIBUTING.md +68 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +11 -0
  9. data/README.md +161 -0
  10. data/Rakefile +15 -0
  11. data/application_insights.gemspec +30 -0
  12. data/lib/application_insights/channel/asynchronous_queue.rb +58 -0
  13. data/lib/application_insights/channel/asynchronous_sender.rb +133 -0
  14. data/lib/application_insights/channel/contracts/application.rb +14 -0
  15. data/lib/application_insights/channel/contracts/cloud.rb +14 -0
  16. data/lib/application_insights/channel/contracts/data.rb +14 -0
  17. data/lib/application_insights/channel/contracts/data_point.rb +24 -0
  18. data/lib/application_insights/channel/contracts/data_point_type.rb +7 -0
  19. data/lib/application_insights/channel/contracts/dependency_kind.rb +9 -0
  20. data/lib/application_insights/channel/contracts/dependency_source_type.rb +9 -0
  21. data/lib/application_insights/channel/contracts/device.rb +28 -0
  22. data/lib/application_insights/channel/contracts/envelope.rb +40 -0
  23. data/lib/application_insights/channel/contracts/event_data.rb +28 -0
  24. data/lib/application_insights/channel/contracts/exception_data.rb +37 -0
  25. data/lib/application_insights/channel/contracts/exception_details.rb +28 -0
  26. data/lib/application_insights/channel/contracts/internal.rb +14 -0
  27. data/lib/application_insights/channel/contracts/json_serializable.rb +59 -0
  28. data/lib/application_insights/channel/contracts/location.rb +16 -0
  29. data/lib/application_insights/channel/contracts/message_data.rb +24 -0
  30. data/lib/application_insights/channel/contracts/metric_data.rb +27 -0
  31. data/lib/application_insights/channel/contracts/operation.rb +19 -0
  32. data/lib/application_insights/channel/contracts/page_view_data.rb +30 -0
  33. data/lib/application_insights/channel/contracts/remote_dependency_data.rb +56 -0
  34. data/lib/application_insights/channel/contracts/request_data.rb +36 -0
  35. data/lib/application_insights/channel/contracts/session.rb +15 -0
  36. data/lib/application_insights/channel/contracts/severity_level.rb +13 -0
  37. data/lib/application_insights/channel/contracts/stack_frame.rb +17 -0
  38. data/lib/application_insights/channel/contracts/user.rb +19 -0
  39. data/lib/application_insights/channel/event.rb +68 -0
  40. data/lib/application_insights/channel/queue_base.rb +73 -0
  41. data/lib/application_insights/channel/sender_base.rb +88 -0
  42. data/lib/application_insights/channel/synchronous_queue.rb +45 -0
  43. data/lib/application_insights/channel/synchronous_sender.rb +17 -0
  44. data/lib/application_insights/channel/telemetry_channel.rb +131 -0
  45. data/lib/application_insights/channel/telemetry_context.rb +85 -0
  46. data/lib/application_insights/rack/track_request.rb +158 -0
  47. data/lib/application_insights/telemetry_client.rb +229 -0
  48. data/lib/application_insights/unhandled_exception.rb +49 -0
  49. data/lib/application_insights/version.rb +3 -0
  50. data/lib/application_insights.rb +9 -0
  51. data/test/application_insights/channel/contracts/test_application.rb +44 -0
  52. data/test/application_insights/channel/contracts/test_cloud.rb +44 -0
  53. data/test/application_insights/channel/contracts/test_data.rb +44 -0
  54. data/test/application_insights/channel/contracts/test_data_point.rb +109 -0
  55. data/test/application_insights/channel/contracts/test_device.rb +200 -0
  56. data/test/application_insights/channel/contracts/test_envelope.rb +209 -0
  57. data/test/application_insights/channel/contracts/test_event_data.rb +62 -0
  58. data/test/application_insights/channel/contracts/test_exception_data.rb +111 -0
  59. data/test/application_insights/channel/contracts/test_exception_details.rb +106 -0
  60. data/test/application_insights/channel/contracts/test_internal.rb +44 -0
  61. data/test/application_insights/channel/contracts/test_location.rb +70 -0
  62. data/test/application_insights/channel/contracts/test_message_data.rb +66 -0
  63. data/test/application_insights/channel/contracts/test_metric_data.rb +50 -0
  64. data/test/application_insights/channel/contracts/test_operation.rb +109 -0
  65. data/test/application_insights/channel/contracts/test_page_view_data.rb +88 -0
  66. data/test/application_insights/channel/contracts/test_remote_dependency_data.rb +209 -0
  67. data/test/application_insights/channel/contracts/test_request_data.rb +153 -0
  68. data/test/application_insights/channel/contracts/test_session.rb +57 -0
  69. data/test/application_insights/channel/contracts/test_stack_frame.rb +83 -0
  70. data/test/application_insights/channel/contracts/test_user.rb +96 -0
  71. data/test/application_insights/channel/test_asynchronous_queue.rb +47 -0
  72. data/test/application_insights/channel/test_asynchronous_sender.rb +81 -0
  73. data/test/application_insights/channel/test_event.rb +53 -0
  74. data/test/application_insights/channel/test_queue_base.rb +89 -0
  75. data/test/application_insights/channel/test_sender_base.rb +94 -0
  76. data/test/application_insights/channel/test_synchronous_queue.rb +28 -0
  77. data/test/application_insights/channel/test_synchronous_sender.rb +11 -0
  78. data/test/application_insights/channel/test_telemetry_channel.rb +167 -0
  79. data/test/application_insights/channel/test_telemetry_context.rb +83 -0
  80. data/test/application_insights/mock_sender.rb +37 -0
  81. data/test/application_insights/rack/test_track_request.rb +182 -0
  82. data/test/application_insights/test_logger.rb +10 -0
  83. data/test/application_insights/test_telemetry_client.rb +138 -0
  84. data/test/application_insights/test_unhandled_exception.rb +23 -0
  85. data/test/application_insights.rb +8 -0
  86. metadata +247 -0
@@ -0,0 +1,229 @@
1
+ require_relative 'channel/telemetry_context'
2
+ require_relative 'channel/telemetry_channel'
3
+ require_relative 'channel/contracts/page_view_data'
4
+ require_relative 'channel/contracts/exception_data'
5
+ require_relative 'channel/contracts/exception_details'
6
+ require_relative 'channel/contracts/event_data'
7
+ require_relative 'channel/contracts/data_point'
8
+ require_relative 'channel/contracts/data_point_type'
9
+ require_relative 'channel/contracts/metric_data'
10
+ require_relative 'channel/contracts/message_data'
11
+ require_relative 'channel/contracts/stack_frame'
12
+ require_relative 'channel/contracts/request_data'
13
+ require_relative 'channel/contracts/severity_level'
14
+
15
+ module ApplicationInsights
16
+ # The telemetry client used for sending all types of telemetry. It serves as
17
+ # the main entry point for interacting with the Application Insights service.
18
+ class TelemetryClient
19
+ # Initializes a new instance of the class.
20
+ # @param [String] instrumentation_key to identify which Application Insights
21
+ # application this data is for.
22
+ # @param [Channel::TelemetryChannel] telemetry_channel the optional telemetry
23
+ # channel to be used instead of constructing a default one.
24
+ def initialize(instrumentation_key = nil, telemetry_channel = nil)
25
+ @context = Channel::TelemetryContext.new
26
+ @context.instrumentation_key = instrumentation_key
27
+ @channel = telemetry_channel || Channel::TelemetryChannel.new
28
+ end
29
+
30
+ # The context associated with this client. All data objects created by this
31
+ # client will be accompanied by this value.
32
+ # @return [Channel::TelemetryContext] the context instance.
33
+ attr_reader :context
34
+
35
+ # The channel associated with this telemetry client. All data created by this
36
+ # client will be passed along with the {#context} object to
37
+ # {Channel::TelemetryChannel#write}
38
+ # @return [Channel::TelemetryChannel] the channel instance.
39
+ attr_reader :channel
40
+
41
+ # Send information about the page viewed in the application (a web page for
42
+ # instance).
43
+ # @param [String] name the name of the page that was viewed.
44
+ # @param [String] url the URL of the page that was viewed.
45
+ # @param [Hash] options the options to create the
46
+ # {Channel::Contracts::PageViewData} object.
47
+ # @option options [Fixnum] :duration the duration of the page view in
48
+ # milliseconds. (defaults to: 0)
49
+ # @option options [Hash] :properties the set of custom properties the client
50
+ # wants attached to this data item. (defaults to: {})
51
+ # @option options [Hash] :measurements the set of custom measurements the
52
+ # client wants to attach to this data item (defaults to: {})
53
+ def track_page_view(name, url, options={})
54
+ data_attributes = {
55
+ :name => name || 'Null',
56
+ :url => url,
57
+ :duration => options[:duration],
58
+ :properties => options[:properties] || {},
59
+ :measurements => options[:measurements] || {}
60
+ }
61
+ data = Channel::Contracts::PageViewData.new data_attributes
62
+ self.channel.write(data, self.context)
63
+ end
64
+
65
+ # Send information about a single exception that occurred in the application.
66
+ # @param [Exception] exception the exception that the client wants to send.
67
+ # @param [Hash] options the options to create the
68
+ # {Channel::Contracts::ExceptionData} object.
69
+ # @option options [String] :handled_at the type of exception
70
+ # (defaults to: 'UserCode')
71
+ # @option options [Hash] :properties the set of custom properties the client
72
+ # wants attached to this data item. (defaults to: {})
73
+ # @option options [Hash] :measurements the set of custom measurements the
74
+ # client wants to attach to this data item (defaults to: {})
75
+ def track_exception(exception, options={})
76
+ return unless exception.is_a? Exception
77
+
78
+ parsed_stack = []
79
+ if exception.backtrace
80
+ frame_pattern = /^(?<file>.*):(?<line>\d+)(\.|:in `((?<method>.*)'$))/
81
+
82
+ exception.backtrace.each_with_index do |frame, counter|
83
+ match = frame_pattern.match frame
84
+ stack_frame = Channel::Contracts::StackFrame.new(
85
+ :assembly => 'Unknown',
86
+ :file_name => match['file'],
87
+ :level => counter,
88
+ :line => match['line'],
89
+ :method => match['method']
90
+ )
91
+
92
+ parsed_stack << stack_frame
93
+ end
94
+ end
95
+
96
+ details = Channel::Contracts::ExceptionDetails.new(
97
+ :id => 1,
98
+ :outer_id => 0,
99
+ :type_name => exception.class.name,
100
+ :message => exception.message,
101
+ :has_full_stack => exception.backtrace != nil,
102
+ :stack => (exception.backtrace.join("\n") if exception.backtrace),
103
+ :parsed_stack => parsed_stack
104
+ )
105
+
106
+ data = Channel::Contracts::ExceptionData.new(
107
+ :handled_at => options.fetch(:handled_at, 'UserCode'),
108
+ :exceptions => [details],
109
+ :properties => options[:properties] || {},
110
+ :measurements => options[:measurements] || {}
111
+ )
112
+
113
+ self.channel.write(data, self.context)
114
+ end
115
+
116
+ # Send information about a single event that has occurred in the context of
117
+ # the application.
118
+ # @param [String] name the data to associate to this event.
119
+ # @param [Hash] options the options to create the
120
+ # {Channel::Contracts::EventData} object.
121
+ # @option options [Hash] :properties the set of custom properties the client
122
+ # wants attached to this data item. (defaults to: {})
123
+ # @option options [Hash] :measurements the set of custom measurements the
124
+ # client wants to attach to this data item (defaults to: {})
125
+ def track_event(name, options={})
126
+ data = Channel::Contracts::EventData.new(
127
+ :name => name || 'Null',
128
+ :properties => options[:properties] || {},
129
+ :measurements => options[:measurements] || {}
130
+ )
131
+
132
+ self.channel.write(data, self.context)
133
+ end
134
+
135
+ # Send information about a single metric data point that was captured for
136
+ # the application.
137
+ # @param [String] name the name of the metric that was captured.
138
+ # @param [Fixnum] value the value of the metric that was captured.
139
+ # @param [Hash] options the options to create the
140
+ # {Channel::Contracts::MetricData} object.
141
+ # @option options [Channel::Contracts::DataPointType] :type the type of the
142
+ # metric (defaults to: {Channel::Contracts::DataPointType::AGGREGATION})
143
+ # @option options [Fixnum] :count the number of metrics that were aggregated
144
+ # into this data point (defaults to: 0)
145
+ # @option options [Fixnum] :min the minimum of all metrics collected that
146
+ # were aggregated into this data point (defaults to: 0)
147
+ # @option options [Fixnum] :max the maximum of all metrics collected that
148
+ # were aggregated into this data point (defaults to: 0)
149
+ # @option options [Fixnum] :std_dev the standard deviation of all metrics
150
+ # collected that were aggregated into this data point (defaults to: 0)
151
+ # @option options [Hash] :properties the set of custom properties the client
152
+ # wants attached to this data item. (defaults to: {})
153
+ # @option options [Hash] :measurements the set of custom measurements the
154
+ # client wants to attach to this data item (defaults to: {})
155
+ def track_metric(name, value, options={})
156
+ data_point = Channel::Contracts::DataPoint.new(
157
+ :name => name || 'Null',
158
+ :value => value || 0,
159
+ :kind => options[:type] || Channel::Contracts::DataPointType::AGGREGATION,
160
+ :count => options[:count],
161
+ :min => options[:min],
162
+ :max => options[:max],
163
+ :std_dev => options[:std_dev]
164
+ )
165
+
166
+ data = Channel::Contracts::MetricData.new(
167
+ :metrics => [data_point],
168
+ :properties => options[:properties] || {}
169
+ )
170
+
171
+ self.channel.write(data, self.context)
172
+ end
173
+
174
+ # Sends a single trace statement.
175
+ # @param [String] name the trace statement.
176
+ # @param [Channel::Contracts::SeverityLevel] severity_level the severity level.
177
+ # @param [Hash] options the options to create the
178
+ # {Channel::Contracts::EventData} object.
179
+ # @option options [Hash] :properties the set of custom properties the client
180
+ # wants attached to this data item. (defaults to: {})
181
+ def track_trace(name, severity_level = nil, options={})
182
+ data = Channel::Contracts::MessageData.new(
183
+ :message => name || 'Null',
184
+ :severity_level => severity_level || Channel::Contracts::SeverityLevel::INFORMATION,
185
+ :properties => options[:properties] || {}
186
+ )
187
+
188
+ self.channel.write(data, self.context)
189
+ end
190
+
191
+ # Sends a single request.
192
+ # @param [String] id the unique identifier of the request.
193
+ # @param (String) start_time the start time of the request.
194
+ # @param [String] duration the duration to process the request.
195
+ # @param [String] response_code the response code of the request.
196
+ # @param [Boolean] success indicates whether the request succeeds or not.
197
+ # @param [Hash] options the options to create the
198
+ # {Channel::Contracts::RequestData} object.
199
+ # @option options [String] :name the name of the request.
200
+ # @option options [String] :http_method the http method used for the request.
201
+ # @option options [String] :url the url of the request.
202
+ # @option options [Hash] :properties the set of custom properties the client
203
+ # wants attached to this data item. (defaults to: {})
204
+ # @option options [Hash] :measurements the set of custom measurements the
205
+ # client wants to attach to this data item (defaults to: {})
206
+ def track_request(id, start_time, duration, response_code, success, options={})
207
+ data = Channel::Contracts::RequestData.new(
208
+ :id => id || 'Null',
209
+ :start_time => start_time || Time.now.iso8601(7),
210
+ :duration => duration || '0:00:00:00.0000000',
211
+ :response_code => response_code || 200,
212
+ :success => success = nil ? true : success,
213
+ :name => options[:name],
214
+ :http_method => options[:http_method],
215
+ :url => options[:url],
216
+ :properties => options[:properties] || {},
217
+ :measurements => options[:measurements] || {}
218
+ )
219
+
220
+ self.channel.write(data, self.context, start_time)
221
+ end
222
+
223
+ # Flushes data in the queue. Data in the queue will be sent either immediately
224
+ # irrespective of what sender is being used.
225
+ def flush
226
+ self.channel.flush
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'telemetry_client'
2
+ require_relative 'channel/telemetry_channel'
3
+ require_relative 'channel/synchronous_queue'
4
+ require_relative 'channel/synchronous_sender'
5
+
6
+ include ApplicationInsights
7
+
8
+ module ApplicationInsights
9
+ module UnhandledException
10
+ @sender = nil
11
+
12
+ # Auto collects unhandled exception and send to the Application Insights service.
13
+ # @param (string) instrumentation_key used to identify which Application
14
+ # Insights application this data is for.
15
+ # @example
16
+ # require 'application_insights'
17
+ # ApplicationInsights::UnhandledException.collect('<YOUR INSTRUMENTATION KEY GOES HERE>')
18
+ # raise Exception, 'Boom!'
19
+ def self.collect(instrumentation_key)
20
+ at_exit do
21
+ # Avoid sending exception more than once if this method got invoked multiple times
22
+ send(instrumentation_key) unless @sender
23
+ end
24
+ end
25
+
26
+ # @api private
27
+ # Send the last raised exception to the Application Insights service if
28
+ # telemetry_sender is not customized.
29
+ # @param (string) instrumentation_key used to identify which Application
30
+ # Insights application this data is for.
31
+ # @param (SenderBase) telemetry_sender used to send the last raised exception.
32
+ def self.send(instrumentation_key, telemetry_sender = nil)
33
+ if $! && !$!.is_a?(SystemExit) && !$!.is_a?(SignalException)
34
+ if telemetry_sender
35
+ @sender = telemetry_sender
36
+ elsif !@sender
37
+ # Use a synchronized sender to guarantee the data would be sent out once flush
38
+ @sender = Channel::SynchronousSender.new
39
+ end
40
+
41
+ queue = Channel::SynchronousQueue.new @sender
42
+ channel = Channel::TelemetryChannel.new nil, queue
43
+ client = TelemetryClient.new instrumentation_key, channel
44
+ client.track_exception($!, handled_at: 'Unhandled')
45
+ client.flush
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module ApplicationInsights
2
+ VERSION = '0.5.7'.freeze
3
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'application_insights/telemetry_client'
2
+ require_relative 'application_insights/unhandled_exception'
3
+ require_relative 'application_insights/version'
4
+
5
+ module ApplicationInsights
6
+ module Rack
7
+ autoload :TrackRequest, "application_insights/rack/track_request"
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../../../../lib/application_insights/channel/contracts/application'
2
+ require 'test/unit'
3
+
4
+ include ApplicationInsights::Channel
5
+
6
+ class TestApplication < Test::Unit::TestCase
7
+ def test_initialize
8
+ item = Contracts::Application.new
9
+ assert_not_nil item
10
+ end
11
+
12
+ def test_ver_works_as_expected
13
+ expected = 'Test string'
14
+ item = Contracts::Application.new
15
+ item.ver = expected
16
+ actual = item.ver
17
+ assert_equal expected, actual
18
+ expected = 'Other string'
19
+ item.ver = expected
20
+ actual = item.ver
21
+ assert_equal expected, actual
22
+ end
23
+
24
+ def test_build_works_as_expected
25
+ expected = 'Test string'
26
+ item = Contracts::Application.new
27
+ item.build = expected
28
+ actual = item.build
29
+ assert_equal expected, actual
30
+ expected = 'Other string'
31
+ item.build = expected
32
+ actual = item.build
33
+ assert_equal expected, actual
34
+ end
35
+
36
+ def test_to_json_works_as_expected
37
+ item = Contracts::Application.new
38
+ item.ver = 'Test string'
39
+ item.build = 'Test string'
40
+ actual = item.to_json
41
+ expected = '{"ai.application.ver":"Test string","ai.application.build":"Test string"}'
42
+ assert_equal expected, actual
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../../../../lib/application_insights/channel/contracts/cloud'
2
+ require 'test/unit'
3
+
4
+ include ApplicationInsights::Channel
5
+
6
+ class TestCloud < Test::Unit::TestCase
7
+ def test_initialize
8
+ item = Contracts::Cloud.new
9
+ assert_not_nil item
10
+ end
11
+
12
+ def test_role_name_works_as_expected
13
+ expected = 'Test string'
14
+ item = Contracts::Cloud.new
15
+ item.role_name = expected
16
+ actual = item.role_name
17
+ assert_equal expected, actual
18
+ expected = 'Other string'
19
+ item.role_name = expected
20
+ actual = item.role_name
21
+ assert_equal expected, actual
22
+ end
23
+
24
+ def test_role_instance_works_as_expected
25
+ expected = 'Test string'
26
+ item = Contracts::Cloud.new
27
+ item.role_instance = expected
28
+ actual = item.role_instance
29
+ assert_equal expected, actual
30
+ expected = 'Other string'
31
+ item.role_instance = expected
32
+ actual = item.role_instance
33
+ assert_equal expected, actual
34
+ end
35
+
36
+ def test_to_json_works_as_expected
37
+ item = Contracts::Cloud.new
38
+ item.role_name = 'Role name'
39
+ item.role_instance = 'Role instance'
40
+ actual = item.to_json
41
+ expected = '{"ai.cloud.role":"Role name","ai.cloud.roleInstance":"Role instance"}'
42
+ assert_equal expected, actual
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../../../../lib/application_insights/channel/contracts/data'
2
+ require 'test/unit'
3
+
4
+ include ApplicationInsights::Channel
5
+
6
+ class TestData < Test::Unit::TestCase
7
+ def test_initialize
8
+ item = Contracts::Data.new
9
+ assert_not_nil item
10
+ end
11
+
12
+ def test_base_type_works_as_expected
13
+ expected = 'Test string'
14
+ item = Contracts::Data.new
15
+ item.base_type = expected
16
+ actual = item.base_type
17
+ assert_equal expected, actual
18
+ expected = 'Other string'
19
+ item.base_type = expected
20
+ actual = item.base_type
21
+ assert_equal expected, actual
22
+ end
23
+
24
+ def test_base_data_works_as_expected
25
+ expected = { 'key' => 'value' }
26
+ item = Contracts::Data.new
27
+ item.base_data = expected
28
+ actual = item.base_data
29
+ assert_equal expected, actual
30
+ expected = { 'key' => 'value' }
31
+ item.base_data = expected
32
+ actual = item.base_data
33
+ assert_equal expected, actual
34
+ end
35
+
36
+ def test_to_json_works_as_expected
37
+ item = Contracts::Data.new
38
+ item.base_type = 'Test string'
39
+ item.base_data = { 'key' => 'value' }
40
+ actual = item.to_json
41
+ expected = '{"baseType":"Test string","baseData":{"key":"value"}}'
42
+ assert_equal expected, actual
43
+ end
44
+ end
@@ -0,0 +1,109 @@
1
+ require_relative '../../../../lib/application_insights/channel/contracts/data_point'
2
+ require 'test/unit'
3
+
4
+ include ApplicationInsights::Channel
5
+
6
+ class TestDataPoint < Test::Unit::TestCase
7
+ def test_initialize
8
+ item = Contracts::DataPoint.new
9
+ assert_not_nil item
10
+ end
11
+
12
+ def test_name_works_as_expected
13
+ expected = 'Test string'
14
+ item = Contracts::DataPoint.new
15
+ item.name = expected
16
+ actual = item.name
17
+ assert_equal expected, actual
18
+ expected = 'Other string'
19
+ item.name = expected
20
+ actual = item.name
21
+ assert_equal expected, actual
22
+ end
23
+
24
+ def test_kind_works_as_expected
25
+ expected = 5
26
+ item = Contracts::DataPoint.new
27
+ item.kind = expected
28
+ actual = item.kind
29
+ assert_equal expected, actual
30
+ expected = 3
31
+ item.kind = expected
32
+ actual = item.kind
33
+ assert_equal expected, actual
34
+ end
35
+
36
+ def test_value_works_as_expected
37
+ expected = 1.5
38
+ item = Contracts::DataPoint.new
39
+ item.value = expected
40
+ actual = item.value
41
+ assert_equal expected, actual
42
+ expected = 4.8
43
+ item.value = expected
44
+ actual = item.value
45
+ assert_equal expected, actual
46
+ end
47
+
48
+ def test_count_works_as_expected
49
+ expected = 42
50
+ item = Contracts::DataPoint.new
51
+ item.count = expected
52
+ actual = item.count
53
+ assert_equal expected, actual
54
+ expected = 13
55
+ item.count = expected
56
+ actual = item.count
57
+ assert_equal expected, actual
58
+ end
59
+
60
+ def test_min_works_as_expected
61
+ expected = 1.5
62
+ item = Contracts::DataPoint.new
63
+ item.min = expected
64
+ actual = item.min
65
+ assert_equal expected, actual
66
+ expected = 4.8
67
+ item.min = expected
68
+ actual = item.min
69
+ assert_equal expected, actual
70
+ end
71
+
72
+ def test_max_works_as_expected
73
+ expected = 1.5
74
+ item = Contracts::DataPoint.new
75
+ item.max = expected
76
+ actual = item.max
77
+ assert_equal expected, actual
78
+ expected = 4.8
79
+ item.max = expected
80
+ actual = item.max
81
+ assert_equal expected, actual
82
+ end
83
+
84
+ def test_std_dev_works_as_expected
85
+ expected = 1.5
86
+ item = Contracts::DataPoint.new
87
+ item.std_dev = expected
88
+ actual = item.std_dev
89
+ assert_equal expected, actual
90
+ expected = 4.8
91
+ item.std_dev = expected
92
+ actual = item.std_dev
93
+ assert_equal expected, actual
94
+ end
95
+
96
+ def test_to_json_works_as_expected
97
+ item = Contracts::DataPoint.new
98
+ item.name = 'Test string'
99
+ item.kind = 5
100
+ item.value = 1.5
101
+ item.count = 42
102
+ item.min = 1.5
103
+ item.max = 1.5
104
+ item.std_dev = 1.5
105
+ actual = item.to_json
106
+ expected = '{"name":"Test string","kind":5,"value":1.5,"count":42,"min":1.5,"max":1.5,"stdDev":1.5}'
107
+ assert_equal expected, actual
108
+ end
109
+ end