@@ -15,34 +15,133 @@ class ConfigTest
15
15
FileUtils . mkdir_p ( File . join ( Dir . pwd , 'config' , 'initializers' ) )
16
16
17
17
before do
18
+ @tracing_mode = AppOpticsAPM ::Config [ :tracing_mode ]
19
+ @sample_rate = AppOpticsAPM ::Config [ :sample_rate ]
20
+ @gem_verbose = AppOpticsAPM ::Config [ :verbose ]
21
+
18
22
ENV . delete ( 'APPOPTICS_APM_CONFIG_RUBY' )
23
+ ENV . delete ( 'APPOPTICS_SERVICE_KEY' )
24
+ ENV . delete ( 'APPOPTICS_HOSTNAME_ALIAS' )
25
+ ENV . delete ( 'APPOPTICS_DEBUG_LEVEL' )
26
+ ENV . delete ( 'APPOPTICS_GEM_VERBOSE' )
27
+
28
+ AppOpticsAPM ::Config [ :service_key ] = nil
29
+ AppOpticsAPM ::Config [ :hostname_alias ] = nil
30
+ AppOpticsAPM ::Config [ :debug_level ] = nil
31
+ AppOpticsAPM ::Config [ :verbose ] = nil
32
+
19
33
FileUtils . rm ( @@default_config_path , :force => true )
20
34
FileUtils . rm ( @@rails_config_path , :force => true )
21
35
FileUtils . rm ( @@test_config_path , :force => true )
22
36
end
23
37
24
38
after do
25
- # Set back to always trace mode
26
- AppOpticsAPM ::Config [ :tracing_mode ] = "always"
27
- AppOpticsAPM ::Config [ :sample_rate ] = 1000000
39
+ AppOpticsAPM ::Config [ :tracing_mode ] = @tracing_mode
40
+ AppOpticsAPM ::Config [ :sample_rate ] = @sample_rate
41
+ AppOpticsAPM ::Config [ :verbose ] = @gem_verbose
42
+ FileUtils . rm_f ( @@default_config_path )
28
43
end
29
44
30
45
after ( :all ) do
31
- AppOpticsAPM ::Config [ :tracing_mode ] = "always"
32
- AppOpticsAPM ::Config [ :sample_rate ] = 1000000
33
46
ENV . delete ( 'APPOPTICS_APM_CONFIG_RUBY' )
47
+ ENV . delete ( 'APPOPTICS_SERVICE_KEY' )
48
+ ENV . delete ( 'APPOPTICS_HOSTNAME_ALIAS' )
49
+ ENV . delete ( 'APPOPTICS_DEBUG_LEVEL' )
50
+ ENV . delete ( 'APPOPTICS_GEM_VERBOSE' )
34
51
FileUtils . rm ( @@default_config_path , :force => true )
35
52
FileUtils . rm ( @@rails_config_path , :force => true )
36
53
FileUtils . rm ( @@test_config_path , :force => true )
37
54
end
38
55
56
+ it 'should read the settings from the config file' do
57
+ File . open ( @@default_config_path , 'w' ) do |f |
58
+ f . puts "AppOpticsAPM::Config[:service_key] = '11111111-1111-1111-1111-111111111111:the_service_name'"
59
+ f . puts "AppOpticsAPM::Config[:hostname_alias] = 'my_service'"
60
+ f . puts "AppOpticsAPM::Config[:debug_level] = 6"
61
+ f . puts "AppOpticsAPM::Config[:verbose] = true"
62
+ end
63
+
64
+ AppOpticsAPM ::Config . load_config_file
65
+
66
+ ENV [ 'APPOPTICS_SERVICE_KEY' ] . must_be_nil
67
+ AppOpticsAPM ::Config [ :service_key ] . must_equal '11111111-1111-1111-1111-111111111111:the_service_name'
68
+
69
+ ENV [ 'APPOPTICS_HOSTNAME_ALIAS' ] . must_be_nil
70
+ AppOpticsAPM ::Config [ :hostname_alias ] . must_equal 'my_service'
71
+
72
+ # logging happens in 2 places, oboe and ruby, we translate
73
+ ENV [ 'APPOPTICS_DEBUG_LEVEL' ] . must_be_nil
74
+ AppOpticsAPM ::Config [ :debug_level ] . must_equal 6
75
+ AppOpticsAPM . logger . level . must_equal Logger ::DEBUG
76
+
77
+ ENV [ 'APPOPTICS_GEM_VERBOSE' ] . must_be_nil
78
+ AppOpticsAPM ::Config [ :verbose ] . must_equal true
79
+ end
80
+
81
+ it 'should NOT override env vars with config file settings' do
82
+ ENV [ 'APPOPTICS_SERVICE_KEY' ] = '22222222-2222-2222-2222-222222222222:the_service_name'
83
+ ENV [ 'APPOPTICS_HOSTNAME_ALIAS' ] = 'my_other_service'
84
+ ENV [ 'APPOPTICS_DEBUG_LEVEL' ] = '2'
85
+ ENV [ 'APPOPTICS_GEM_VERBOSE' ] = 'TRUE'
86
+
87
+ File . open ( @@default_config_path , 'w' ) do |f |
88
+ f . puts "AppOpticsAPM::Config[:service_key] = '11111111-1111-1111-1111-111111111111:the_service_name'"
89
+ f . puts "AppOpticsAPM::Config[:hostname_alias] = 'my_service'"
90
+ f . puts "AppOpticsAPM::Config[:debug_level] = 6"
91
+ f . puts "AppOpticsAPM::Config[:verbose] = false"
92
+ end
93
+
94
+ AppOpticsAPM ::Config . load_config_file
95
+
96
+ ENV [ 'APPOPTICS_SERVICE_KEY' ] . must_equal '22222222-2222-2222-2222-222222222222:the_service_name'
97
+ ENV [ 'APPOPTICS_HOSTNAME_ALIAS' ] . must_equal 'my_other_service'
98
+ ENV [ 'APPOPTICS_DEBUG_LEVEL' ] . must_equal '2'
99
+ AppOpticsAPM . logger . level . must_equal Logger ::WARN
100
+ ENV [ 'APPOPTICS_GEM_VERBOSE' ] . must_equal 'TRUE'
101
+ AppOpticsAPM ::Config [ :verbose ] . must_equal true
102
+ end
103
+
104
+ it 'should use default when there is a wrong debug level setting' do
105
+ File . open ( @@default_config_path , 'w' ) do |f |
106
+ f . puts "AppOpticsAPM::Config[:debug_level] = 7"
107
+ end
108
+
109
+ AppOpticsAPM ::Config . load_config_file
110
+
111
+ ENV [ 'APPOPTICS_DEBUG_LEVEL' ] . must_be_nil
112
+ AppOpticsAPM ::Config [ :debug_level ] . must_be_nil
113
+ AppOpticsAPM . logger . level . must_equal Logger ::INFO
114
+ end
115
+
116
+ it "should accept 'true'/'TRUE'/'True'/... as true for VERBOSE" do
117
+ File . open ( @@default_config_path , 'w' ) do |f |
118
+ f . puts "AppOpticsAPM::Config[:verbose] = false"
119
+ end
120
+
121
+ ENV [ 'APPOPTICS_GEM_VERBOSE' ] = 'FALSE'
122
+ AppOpticsAPM ::Config . load_config_file
123
+ AppOpticsAPM ::Config [ :verbose ] . wont_equal true
124
+
125
+ ENV [ 'APPOPTICS_GEM_VERBOSE' ] = 'TRUE'
126
+ AppOpticsAPM ::Config . load_config_file
127
+ AppOpticsAPM ::Config [ :verbose ] . must_equal true
128
+
129
+ ENV [ 'APPOPTICS_GEM_VERBOSE' ] = 'verbose'
130
+ AppOpticsAPM ::Config . load_config_file
131
+ AppOpticsAPM ::Config [ :verbose ] . wont_equal true
132
+
133
+ ENV [ 'APPOPTICS_GEM_VERBOSE' ] = 'True'
134
+ AppOpticsAPM ::Config . load_config_file
135
+ AppOpticsAPM ::Config [ :verbose ] . must_equal true
136
+ end
137
+
39
138
it 'should have the correct instrumentation defaults' do
40
139
# Reset AppOpticsAPM::Config to defaults
41
140
AppOpticsAPM ::Config . initialize
42
141
142
+ AppOpticsAPM ::Config [ :debug_level ] = 3
143
+ AppOpticsAPM ::Config [ :verbose ] . must_equal false
43
144
AppOpticsAPM ::Config [ :tracing_mode ] . must_equal :always
44
- AppOpticsAPM ::Config [ :verbose ] . must_equal ENV . key? ( 'APPOPTICS_GEM_VERBOSE' ) && ENV [ 'APPOPTICS_GEM_VERBOSE' ] == 'true' ? true : false
45
-
46
145
AppOpticsAPM ::Config [ :sanitize_sql ] . must_equal true
47
146
AppOpticsAPM ::Config [ :sanitize_sql_regexp ] . must_equal '(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)'
48
147
AppOpticsAPM ::Config [ :sanitize_sql_opts ] . must_equal Regexp ::IGNORECASE
0 commit comments