tengine_support 0.3.27 → 1.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.
- data/Gemfile +3 -20
- data/lib/tengine/support/core_ext/enumerable/map_to_hash.rb +20 -0
- data/lib/tengine/support/mongoid.rb +59 -0
- data/lib/tengine/support/null_logger.rb +1 -1
- data/lib/tengine/support.rb +4 -3
- metadata +80 -76
- data/.document +0 -5
- data/.rspec +0 -1
- data/.travis.yml +0 -11
- data/NULL +0 -1
- data/Rakefile +0 -43
- data/VERSION +0 -1
- data/gemfiles/Gemfile.activesupport-3.0.10 +0 -24
- data/gemfiles/Gemfile.activesupport-3.1.1 +0 -24
- data/gemfiles/Gemfile.activesupport-3.2.3 +0 -24
- data/spec/spec_helper.rb +0 -15
- data/spec/support/app1.rb +0 -27
- data/spec/support/suite.rb +0 -182
- data/spec/tengine/support/config/amqp_spec.rb +0 -32
- data/spec/tengine/support/config/logger_spec.rb +0 -316
- data/spec/tengine/support/config/mongoid_spec.rb +0 -24
- data/spec/tengine/support/config_spec/dump_skelton_spec.rb +0 -171
- data/spec/tengine/support/config_spec/load_config_file_by_config_option_spec.rb +0 -94
- data/spec/tengine/support/config_spec/load_spec.rb +0 -239
- data/spec/tengine/support/config_spec/load_spec_01.yml.erb +0 -43
- data/spec/tengine/support/config_spec/load_spec_01_with_other_settings.yml.erb +0 -48
- data/spec/tengine/support/config_spec/load_spec_02.yml.erb +0 -52
- data/spec/tengine/support/config_spec/parse_spec.rb +0 -178
- data/spec/tengine/support/config_spec.rb +0 -217
- data/spec/tengine/support/core_ext/array/deep_dup_spec.rb +0 -69
- data/spec/tengine/support/core_ext/enumerable/deep_freeze_spec.rb +0 -16
- data/spec/tengine/support/core_ext/enumerable/each_next_tick_spec.rb +0 -29
- data/spec/tengine/support/core_ext/hash/compact_spec.rb +0 -28
- data/spec/tengine/support/core_ext/hash/deep_dup_spec.rb +0 -66
- data/spec/tengine/support/core_ext/hash/keys_spec.rb +0 -88
- data/spec/tengine/support/mongoid_spec.rb +0 -36
- data/spec/tengine/support/null_logger_spec.rb +0 -13
- data/spec/tengine/support/yaml_with_erb_spec/test1.yml.erb +0 -2
- data/spec/tengine/support/yaml_with_erb_spec/test2_with_erb.yml +0 -2
- data/spec/tengine/support/yaml_with_erb_spec/test3_without_erb.yml +0 -2
- data/spec/tengine/support/yaml_with_erb_spec/test4_with_invalid_erb.yml +0 -2
- data/spec/tengine/support/yaml_with_erb_spec.rb +0 -76
- data/tengine_support.gemspec +0 -125
data/spec/support/suite.rb
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
def build_suite1
|
3
|
-
Tengine::Support::Config.suite do
|
4
|
-
banner <<EOS
|
5
|
-
Usage: config_test [-k action] [-f path_to_config]
|
6
|
-
[-H db_host] [-P db_port] [-U db_user] [-S db_pass] [-B db_database]
|
7
|
-
|
8
|
-
EOS
|
9
|
-
|
10
|
-
field(:action, "test|load|start|enable|stop|force-stop|status|activate", :type => :string, :default => "start")
|
11
|
-
load_config(:config, "path/to/config_file", :type => :string)
|
12
|
-
add(:process, App1::ProcessConfig)
|
13
|
-
add(:db, Tengine::Support::Config::Mongoid::Connection, :defaults => {:database => "tengine_production"})
|
14
|
-
group(:event_queue, :hidden => true) do
|
15
|
-
add(:connection, Tengine::Support::Config::Amqp::Connection)
|
16
|
-
add(:exchange , Tengine::Support::Config::Amqp::Exchange, :defaults => {:name => 'tengine_event_exchange'})
|
17
|
-
add(:queue , Tengine::Support::Config::Amqp::Queue , :defaults => {:name => 'tengine_event_queue'})
|
18
|
-
end
|
19
|
-
hide_about_rotation = proc do
|
20
|
-
find(:rotation).hidden = true; find(:rotation_size).hidden = true
|
21
|
-
end
|
22
|
-
add(:log_common, Tengine::Support::Config::Logger,
|
23
|
-
:defaults => {
|
24
|
-
:rotation => 3 ,
|
25
|
-
:rotation_size => 1024 * 1024,
|
26
|
-
:level => 'info' ,
|
27
|
-
}, &hide_about_rotation)
|
28
|
-
add(:application_log, App1::LoggerConfig,
|
29
|
-
:parameters => { :logger_name => "application" },
|
30
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,}, &hide_about_rotation)
|
31
|
-
add(:process_stdout_log, App1::LoggerConfig,
|
32
|
-
:parameters => { :logger_name => proc{ "#{File.basename(__FILE__, '.*')}_stdout"} },
|
33
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,}, &hide_about_rotation)
|
34
|
-
add(:process_stderr_log, App1::LoggerConfig,
|
35
|
-
:parameters => { :logger_name => "#{File.basename(__FILE__, '.*')}_stderr" },
|
36
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,}, &hide_about_rotation)
|
37
|
-
ignore(:app2_settings, :app3_settings)
|
38
|
-
separator("\nGeneral:")
|
39
|
-
__action__(:version, "show version"){ STDOUT.puts "1.1.1"; exit }
|
40
|
-
__action__(:dump_skelton, "dump skelton of config"){ STDOUT.puts YAML.dump(root.to_hash); exit }
|
41
|
-
__action__(:help , "show this help message"){ STDOUT.puts option_parser.help; exit }
|
42
|
-
|
43
|
-
mapping({
|
44
|
-
[:action] => :k,
|
45
|
-
[:config] => :f,
|
46
|
-
[:process, :daemon] => :D,
|
47
|
-
[:db, :host] => :O,
|
48
|
-
[:db, :port] => :P,
|
49
|
-
[:db, :username] => :U,
|
50
|
-
[:db, :password] => :S,
|
51
|
-
})
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
# build_suite1 との違いは、:dbが Tengine::Support::Config::Mongoid::Connectionではなくて、
|
57
|
-
# 単なるhashのfieldとして定義している点と ignore(:app2_settings, :app3_settings) の定義がない点です。
|
58
|
-
def build_suite2
|
59
|
-
Tengine::Support::Config.suite do
|
60
|
-
banner <<EOS
|
61
|
-
Usage: config_test [-k action] [-f path_to_config]
|
62
|
-
[-H db_host] [-P db_port] [-U db_user] [-S db_pass] [-B db_database]
|
63
|
-
|
64
|
-
EOS
|
65
|
-
|
66
|
-
field(:action, "test|load|start|enable|stop|force-stop|status|activate", :type => :string, :default => "start")
|
67
|
-
load_config(:config, "path/to/config_file", :type => :string)
|
68
|
-
add(:process, App1::ProcessConfig)
|
69
|
-
field(:db, "settings to connect to db", :type => :hash, :default => {
|
70
|
-
:host => 'localhost',
|
71
|
-
:port => 27017,
|
72
|
-
:username => nil,
|
73
|
-
:password => nil,
|
74
|
-
:database => 'tengine_production',
|
75
|
-
})
|
76
|
-
group(:event_queue, :hidden => true) do
|
77
|
-
add(:connection, Tengine::Support::Config::Amqp::Connection)
|
78
|
-
add(:exchange , Tengine::Support::Config::Amqp::Exchange, :defaults => {:name => 'tengine_event_exchange'})
|
79
|
-
add(:queue , Tengine::Support::Config::Amqp::Queue , :defaults => {:name => 'tengine_event_queue'})
|
80
|
-
end
|
81
|
-
add(:log_common, Tengine::Support::Config::Logger,
|
82
|
-
:defaults => {
|
83
|
-
:rotation => 3 ,
|
84
|
-
:rotation_size => 1024 * 1024,
|
85
|
-
:level => 'info' ,
|
86
|
-
})
|
87
|
-
add(:application_log, App1::LoggerConfig,
|
88
|
-
:logger_name => "application",
|
89
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,})
|
90
|
-
add(:process_stdout_log, App1::LoggerConfig,
|
91
|
-
:logger_name => "#{File.basename($PROGRAM_NAME)}_stdout",
|
92
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,})
|
93
|
-
add(:process_stderr_log, App1::LoggerConfig,
|
94
|
-
:logger_name => "#{File.basename($PROGRAM_NAME)}_stderr",
|
95
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,})
|
96
|
-
separator("\nGeneral:")
|
97
|
-
__action__(:version, "show version"){ STDOUT.puts "1.1.1"; exit }
|
98
|
-
__action__(:dump_skelton, "dump skelton of config"){ STDOUT.puts YAML.dump(root.to_hash); exit }
|
99
|
-
__action__(:help , "show this help message"){ STDOUT.puts option_parser.help; exit }
|
100
|
-
|
101
|
-
mapping({
|
102
|
-
[:action] => :k,
|
103
|
-
[:config] => :f,
|
104
|
-
[:process, :daemon] => :D,
|
105
|
-
[:db, :host] => :O,
|
106
|
-
[:db, :port] => :P,
|
107
|
-
[:db, :username] => :U,
|
108
|
-
[:db, :password] => :S,
|
109
|
-
})
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
# build_suite2 との違いは、Tengine::Support::Config::Definition::Suiteを直接newするのではなく
|
118
|
-
# 継承したものをnewしている点です。それ以外は変わりません
|
119
|
-
def build_suite3(*args)
|
120
|
-
ConfigSuite3.new(*args)
|
121
|
-
end
|
122
|
-
|
123
|
-
class ConfigSuite3 < Tengine::Support::Config::Definition::Suite
|
124
|
-
def build
|
125
|
-
banner <<EOS
|
126
|
-
Usage: config_test [-k action] [-f path_to_config]
|
127
|
-
[-H db_host] [-P db_port] [-U db_user] [-S db_pass] [-B db_database]
|
128
|
-
|
129
|
-
EOS
|
130
|
-
|
131
|
-
field(:action, "test|load|start|enable|stop|force-stop|status|activate", :type => :string, :default => "start")
|
132
|
-
load_config(:config, "path/to/config_file", :type => :string)
|
133
|
-
add(:process, App1::ProcessConfig)
|
134
|
-
# field(:db, "settings to connect to db", :type => :hash,
|
135
|
-
# :default => {:database => "tengine_production"})
|
136
|
-
field(:db, "settings to connect to db", :type => :hash, :default => {
|
137
|
-
:host => 'localhost',
|
138
|
-
:port => 27017,
|
139
|
-
:username => nil,
|
140
|
-
:password => nil,
|
141
|
-
:database => 'tengine_production',
|
142
|
-
})
|
143
|
-
group(:event_queue, :hidden => true) do
|
144
|
-
add(:connection, Tengine::Support::Config::Amqp::Connection)
|
145
|
-
add(:exchange , Tengine::Support::Config::Amqp::Exchange, :defaults => {:name => 'tengine_event_exchange'})
|
146
|
-
add(:queue , Tengine::Support::Config::Amqp::Queue , :defaults => {:name => 'tengine_event_queue'})
|
147
|
-
end
|
148
|
-
hide_about_rotation = proc do
|
149
|
-
find(:rotation).hidden = true; find(:rotation_size).hidden = true
|
150
|
-
end
|
151
|
-
add(:log_common, Tengine::Support::Config::Logger,
|
152
|
-
:defaults => {
|
153
|
-
:rotation => 3 ,
|
154
|
-
:rotation_size => 1024 * 1024,
|
155
|
-
:level => 'info' ,
|
156
|
-
}, &hide_about_rotation)
|
157
|
-
add(:application_log, App1::LoggerConfig,
|
158
|
-
:logger_name => "application",
|
159
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,}, &hide_about_rotation)
|
160
|
-
add(:process_stdout_log, App1::LoggerConfig,
|
161
|
-
:logger_name => "#{File.basename($PROGRAM_NAME)}_stdout",
|
162
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,}, &hide_about_rotation)
|
163
|
-
add(:process_stderr_log, App1::LoggerConfig,
|
164
|
-
:logger_name => "#{File.basename($PROGRAM_NAME)}_stderr",
|
165
|
-
:dependencies => { :process_config => :process, :log_common => :log_common,}, &hide_about_rotation)
|
166
|
-
separator("\nGeneral:")
|
167
|
-
__action__(:version, "show version"){ STDOUT.puts "1.1.1"; exit }
|
168
|
-
__action__(:dump_skelton, "dump skelton of config"){ STDOUT.puts YAML.dump(root.to_hash); exit }
|
169
|
-
__action__(:help , "show this help message"){ STDOUT.puts option_parser.help; exit }
|
170
|
-
|
171
|
-
mapping({
|
172
|
-
[:action] => :k,
|
173
|
-
[:config] => :f,
|
174
|
-
[:process, :daemon] => :D,
|
175
|
-
[:db, :host] => :O,
|
176
|
-
[:db, :port] => :P,
|
177
|
-
[:db, :username] => :U,
|
178
|
-
[:db, :password] => :S,
|
179
|
-
})
|
180
|
-
|
181
|
-
end
|
182
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
3
|
-
|
4
|
-
describe 'Tengine::Support::Config::Amqp' do
|
5
|
-
|
6
|
-
context "static" do
|
7
|
-
describe Tengine::Support::Config::Amqp::Connection.host do
|
8
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
9
|
-
its(:type){ should == :string }
|
10
|
-
its(:__name__){ should == :host }
|
11
|
-
its(:description){ should == 'hostname to connect queue.'}
|
12
|
-
its(:default){ should == 'localhost'}
|
13
|
-
end
|
14
|
-
|
15
|
-
describe Tengine::Support::Config::Amqp::Connection.port do
|
16
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
17
|
-
its(:type){ should == :integer }
|
18
|
-
its(:__name__){ should == :port }
|
19
|
-
its(:description){ should == 'port to connect queue.'}
|
20
|
-
its(:default){ should == 5672}
|
21
|
-
end
|
22
|
-
|
23
|
-
describe Tengine::Support::Config::Amqp::Connection.heartbeat_interval do
|
24
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
25
|
-
its(:type){ should == :integer }
|
26
|
-
its(:__name__){ should == :heartbeat_interval }
|
27
|
-
its(:description){ should == 'heartbeat interval client uses, in seconds.'}
|
28
|
-
its(:default){ should == 0}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,316 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
3
|
-
|
4
|
-
require 'logger'
|
5
|
-
require 'tempfile'
|
6
|
-
require 'active_support/core_ext/logger'
|
7
|
-
|
8
|
-
describe 'Tengine::Support::Config::Logger' do
|
9
|
-
|
10
|
-
context "static" do
|
11
|
-
describe Tengine::Support::Config::Logger.output do
|
12
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
13
|
-
its(:type){ should == :string }
|
14
|
-
its(:__name__){ should == :output }
|
15
|
-
its(:description){ should == 'file path or "STDOUT" / "STDERR" / "NULL".'}
|
16
|
-
its(:default){ should == "STDOUT"}
|
17
|
-
end
|
18
|
-
|
19
|
-
describe Tengine::Support::Config::Logger.rotation do
|
20
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
21
|
-
its(:type){ should == nil} # 文字列か整数値なので指定していません
|
22
|
-
its(:__name__){ should == :rotation }
|
23
|
-
its(:description){ should == 'rotation file count or daily,weekly,monthly.'}
|
24
|
-
its(:default){ should == nil}
|
25
|
-
end
|
26
|
-
|
27
|
-
describe Tengine::Support::Config::Logger.rotation_size do
|
28
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
29
|
-
its(:type){ should == :integer }
|
30
|
-
its(:__name__){ should == :rotation_size }
|
31
|
-
its(:description){ should == 'number of max log file size.'}
|
32
|
-
its(:default){ should == nil}
|
33
|
-
end
|
34
|
-
|
35
|
-
describe Tengine::Support::Config::Logger.level do
|
36
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
37
|
-
its(:type){ should == :string }
|
38
|
-
its(:__name__){ should == :level }
|
39
|
-
its(:description){ should == 'Logging severity threshold.'}
|
40
|
-
its(:enum){ should == %w[debug info warn error fatal]}
|
41
|
-
its(:default){ should == "info"}
|
42
|
-
end
|
43
|
-
|
44
|
-
describe Tengine::Support::Config::Logger.progname do
|
45
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
46
|
-
its(:type){ should == :string }
|
47
|
-
its(:__name__){ should == :progname }
|
48
|
-
its(:description){ should == 'program name to include in log messages.'}
|
49
|
-
its(:default){ should == nil}
|
50
|
-
end
|
51
|
-
|
52
|
-
describe Tengine::Support::Config::Logger.datetime_format do
|
53
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
54
|
-
its(:type){ should == :string }
|
55
|
-
its(:__name__){ should == :datetime_format }
|
56
|
-
its(:description){ should == 'A string suitable for passing to strftime.'}
|
57
|
-
its(:default){ should == nil}
|
58
|
-
end
|
59
|
-
|
60
|
-
# describe Tengine::Support::Config::Logger.formatter do
|
61
|
-
# it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
62
|
-
# its(:type){ should == :proc }
|
63
|
-
# its(:__name__){ should == :formatter }
|
64
|
-
# its(:description){ should == 'Logging formatter, as a Proc that will take four arguments and return the formatted message.'}
|
65
|
-
# its(:default){ should == nil}
|
66
|
-
# end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "デフォルト値" do
|
70
|
-
context "instantiate_childrenなし" do
|
71
|
-
subject{ Tengine::Support::Config::Logger.new }
|
72
|
-
its(:output){ should == nil }
|
73
|
-
its(:rotation){ should == nil}
|
74
|
-
its(:rotation_size){ should == nil}
|
75
|
-
its(:level){ should == nil}
|
76
|
-
its(:datetime_format){ should == nil}
|
77
|
-
its(:formatter){ should == nil}
|
78
|
-
its(:progname){ should == nil}
|
79
|
-
end
|
80
|
-
|
81
|
-
context "instantiate_childrenあり" do
|
82
|
-
subject{ Tengine::Support::Config::Logger.new.instantiate_children }
|
83
|
-
its(:output){ should == "STDOUT" }
|
84
|
-
its(:rotation){ should == nil}
|
85
|
-
its(:rotation_size){ should == nil}
|
86
|
-
its(:level){ should == "info"}
|
87
|
-
its(:datetime_format){ should == nil}
|
88
|
-
its(:formatter){ should == nil}
|
89
|
-
its(:progname){ should == nil}
|
90
|
-
end
|
91
|
-
|
92
|
-
describe :level do
|
93
|
-
subject{ Tengine::Support::Config::Logger.new.instantiate_children }
|
94
|
-
|
95
|
-
it "nilが明示的に指定されてもデフォルト値になる" do
|
96
|
-
subject.level = nil
|
97
|
-
subject.level.should == 'info'
|
98
|
-
end
|
99
|
-
|
100
|
-
%w[debug info warn error fatal].each do |name|
|
101
|
-
it "#{name}を設定することができる" do
|
102
|
-
subject.level = name
|
103
|
-
subject.level.should == name
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
%w[invalid_name DEBUG inf err].each do |name|
|
108
|
-
it "#{name}は設定することができない" do
|
109
|
-
expect{
|
110
|
-
subject.level = name
|
111
|
-
}.to raise_error(ArgumentError)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe :rotation do
|
117
|
-
subject{ Tengine::Support::Config::Logger.new.instantiate_children }
|
118
|
-
|
119
|
-
["daily", "weekly", "monthly", :daily, 2, 8].each do |value|
|
120
|
-
it "#{value}を設定することができる(変換なし)" do
|
121
|
-
subject.rotation = value
|
122
|
-
subject.rotation.should == value
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
["1", "100"].each do |value|
|
127
|
-
it "#{value}を設定することができる(変換あり)" do
|
128
|
-
subject.rotation = value
|
129
|
-
subject.rotation.should == value.to_i
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
['invalid_rotation', true, false].each do |value|
|
134
|
-
it "#{value}は設定することができない" do
|
135
|
-
expect{
|
136
|
-
subject.rotation = value
|
137
|
-
}.to raise_error(ArgumentError)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
describe :output do
|
144
|
-
subject{ Tengine::Support::Config::Logger.new.instantiate_children }
|
145
|
-
|
146
|
-
%w[STDOUT STDERR NULL].each do |value|
|
147
|
-
it "#{value}を設定することができる" do
|
148
|
-
subject.output = value
|
149
|
-
subject.output.should == value
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
it "存在するディレクトリのファイル" do
|
154
|
-
path = File.expand_path("unexist.log", File.dirname(__FILE__))
|
155
|
-
subject.output = path
|
156
|
-
subject.output.should == path
|
157
|
-
end
|
158
|
-
|
159
|
-
it "存在しないディレクトリのファイル" do
|
160
|
-
expect{
|
161
|
-
subject.output = "/unexist/dir/foo.log"
|
162
|
-
}.to raise_error(ArgumentError)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
describe :new_logger do
|
169
|
-
context "デフォルトの場合" do
|
170
|
-
subject{ Tengine::Support::Config::Logger.new.instantiate_children.new_logger }
|
171
|
-
its(:datetime_format){ should == nil}
|
172
|
-
|
173
|
-
require 'active_support/version'
|
174
|
-
if ActiveSupport::VERSION::STRING =~ /^3\.0\./
|
175
|
-
its(:formatter){ should be_a(Logger::SimpleFormatter)}
|
176
|
-
else
|
177
|
-
its(:formatter){ should == nil}
|
178
|
-
end
|
179
|
-
|
180
|
-
its(:level){ should == 1}
|
181
|
-
its(:progname){ should == nil}
|
182
|
-
end
|
183
|
-
|
184
|
-
context "各属性の設定と引数を指定が両方ある場合" do
|
185
|
-
before{ @tempfile = Tempfile.new("test.log") }
|
186
|
-
after { @tempfile.close }
|
187
|
-
it "引数に指定されたオプションを優先" do
|
188
|
-
mock_logger = Logger.new("/dev/null")
|
189
|
-
Logger.should_receive(:new).with($stdout, nil, nil).and_return(mock_logger)
|
190
|
-
Tengine::Support::Config::Logger.new.tap{|c|
|
191
|
-
c.output = @tempfile.path
|
192
|
-
}.instantiate_children.new_logger(:output => $stdout)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
context "各属性を設定を指定する場合" do
|
197
|
-
before{ @tempfile = Tempfile.new("test.log") }
|
198
|
-
after { @tempfile.close }
|
199
|
-
subject do
|
200
|
-
Tengine::Support::Config::Logger.new.tap{|c|
|
201
|
-
c.output = @tempfile.path
|
202
|
-
c.rotation = "3"
|
203
|
-
c.rotation_size = 1000000
|
204
|
-
c.level = "info"
|
205
|
-
c.datetime_format = "%Y/%m/%d %H:%M:%S"
|
206
|
-
c.progname = "foobar"
|
207
|
-
}.instantiate_children.new_logger
|
208
|
-
end
|
209
|
-
its(:datetime_format){ should == "%Y/%m/%d %H:%M:%S"}
|
210
|
-
its(:formatter){ should be_a(Logger::Formatter)}
|
211
|
-
its(:level){ should == 1}
|
212
|
-
its(:progname){ should == "foobar"}
|
213
|
-
it "実際に出力してみる" do
|
214
|
-
t = Time.local(2011, 12, 31, 23, 59, 59)
|
215
|
-
Time.stub!(:now).and_return(t)
|
216
|
-
subject.info("something started.")
|
217
|
-
subject.error("something happened.")
|
218
|
-
File.read(@tempfile.path).should == [
|
219
|
-
"I, [2011/12/31 23:59:59##{Process.pid}] INFO -- foobar: something started.\n",
|
220
|
-
"E, [2011/12/31 23:59:59##{Process.pid}] ERROR -- foobar: something happened.\n"
|
221
|
-
].join
|
222
|
-
end
|
223
|
-
|
224
|
-
context "更にformatterも指定してみる" do
|
225
|
-
before do
|
226
|
-
subject.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} #{level} #{prog} #{msg}\n"}
|
227
|
-
end
|
228
|
-
it "実際に出力してみる" do
|
229
|
-
t = Time.utc(2011, 12, 31, 23, 59, 59)
|
230
|
-
Time.stub!(:now).and_return(t)
|
231
|
-
subject.info("something started.")
|
232
|
-
subject.error("something happened.")
|
233
|
-
File.read(@tempfile.path).should == [
|
234
|
-
"2011-12-31T23:59:59Z INFO foobar something started.\n",
|
235
|
-
"2011-12-31T23:59:59Z ERROR foobar something happened.\n",
|
236
|
-
].join
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
it "STDOUTの場合" do
|
242
|
-
config = Tengine::Support::Config::Logger.new.instantiate_children
|
243
|
-
config.output = "STDOUT"
|
244
|
-
config.level = "warn"
|
245
|
-
config.rotation = nil
|
246
|
-
config.rotation_size = nil
|
247
|
-
config.output.should == "STDOUT"
|
248
|
-
config.level.should == "warn"
|
249
|
-
config.rotation.should == nil
|
250
|
-
config.rotation_size.should == nil
|
251
|
-
logger = Logger.new(STDOUT, nil, nil)
|
252
|
-
Logger.should_receive(:new).with(STDOUT, nil, nil).and_return(logger)
|
253
|
-
logger.should_receive(:level=).with(Logger::WARN)
|
254
|
-
config.new_logger.should == logger
|
255
|
-
end
|
256
|
-
|
257
|
-
it "STDERRの場合" do
|
258
|
-
config = Tengine::Support::Config::Logger.new.instantiate_children
|
259
|
-
config.output = "STDERR"
|
260
|
-
config.level = "warn"
|
261
|
-
config.rotation = nil
|
262
|
-
config.rotation_size = nil
|
263
|
-
logger = Logger.new(STDERR, nil, nil)
|
264
|
-
Logger.should_receive(:new).with(STDERR, nil, nil).and_return(logger)
|
265
|
-
logger.should_receive(:level=).with(Logger::WARN)
|
266
|
-
config.new_logger.should == logger
|
267
|
-
end
|
268
|
-
|
269
|
-
it "NULLの場合" do
|
270
|
-
config = Tengine::Support::Config::Logger.new.instantiate_children
|
271
|
-
config.output = "NULL"
|
272
|
-
config.level = "warn"
|
273
|
-
config.rotation = nil
|
274
|
-
config.rotation_size = nil
|
275
|
-
Tengine::Support::NullLogger.should_receive(:new).and_return(:logger)
|
276
|
-
config.new_logger.should == :logger
|
277
|
-
end
|
278
|
-
|
279
|
-
context "ファイル名の場合" do
|
280
|
-
before do
|
281
|
-
@tempfile = Tempfile.new("test.log")
|
282
|
-
@filepath = @tempfile.path
|
283
|
-
end
|
284
|
-
after do
|
285
|
-
@tempfile.close
|
286
|
-
end
|
287
|
-
|
288
|
-
%w[daily weekly monthly].each do |shift_age|
|
289
|
-
it "shift_age が #{shift_age}" do
|
290
|
-
config = Tengine::Support::Config::Logger.new.instantiate_children
|
291
|
-
config.output = @filepath
|
292
|
-
config.level = "info"
|
293
|
-
config.rotation = shift_age
|
294
|
-
config.rotation_size = nil
|
295
|
-
logger = Logger.new(@filepath, shift_age, nil)
|
296
|
-
Logger.should_receive(:new).with(@filepath, shift_age, nil).and_return(logger)
|
297
|
-
logger.should_receive(:level=).with(Logger::INFO)
|
298
|
-
config.new_logger.should == logger
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
it "shift_ageが整数値" do
|
303
|
-
config = Tengine::Support::Config::Logger.new.instantiate_children
|
304
|
-
config.output = @filepath
|
305
|
-
config.level = "info"
|
306
|
-
config.rotation = "3"
|
307
|
-
config.rotation_size = 10 * 1024 * 1024 # 10MB
|
308
|
-
logger = Logger.new(@filepath, 3, 10 * 1024 * 1024)
|
309
|
-
Logger.should_receive(:new).with(@filepath, 3, 10 * 1024 * 1024).and_return(logger)
|
310
|
-
logger.should_receive(:level=).with(Logger::INFO)
|
311
|
-
config.new_logger.should == logger
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
3
|
-
|
4
|
-
describe 'Tengine::Support::Config::Mongoid' do
|
5
|
-
|
6
|
-
context "static" do
|
7
|
-
describe Tengine::Support::Config::Mongoid::Connection.host do
|
8
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
9
|
-
its(:type){ should == :string }
|
10
|
-
its(:__name__){ should == :host }
|
11
|
-
its(:description){ should == 'hostname to connect db.'}
|
12
|
-
its(:default){ should == 'localhost'}
|
13
|
-
end
|
14
|
-
|
15
|
-
describe Tengine::Support::Config::Mongoid::Connection.port do
|
16
|
-
it { subject.should be_a(Tengine::Support::Config::Definition::Field)}
|
17
|
-
its(:type){ should == :integer }
|
18
|
-
its(:__name__){ should == :port }
|
19
|
-
its(:description){ should == 'port to connect db.'}
|
20
|
-
its(:default){ should == 27017}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|