|
4 | 4 | describe 'defined constants' do |
5 | 5 | it { expect(described_class).to be_const_defined(:INCOMPLETE_CONFIG) } |
6 | 6 | it { expect(described_class).to be_const_defined(:SETTERS) } |
| 7 | + it { expect(described_class).to be_const_defined(:BUILTIN_FIELDS_DEFAULT_NAMES) } |
7 | 8 | end |
8 | 9 |
|
9 | 10 | describe '.new' do |
10 | 11 | let(:custom_formatter) { use_formatter(:custom) } |
11 | 12 | let(:detailed_formatter) { true } |
12 | 13 | let(:service_name) { random_service_name } |
13 | 14 | let(:service_version) { random_semver } |
| 15 | + let(:field_name_level) { random_field_name } |
| 16 | + let(:field_name_time) { random_field_name } |
| 17 | + let(:field_name_message) { random_field_name } |
| 18 | + let(:field_name_context) { random_field_name } |
| 19 | + let(:field_name_exception_message) { random_field_name } |
| 20 | + let(:field_name_exception_stack_trace) { random_field_name } |
14 | 21 |
|
15 | 22 | context 'when valid configuration' do |
16 | 23 | subject(:configuration) do |
17 | 24 | create_configuration( |
18 | 25 | custom_formatter: custom_formatter, |
19 | 26 | detailed_formatter: detailed_formatter, |
20 | 27 | service_name: service_name, |
21 | | - service_version: service_version |
| 28 | + service_version: service_version, |
| 29 | + field_name_level: field_name_level, |
| 30 | + field_name_time: field_name_time, |
| 31 | + field_name_message: field_name_message, |
| 32 | + field_name_context: field_name_context, |
| 33 | + field_name_exception_message: field_name_exception_message, |
| 34 | + field_name_exception_stack_trace: field_name_exception_stack_trace |
22 | 35 | ) |
23 | 36 | end |
24 | 37 |
|
|
27 | 40 | expect(configuration.detailed_formatter).to eq(detailed_formatter) |
28 | 41 | expect(configuration.service_name).to eq(service_name) |
29 | 42 | expect(configuration.service_version).to eq(service_version) |
| 43 | + expect(configuration.field_name_level).to eq(field_name_level) |
| 44 | + expect(configuration.field_name_time).to eq(field_name_time) |
| 45 | + expect(configuration.field_name_message).to eq(field_name_message) |
| 46 | + expect(configuration.field_name_context).to eq(field_name_context) |
| 47 | + expect(configuration.field_name_exception_message).to eq(field_name_exception_message) |
| 48 | + expect(configuration.field_name_exception_stack_trace).to eq(field_name_exception_stack_trace) |
30 | 49 | expect(configuration).to be_complete |
31 | 50 | end |
32 | 51 | end |
|
76 | 95 |
|
77 | 96 | include_examples 'raies argument error' |
78 | 97 | end |
| 98 | + |
| 99 | + OnStrum::Logs::Configuration::SETTERS[3..-1].each do |field_name_setter| |
| 100 | + context "when argument #{field_name_setter}= invalid" do |
| 101 | + subject(:configuration) do |
| 102 | + create_configuration( |
| 103 | + service_name: random_service_name, |
| 104 | + service_version: random_semver, |
| 105 | + field_name_setter => invalid_argument |
| 106 | + ) |
| 107 | + end |
| 108 | + |
| 109 | + let(:expected_error_message) { "#{invalid_argument} is not a valid #{field_name_setter}=" } |
| 110 | + |
| 111 | + include_examples 'raies argument error' |
| 112 | + end |
| 113 | + end |
79 | 114 | end |
80 | 115 |
|
81 | 116 | context 'when configuration without block' do |
|
85 | 120 | expect(configuration.service_name).to be_nil |
86 | 121 | expect(configuration.service_version).to be_nil |
87 | 122 | expect(configuration.custom_formatter).to be_nil |
| 123 | + expect(configuration.field_name_level).to eq(:level) |
| 124 | + expect(configuration.field_name_time).to eq(:time) |
| 125 | + expect(configuration.field_name_message).to eq(:message) |
| 126 | + expect(configuration.field_name_context).to eq(:context) |
| 127 | + expect(configuration.field_name_exception_message).to eq(:message) |
| 128 | + expect(configuration.field_name_exception_stack_trace).to eq(:stack_trace) |
88 | 129 | expect(configuration.detailed_formatter).to be_nil |
89 | 130 | expect(configuration).not_to be_complete |
90 | 131 | end |
|
156 | 197 | include_examples 'returns target formatter' |
157 | 198 | end |
158 | 199 | end |
| 200 | + |
| 201 | + describe '#log_attributes_order' do |
| 202 | + subject(:log_attributes_order) { configuration_instance.log_attributes_order } |
| 203 | + |
| 204 | + let(:configuration_instance) do |
| 205 | + create_configuration( |
| 206 | + field_name_level: random_field_name, |
| 207 | + field_name_time: random_field_name, |
| 208 | + field_name_message: random_field_name, |
| 209 | + field_name_context: random_field_name |
| 210 | + ) |
| 211 | + end |
| 212 | + |
| 213 | + it 'returns log attributes order' do |
| 214 | + expect(log_attributes_order).to eq( |
| 215 | + [ |
| 216 | + configuration_instance.field_name_level, |
| 217 | + configuration_instance.field_name_time, |
| 218 | + configuration_instance.field_name_message, |
| 219 | + configuration_instance.field_name_context, |
| 220 | + :service_name, |
| 221 | + :service_version |
| 222 | + ] |
| 223 | + ) |
| 224 | + end |
| 225 | + end |
159 | 226 | end |
0 commit comments