statsd-instrument 3.0.0.pre1 → 3.1.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/lint.yml +22 -0
- data/.github/workflows/tests.yml +31 -0
- data/.rubocop.yml +3 -13
- data/CHANGELOG.md +50 -0
- data/Gemfile +8 -2
- data/README.md +6 -3
- data/Rakefile +7 -7
- data/benchmark/send-metrics-to-dev-null-log +12 -11
- data/benchmark/send-metrics-to-local-udp-receiver +16 -15
- data/bin/rake +29 -0
- data/bin/rubocop +29 -0
- data/lib/statsd-instrument.rb +1 -1
- data/lib/statsd/instrument.rb +112 -145
- data/lib/statsd/instrument/assertions.rb +200 -208
- data/lib/statsd/instrument/batched_udp_sink.rb +154 -0
- data/lib/statsd/instrument/capture_sink.rb +23 -19
- data/lib/statsd/instrument/client.rb +410 -306
- data/lib/statsd/instrument/datagram.rb +69 -65
- data/lib/statsd/instrument/datagram_builder.rb +81 -77
- data/lib/statsd/instrument/dogstatsd_datagram.rb +76 -72
- data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +68 -64
- data/lib/statsd/instrument/environment.rb +88 -77
- data/lib/statsd/instrument/expectation.rb +96 -96
- data/lib/statsd/instrument/helpers.rb +11 -7
- data/lib/statsd/instrument/log_sink.rb +20 -16
- data/lib/statsd/instrument/matchers.rb +93 -74
- data/lib/statsd/instrument/null_sink.rb +12 -8
- data/lib/statsd/instrument/railtie.rb +11 -7
- data/lib/statsd/instrument/rubocop.rb +8 -8
- data/lib/statsd/instrument/rubocop/measure_as_dist_argument.rb +1 -1
- data/lib/statsd/instrument/rubocop/metaprogramming_positional_arguments.rb +2 -2
- data/lib/statsd/instrument/rubocop/metric_prefix_argument.rb +1 -1
- data/lib/statsd/instrument/rubocop/metric_return_value.rb +2 -2
- data/lib/statsd/instrument/rubocop/metric_value_keyword_argument.rb +1 -1
- data/lib/statsd/instrument/rubocop/positional_arguments.rb +4 -4
- data/lib/statsd/instrument/rubocop/singleton_configuration.rb +1 -1
- data/lib/statsd/instrument/rubocop/splat_arguments.rb +2 -2
- data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
- data/lib/statsd/instrument/strict.rb +1 -6
- data/lib/statsd/instrument/udp_sink.rb +49 -47
- data/lib/statsd/instrument/version.rb +1 -1
- data/statsd-instrument.gemspec +4 -8
- data/test/assertions_test.rb +205 -161
- data/test/benchmark/clock_gettime.rb +1 -1
- data/test/benchmark/default_tags.rb +9 -9
- data/test/benchmark/metrics.rb +8 -8
- data/test/benchmark/tags.rb +4 -4
- data/test/capture_sink_test.rb +14 -14
- data/test/client_test.rb +96 -96
- data/test/datagram_builder_test.rb +55 -55
- data/test/datagram_test.rb +5 -5
- data/test/dogstatsd_datagram_builder_test.rb +37 -37
- data/test/environment_test.rb +30 -21
- data/test/helpers/rubocop_helper.rb +12 -9
- data/test/helpers_test.rb +15 -15
- data/test/integration_test.rb +7 -7
- data/test/log_sink_test.rb +4 -4
- data/test/matchers_test.rb +54 -54
- data/test/null_sink_test.rb +4 -4
- data/test/rubocop/measure_as_dist_argument_test.rb +2 -2
- data/test/rubocop/metaprogramming_positional_arguments_test.rb +2 -2
- data/test/rubocop/metric_prefix_argument_test.rb +2 -2
- data/test/rubocop/metric_return_value_test.rb +6 -6
- data/test/rubocop/metric_value_keyword_argument_test.rb +3 -3
- data/test/rubocop/positional_arguments_test.rb +12 -12
- data/test/rubocop/singleton_configuration_test.rb +8 -8
- data/test/rubocop/splat_arguments_test.rb +2 -2
- data/test/statsd_datagram_builder_test.rb +6 -6
- data/test/statsd_instrumentation_test.rb +122 -122
- data/test/statsd_test.rb +69 -67
- data/test/test_helper.rb +19 -10
- data/test/udp_sink_test.rb +122 -50
- metadata +12 -92
- data/.github/workflows/ci.yml +0 -56
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
data/test/integration_test.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
class IntegrationTest < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@server = UDPSocket.new
|
8
|
-
@server.bind(
|
8
|
+
@server.bind("localhost", 0)
|
9
9
|
|
10
10
|
@env = StatsD::Instrument::Environment.new(
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
"STATSD_ADDR" => "#{@server.addr[2]}:#{@server.addr[1]}",
|
12
|
+
"STATSD_IMPLEMENTATION" => "dogstatsd",
|
13
|
+
"STATSD_ENV" => "production",
|
14
14
|
)
|
15
15
|
|
16
16
|
@old_client = StatsD.singleton_client
|
@@ -23,7 +23,7 @@ class IntegrationTest < Minitest::Test
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_live_local_udp_socket
|
26
|
-
StatsD.increment(
|
27
|
-
assert_equal
|
26
|
+
StatsD.increment("counter")
|
27
|
+
assert_equal("counter:1|c", @server.recvfrom(100).first)
|
28
28
|
end
|
29
29
|
end
|
data/test/log_sink_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
class LogSinkTest < Minitest::Test
|
6
6
|
def test_log_sink
|
@@ -10,9 +10,9 @@ class LogSinkTest < Minitest::Test
|
|
10
10
|
end
|
11
11
|
|
12
12
|
log_sink = StatsD::Instrument::LogSink.new(logger)
|
13
|
-
log_sink <<
|
13
|
+
log_sink << "foo:1|c" << "bar:1|c"
|
14
14
|
|
15
|
-
assert_equal
|
15
|
+
assert_equal(<<~LOG, log.string)
|
16
16
|
DEBUG: [StatsD] foo:1|c
|
17
17
|
DEBUG: [StatsD] bar:1|c
|
18
18
|
LOG
|
@@ -27,7 +27,7 @@ class LogSinkTest < Minitest::Test
|
|
27
27
|
log_sink = StatsD::Instrument::LogSink.new(logger)
|
28
28
|
log_sink << "foo:1|c\n" << "bar:1|c\n"
|
29
29
|
|
30
|
-
assert_equal
|
30
|
+
assert_equal(<<~LOG, log.string)
|
31
31
|
DEBUG: [StatsD] foo:1|c
|
32
32
|
DEBUG: [StatsD] bar:1|c
|
33
33
|
LOG
|
data/test/matchers_test.rb
CHANGED
@@ -1,116 +1,116 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "statsd/instrument/matchers"
|
5
5
|
|
6
6
|
class MatchersTest < Minitest::Test
|
7
7
|
def test_statsd_increment_matched
|
8
|
-
assert
|
9
|
-
.matches?(lambda { StatsD.increment(
|
8
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", {})
|
9
|
+
.matches?(lambda { StatsD.increment("counter") }))
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_statsd_increment_not_matched
|
13
|
-
refute
|
14
|
-
.matches?(lambda { StatsD.increment(
|
13
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", {})
|
14
|
+
.matches?(lambda { StatsD.increment("not_counter") }))
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_statsd_increment_compound_matched
|
18
|
-
matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c,
|
19
|
-
matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c,
|
18
|
+
matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["a"])
|
19
|
+
matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["b"])
|
20
20
|
|
21
|
-
assert
|
22
|
-
StatsD.increment(
|
23
|
-
StatsD.increment(
|
24
|
-
}
|
21
|
+
assert(RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches?(lambda {
|
22
|
+
StatsD.increment("counter", tags: ["a"])
|
23
|
+
StatsD.increment("counter", tags: ["b"])
|
24
|
+
}))
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_statsd_increment_compound_not_matched
|
28
|
-
matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c,
|
29
|
-
matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c,
|
28
|
+
matcher_1 = StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["a"])
|
29
|
+
matcher_2 = StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["b"])
|
30
30
|
|
31
|
-
refute
|
32
|
-
StatsD.increment(
|
33
|
-
StatsD.increment(
|
34
|
-
}
|
31
|
+
refute(RSpec::Matchers::BuiltIn::Compound::And.new(matcher_1, matcher_2).matches?(lambda {
|
32
|
+
StatsD.increment("counter", tags: ["a"])
|
33
|
+
StatsD.increment("counter", tags: ["a"])
|
34
|
+
}))
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_statsd_increment_with_times_matched
|
38
|
-
assert
|
39
|
-
.matches?(lambda { StatsD.increment(
|
38
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", times: 1)
|
39
|
+
.matches?(lambda { StatsD.increment("counter") }))
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_statsd_increment_with_times_not_matched
|
43
|
-
refute
|
44
|
-
.matches?
|
43
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", times: 2)
|
44
|
+
.matches?(lambda { 3.times { StatsD.increment("counter") } }))
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_statsd_increment_with_sample_rate_matched
|
48
|
-
assert
|
49
|
-
.matches?(lambda { StatsD.increment(
|
48
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", sample_rate: 0.5)
|
49
|
+
.matches?(lambda { StatsD.increment("counter", sample_rate: 0.5) }))
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_statsd_increment_with_sample_rate_not_matched
|
53
|
-
refute
|
54
|
-
.matches?(lambda { StatsD.increment(
|
53
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", sample_rate: 0.5)
|
54
|
+
.matches?(lambda { StatsD.increment("counter", sample_rate: 0.7) }))
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_statsd_increment_with_value_matched
|
58
|
-
assert
|
59
|
-
.matches?(lambda { StatsD.increment(
|
58
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", value: 1)
|
59
|
+
.matches?(lambda { StatsD.increment("counter") }))
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_statsd_increment_with_value_matched_when_multiple_metrics
|
63
|
-
assert
|
64
|
-
StatsD.increment(
|
65
|
-
StatsD.increment(
|
66
|
-
})
|
63
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", value: 1).matches?(lambda {
|
64
|
+
StatsD.increment("counter", 2)
|
65
|
+
StatsD.increment("counter", 1)
|
66
|
+
}))
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_statsd_increment_with_value_not_matched_when_multiple_metrics
|
70
|
-
refute
|
71
|
-
StatsD.increment(
|
72
|
-
StatsD.increment(
|
73
|
-
})
|
70
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", value: 1).matches?(lambda {
|
71
|
+
StatsD.increment("counter", 2)
|
72
|
+
StatsD.increment("counter", 3)
|
73
|
+
}))
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_statsd_increment_with_value_not_matched
|
77
|
-
refute
|
78
|
-
.matches?(lambda { StatsD.increment(
|
77
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", value: 3)
|
78
|
+
.matches?(lambda { StatsD.increment("counter") }))
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_statsd_increment_with_tags_matched
|
82
|
-
assert
|
83
|
-
.matches?(lambda { StatsD.increment(
|
82
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["a", "b"])
|
83
|
+
.matches?(lambda { StatsD.increment("counter", tags: ["a", "b"]) }))
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_statsd_increment_with_tags_not_matched
|
87
|
-
refute
|
88
|
-
.matches?(lambda { StatsD.increment(
|
87
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", tags: ["a", "b"])
|
88
|
+
.matches?(lambda { StatsD.increment("counter", tags: ["c"]) }))
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_statsd_increment_with_times_and_value_matched
|
92
|
-
assert
|
93
|
-
StatsD.increment(
|
94
|
-
StatsD.increment(
|
95
|
-
})
|
92
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", times: 2, value: 1).matches?(lambda {
|
93
|
+
StatsD.increment("counter", 1)
|
94
|
+
StatsD.increment("counter", 1)
|
95
|
+
}))
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_statsd_increment_with_times_and_value_not_matched
|
99
|
-
refute
|
100
|
-
StatsD.increment(
|
101
|
-
StatsD.increment(
|
102
|
-
})
|
99
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", times: 2, value: 1).matches?(lambda {
|
100
|
+
StatsD.increment("counter", 1)
|
101
|
+
StatsD.increment("counter", 2)
|
102
|
+
}))
|
103
103
|
end
|
104
104
|
|
105
105
|
def test_statsd_increment_with_sample_rate_and_argument_matcher_matched
|
106
106
|
between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
|
107
|
-
assert
|
108
|
-
.matches?(lambda { StatsD.increment(
|
107
|
+
assert(StatsD::Instrument::Matchers::Increment.new(:c, "counter", sample_rate: between_matcher)
|
108
|
+
.matches?(lambda { StatsD.increment("counter", sample_rate: 0.5) }))
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_statsd_increment_with_sample_rate_and_argument_matcher_not_matched
|
112
112
|
between_matcher = RSpec::Matchers::BuiltIn::BeBetween.new(0.4, 0.6).inclusive
|
113
|
-
refute
|
114
|
-
.matches?(lambda { StatsD.increment(
|
113
|
+
refute(StatsD::Instrument::Matchers::Increment.new(:c, "counter", sample_rate: between_matcher)
|
114
|
+
.matches?(lambda { StatsD.increment("counter", sample_rate: 0.7) }))
|
115
115
|
end
|
116
116
|
end
|
data/test/null_sink_test.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
class NullSinkTest < Minitest::Test
|
6
6
|
def test_null_sink
|
7
7
|
null_sink = StatsD::Instrument::NullSink.new
|
8
|
-
null_sink <<
|
8
|
+
null_sink << "foo:1|c" << "bar:1|c"
|
9
9
|
pass # We don't have anything to assert, except that no exception was raised
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_null_sink_sample
|
13
13
|
null_sink = StatsD::Instrument::NullSink.new
|
14
|
-
assert
|
15
|
-
assert
|
14
|
+
assert(null_sink.sample?(0), "The null sink should always sample")
|
15
|
+
assert(null_sink.sample?(1), "The null sink should always sample")
|
16
16
|
end
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "statsd/instrument/rubocop"
|
5
5
|
|
6
6
|
module Rubocop
|
7
7
|
class MetricReturnValueTest < Minitest::Test
|
@@ -12,7 +12,7 @@ module Rubocop
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_ok_for_non_metric_method
|
15
|
-
assert_no_offenses(
|
15
|
+
assert_no_offenses("backend = StatsD.backend")
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_ok_as_naked_statement
|
@@ -21,14 +21,14 @@ module Rubocop
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_ok_as_multiple_statement
|
24
|
-
assert_no_offenses
|
24
|
+
assert_no_offenses(<<~RUBY)
|
25
25
|
StatsD.increment 'foo'
|
26
26
|
StatsD.increment 'bar'
|
27
27
|
RUBY
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_ok_inside_block
|
31
|
-
assert_no_offenses
|
31
|
+
assert_no_offenses(<<~RUBY)
|
32
32
|
block do
|
33
33
|
StatsD.measure
|
34
34
|
end
|
@@ -44,7 +44,7 @@ module Rubocop
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_ok_when_passing_do_end_block
|
47
|
-
assert_no_offenses
|
47
|
+
assert_no_offenses(<<~RUBY)
|
48
48
|
block_result = StatsD.measure('foo') do
|
49
49
|
return_something_useful
|
50
50
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "statsd/instrument/rubocop"
|
5
5
|
|
6
6
|
module Rubocop
|
7
7
|
class MetricValueKeywordArgumentTest < Minitest::Test
|
@@ -31,7 +31,7 @@ module Rubocop
|
|
31
31
|
def test_offense_with_value_keyword
|
32
32
|
assert_offense("StatsD.increment('foo', value: 1)")
|
33
33
|
assert_offense("StatsD.increment('foo', :value => 1)")
|
34
|
-
assert_offense("StatsD.increment('foo', 'value' => 1)")
|
34
|
+
# assert_offense("StatsD.increment('foo', 'value' => 1)")
|
35
35
|
assert_offense("StatsD.increment('foo', sample_rate: 0.1, value: 1, tags: ['foo'])")
|
36
36
|
assert_offense("StatsD.increment('foo', value: 1, &block)")
|
37
37
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "statsd/instrument/rubocop"
|
5
5
|
|
6
6
|
module Rubocop
|
7
7
|
class PositionalArgumentsTest < Minitest::Test
|
@@ -51,47 +51,47 @@ module Rubocop
|
|
51
51
|
|
52
52
|
def test_autocorrect_only_sample_rate
|
53
53
|
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5)")
|
54
|
-
assert_equal
|
54
|
+
assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5)", corrected)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_autocorrect_only_sample_rate_as_int
|
58
58
|
corrected = autocorrect_source("StatsD.increment('foo', 2, 1)")
|
59
|
-
assert_equal
|
59
|
+
assert_equal("StatsD.increment('foo', 2, sample_rate: 1)", corrected)
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_autocorrect_only_tags
|
63
63
|
corrected = autocorrect_source("StatsD.increment('foo', 2, nil, ['foo', 'bar'])")
|
64
|
-
assert_equal
|
64
|
+
assert_equal("StatsD.increment('foo', 2, tags: ['foo', 'bar'])", corrected)
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_autocorrect_sample_rate_and_tags_as_array
|
68
68
|
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, ['foo', 'bar'])")
|
69
|
-
assert_equal
|
69
|
+
assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5, tags: ['foo', 'bar'])", corrected)
|
70
70
|
end
|
71
71
|
|
72
72
|
def test_autocorrect_sample_rate_and_tags_as_hash_with_curly_braces
|
73
73
|
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, { foo: 'bar' })")
|
74
|
-
assert_equal
|
74
|
+
assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected)
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_autocorrect_sample_rate_and_tags_as_hash_without_curly_braces
|
78
78
|
corrected = autocorrect_source("StatsD.increment('foo', 2, 0.5, foo: 'bar')")
|
79
|
-
assert_equal
|
79
|
+
assert_equal("StatsD.increment('foo', 2, sample_rate: 0.5, tags: { foo: 'bar' })", corrected)
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_autocorrect_sample_rate_and_block_pass
|
83
83
|
corrected = autocorrect_source("StatsD.distribution('foo', 2, 0.5, &block)")
|
84
|
-
assert_equal
|
84
|
+
assert_equal("StatsD.distribution('foo', 2, sample_rate: 0.5, &block)", corrected)
|
85
85
|
end
|
86
86
|
|
87
87
|
def test_autocorrect_sample_rate_tags_and_block_pass
|
88
88
|
corrected = autocorrect_source("StatsD.measure('foo', 2, nil, foo: 'bar', &block)")
|
89
|
-
assert_equal
|
89
|
+
assert_equal("StatsD.measure('foo', 2, tags: { foo: 'bar' }, &block)", corrected)
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_autocorrect_sample_rate_and_curly_braces_block
|
93
93
|
corrected = autocorrect_source("StatsD.measure('foo', 2, 0.5) { foo }")
|
94
|
-
assert_equal
|
94
|
+
assert_equal("StatsD.measure('foo', 2, sample_rate: 0.5) { foo }", corrected)
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_autocorrect_sample_rate_and_do_end_block
|
@@ -100,7 +100,7 @@ module Rubocop
|
|
100
100
|
foo
|
101
101
|
end
|
102
102
|
RUBY
|
103
|
-
assert_equal
|
103
|
+
assert_equal(<<~RUBY, corrected)
|
104
104
|
StatsD.distribution 'foo', 124, sample_rate: 0.6, tags: ['bar'] do
|
105
105
|
foo
|
106
106
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "statsd/instrument/rubocop"
|
5
5
|
|
6
6
|
module Rubocop
|
7
7
|
class SingletonConfigurationTest < Minitest::Test
|
@@ -13,7 +13,7 @@ module Rubocop
|
|
13
13
|
|
14
14
|
def test_offense_statsd_backend
|
15
15
|
assert_offense('StatsD.backend = "foo"')
|
16
|
-
assert_offense(
|
16
|
+
assert_offense("old_backend = StatsD.backend")
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_offense_statsd_prefix
|
@@ -23,21 +23,21 @@ module Rubocop
|
|
23
23
|
|
24
24
|
def test_offense_statsd_default_tags
|
25
25
|
assert_offense('StatsD.default_tags = ["foo"]')
|
26
|
-
assert_offense(
|
26
|
+
assert_offense("StatsD.default_tags.empty?")
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_offense_statsd_default_sample_rate
|
30
|
-
assert_offense(
|
31
|
-
assert_offense(
|
30
|
+
assert_offense("StatsD.default_sample_rate = 1.0")
|
31
|
+
assert_offense("should_sample = StatsD.default_sample_rate > rand")
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_no_offense_for_other_methods
|
35
|
-
assert_no_offenses(
|
35
|
+
assert_no_offenses("StatsD.singleton_client = my_client")
|
36
36
|
assert_no_offenses('StatsD.logger.info("foo")')
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_no_offense_for_constant_reference
|
40
|
-
assert_no_offenses(
|
40
|
+
assert_no_offenses("legacy_client = StatsD")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|