twiglet 3.14.2 → 3.15.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/lib/twiglet/version.rb +1 -1
- metadata +42 -38
- data/.github/CODEOWNERS +0 -4
- data/.github/dependabot.yml +0 -22
- data/.github/workflows/codeql-analysis.yml +0 -70
- data/.github/workflows/dobby-actions.yml +0 -28
- data/.github/workflows/gem-publish.yml +0 -46
- data/.github/workflows/ruby.yml +0 -38
- data/.github/workflows/version-forget-me-not.yml +0 -19
- data/.gitignore +0 -58
- data/.rubocop.yml +0 -14
- data/.ruby-version +0 -1
- data/Gemfile +0 -5
- data/Rakefile +0 -7
- data/catalog-info.yaml +0 -15
- data/docs/CODE_OF_CONDUCT.md +0 -76
- data/docs/RATIONALE.md +0 -90
- data/docs/index.md +0 -256
- data/example_app.rb +0 -60
- data/examples/rack/example_rack_app.rb +0 -17
- data/examples/rack/request_logger.rb +0 -66
- data/examples/rack/request_logger_test.rb +0 -91
- data/test/error_serialiser_test.rb +0 -18
- data/test/formatter_test.rb +0 -89
- data/test/hash_extensions_test.rb +0 -133
- data/test/logger_test.rb +0 -751
- data/test/message_test.rb +0 -13
- data/test/test_coverage.rb +0 -17
- data/test/validator_test.rb +0 -38
- data/twiglet.gemspec +0 -29
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'minitest/autorun'
|
|
4
|
-
require_relative '../lib/hash_extensions'
|
|
5
|
-
|
|
6
|
-
describe HashExtensions do
|
|
7
|
-
before do
|
|
8
|
-
Hash.include HashExtensions
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it 'should retain an object without . in any keys' do
|
|
12
|
-
actual = {
|
|
13
|
-
message: 'Out of pets exception',
|
|
14
|
-
service: {
|
|
15
|
-
name: 'petshop'
|
|
16
|
-
},
|
|
17
|
-
log: {
|
|
18
|
-
level: 'error'
|
|
19
|
-
},
|
|
20
|
-
'@timestamp': '2020-05-09T15:13:20.736Z'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
expected = actual.to_nested
|
|
24
|
-
assert_equal actual, expected
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'should convert keys with . into nested objects' do
|
|
28
|
-
actual = {
|
|
29
|
-
'service.name': 'petshop',
|
|
30
|
-
'log.level': 'error'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
nested = actual.to_nested
|
|
34
|
-
|
|
35
|
-
assert_equal 'petshop', nested[:service][:name]
|
|
36
|
-
assert_equal 'error', nested[:log][:level]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'should group nested objects' do
|
|
40
|
-
actual = {
|
|
41
|
-
'service.name': 'petshop',
|
|
42
|
-
'service.id': 'ps001',
|
|
43
|
-
'service.version': '0.9.1',
|
|
44
|
-
'log.level': 'error'
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
nested = actual.to_nested
|
|
48
|
-
|
|
49
|
-
assert_equal 'petshop', nested[:service][:name]
|
|
50
|
-
assert_equal 'ps001', nested[:service][:id]
|
|
51
|
-
assert_equal '0.9.1', nested[:service][:version]
|
|
52
|
-
assert_equal 'error', nested[:log][:level]
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'should cope with more than two levels' do
|
|
56
|
-
actual = {
|
|
57
|
-
'http.request.method': 'get',
|
|
58
|
-
'http.request.body.bytes': 112,
|
|
59
|
-
'http.response.bytes': 1564,
|
|
60
|
-
'http.response.status_code': 200
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
nested = actual.to_nested
|
|
64
|
-
|
|
65
|
-
assert_equal 'get', nested[:http][:request][:method]
|
|
66
|
-
assert_equal 112, nested[:http][:request][:body][:bytes]
|
|
67
|
-
assert_equal 1564, nested[:http][:response][:bytes]
|
|
68
|
-
assert_equal 200, nested[:http][:response][:status_code]
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it '#deep_merge() should work with two hashes without common keys' do
|
|
72
|
-
first = { id: 1, name: 'petshop' }
|
|
73
|
-
second = { level: 'debug', code: 5 }
|
|
74
|
-
|
|
75
|
-
actual = first.deep_merge(second)
|
|
76
|
-
|
|
77
|
-
assert_equal 1, actual[:id]
|
|
78
|
-
assert_equal 'petshop', actual[:name]
|
|
79
|
-
assert_equal 'debug', actual[:level]
|
|
80
|
-
assert_equal 5, actual[:code]
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it '#deep_merge() should use the second value for shared keys' do
|
|
84
|
-
first = { id: 1, name: 'petshop', level: 'debug' }
|
|
85
|
-
second = { name: 'petstore', level: 'error', code: 5 }
|
|
86
|
-
|
|
87
|
-
actual = first.deep_merge(second)
|
|
88
|
-
|
|
89
|
-
assert_equal 1, actual[:id]
|
|
90
|
-
assert_equal 'petstore', actual[:name]
|
|
91
|
-
assert_equal 'error', actual[:level]
|
|
92
|
-
assert_equal 5, actual[:code]
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it '#deep_merge() should merge two sub-keys' do
|
|
96
|
-
first = { service: { name: 'petshop' } }
|
|
97
|
-
second = { service: { id: 'ps001' } }
|
|
98
|
-
|
|
99
|
-
actual = first.deep_merge(second)
|
|
100
|
-
assert_equal 'petshop', actual[:service][:name]
|
|
101
|
-
assert_equal 'ps001', actual[:service][:id]
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it '#deep_merge() should merge sub-keys in more than 2 levels' do
|
|
105
|
-
first = { http: { request: { method: 'get', bytes: 124 } } }
|
|
106
|
-
second = { http: { response: { status_code: 200, bytes: 5001 } } }
|
|
107
|
-
|
|
108
|
-
actual = first.deep_merge(second)
|
|
109
|
-
|
|
110
|
-
assert_equal 'get', actual[:http][:request][:method]
|
|
111
|
-
assert_equal 124, actual[:http][:request][:bytes]
|
|
112
|
-
assert_equal 200, actual[:http][:response][:status_code]
|
|
113
|
-
assert_equal 5001, actual[:http][:response][:bytes]
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it '#deep_merge() should work when the first key is empty' do
|
|
117
|
-
first = {}
|
|
118
|
-
second = { id: 1 }
|
|
119
|
-
|
|
120
|
-
actual = first.deep_merge(second)
|
|
121
|
-
|
|
122
|
-
assert_equal 1, actual[:id]
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it '#deep_merge() should work when the second key is empty' do
|
|
126
|
-
first = { id: 1 }
|
|
127
|
-
second = {}
|
|
128
|
-
|
|
129
|
-
actual = first.deep_merge(second)
|
|
130
|
-
|
|
131
|
-
assert_equal 1, actual[:id]
|
|
132
|
-
end
|
|
133
|
-
end
|