flapjack 0.6.43 → 0.6.44
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/bin/flapjack +4 -2
- data/bin/flapjack-nagios-receiver +4 -1
- data/bin/flapjack-populator +4 -1
- data/etc/flapjack_config.yaml.example +111 -106
- data/features/steps/notifications_steps.rb +6 -6
- data/lib/flapjack/configuration.rb +76 -24
- data/lib/flapjack/coordinator.rb +27 -44
- data/lib/flapjack/data/entity.rb +28 -7
- data/lib/flapjack/data/entity_check.rb +18 -20
- data/lib/flapjack/executive.rb +5 -4
- data/lib/flapjack/gateways/api.rb +391 -0
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +185 -0
- data/lib/flapjack/gateways/api/entity_presenter.rb +70 -0
- data/lib/flapjack/gateways/base.rb +38 -0
- data/lib/flapjack/{notification → gateways}/email.rb +4 -5
- data/lib/flapjack/{notification → gateways}/email/alert.html.haml +0 -0
- data/lib/flapjack/{notification → gateways}/email/alert.text.erb +0 -0
- data/lib/flapjack/gateways/jabber.rb +387 -0
- data/lib/flapjack/gateways/oobetet.rb +241 -0
- data/lib/flapjack/gateways/pagerduty.rb +247 -0
- data/lib/flapjack/{notification → gateways}/sms.rb +5 -6
- data/lib/flapjack/{notification → gateways}/sms/messagenet.rb +1 -1
- data/lib/flapjack/gateways/web.rb +293 -0
- data/lib/flapjack/{web → gateways/web}/views/_css.haml +0 -0
- data/lib/flapjack/{web → gateways/web}/views/_nav.haml +0 -0
- data/lib/flapjack/{web → gateways/web}/views/check.haml +0 -0
- data/lib/flapjack/{web → gateways/web}/views/contact.haml +0 -0
- data/lib/flapjack/{web → gateways/web}/views/contacts.haml +0 -0
- data/lib/flapjack/{web → gateways/web}/views/index.haml +0 -0
- data/lib/flapjack/{web → gateways/web}/views/self_stats.haml +0 -0
- data/lib/flapjack/pikelet.rb +0 -23
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +56 -36
- data/spec/lib/flapjack/data/entity_spec.rb +53 -4
- data/spec/lib/flapjack/{api → gateways/api}/entity_check_presenter_spec.rb +10 -13
- data/spec/lib/flapjack/{api → gateways/api}/entity_presenter_spec.rb +10 -10
- data/spec/lib/flapjack/{api_spec.rb → gateways/api_spec.rb} +14 -14
- data/spec/lib/flapjack/gateways/email_spec.rb +6 -0
- data/spec/lib/flapjack/{jabber_spec.rb → gateways/jabber_spec.rb} +9 -9
- data/spec/lib/flapjack/{oobetet_spec.rb → gateways/oobetet_spec.rb} +10 -10
- data/spec/lib/flapjack/{pagerduty_spec.rb → gateways/pagerduty_spec.rb} +11 -11
- data/spec/lib/flapjack/gateways/sms_spec.rb +6 -0
- data/spec/lib/flapjack/{web_spec.rb → gateways/web_spec.rb} +4 -4
- metadata +46 -79
- data/bin/install-flapjack-systemwide +0 -58
- data/features/steps/flapjack-importer_steps.rb +0 -109
- data/features/steps/flapjack-worker_steps.rb +0 -68
- data/lib/flapjack/api.rb +0 -388
- data/lib/flapjack/api/entity_check_presenter.rb +0 -181
- data/lib/flapjack/api/entity_presenter.rb +0 -66
- data/lib/flapjack/cli/worker_manager.rb +0 -46
- data/lib/flapjack/inifile.rb +0 -44
- data/lib/flapjack/jabber.rb +0 -383
- data/lib/flapjack/notifier_engine.rb +0 -40
- data/lib/flapjack/notifiers/mailer/init.rb +0 -3
- data/lib/flapjack/notifiers/mailer/mailer.rb +0 -51
- data/lib/flapjack/notifiers/xmpp/init.rb +0 -3
- data/lib/flapjack/notifiers/xmpp/xmpp.rb +0 -46
- data/lib/flapjack/oobetet.rb +0 -240
- data/lib/flapjack/pagerduty.rb +0 -242
- data/lib/flapjack/web.rb +0 -286
- data/spec.old/check_sandbox/echo +0 -3
- data/spec.old/check_sandbox/sandboxed_check +0 -5
- data/spec.old/configs/flapjack-notifier-couchdb.ini +0 -25
- data/spec.old/configs/flapjack-notifier.ini +0 -39
- data/spec.old/configs/recipients.ini +0 -14
- data/spec.old/helpers.rb +0 -15
- data/spec.old/inifile_spec.rb +0 -66
- data/spec.old/mock-notifiers/mock/init.rb +0 -3
- data/spec.old/mock-notifiers/mock/mock.rb +0 -19
- data/spec.old/notifier-directories/spoons/testmailer/init.rb +0 -20
- data/spec.old/notifier_application_spec.rb +0 -222
- data/spec.old/notifier_filters_spec.rb +0 -52
- data/spec.old/notifier_options_multiplexer_spec.rb +0 -71
- data/spec.old/notifier_options_spec.rb +0 -115
- data/spec.old/notifier_spec.rb +0 -57
- data/spec.old/notifiers/mailer_spec.rb +0 -36
- data/spec.old/notifiers/xmpp_spec.rb +0 -36
- data/spec.old/persistence/datamapper_spec.rb +0 -74
- data/spec.old/persistence/mock_persistence_backend.rb +0 -26
- data/spec.old/simple.ini +0 -6
- data/spec.old/spec.opts +0 -4
- data/spec.old/test-filters/blocker.rb +0 -13
- data/spec.old/test-filters/mock.rb +0 -13
- data/spec.old/transports/beanstalkd_spec.rb +0 -44
- data/spec.old/transports/mock_transport.rb +0 -58
- data/spec.old/worker_application_spec.rb +0 -62
- data/spec.old/worker_options_spec.rb +0 -83
- data/spec/lib/flapjack/notification/email_spec.rb +0 -6
- data/spec/lib/flapjack/notification/sms_spec.rb +0 -6
data/lib/flapjack/web.rb
DELETED
@@ -1,286 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'chronic'
|
4
|
-
require 'chronic_duration'
|
5
|
-
require 'sinatra/base'
|
6
|
-
require 'haml'
|
7
|
-
require 'rack/fiber_pool'
|
8
|
-
|
9
|
-
require 'async-rack'
|
10
|
-
require 'flapjack/rack_logger'
|
11
|
-
|
12
|
-
require 'flapjack/pikelet'
|
13
|
-
require 'flapjack/data/contact'
|
14
|
-
require 'flapjack/data/entity_check'
|
15
|
-
require 'flapjack/redis_pool'
|
16
|
-
require 'flapjack/utility'
|
17
|
-
|
18
|
-
module Flapjack
|
19
|
-
class Web < Sinatra::Base
|
20
|
-
|
21
|
-
if defined?(FLAPJACK_ENV) && 'test'.eql?(FLAPJACK_ENV)
|
22
|
-
# expose test errors properly
|
23
|
-
set :raise_errors, true
|
24
|
-
set :show_exceptions, false
|
25
|
-
else
|
26
|
-
rescue_exception = Proc.new do |env, e|
|
27
|
-
if settings.show_exceptions?
|
28
|
-
# ensure the sinatra error page shows properly
|
29
|
-
request = Sinatra::Request.new(env)
|
30
|
-
printer = Sinatra::ShowExceptions.new(proc{ raise e })
|
31
|
-
s, h, b = printer.call(env)
|
32
|
-
[s, h, b]
|
33
|
-
else
|
34
|
-
logger.error e.message
|
35
|
-
logger.error e.backtrace.join("\n")
|
36
|
-
[503, {}, ""]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# doesn't work with Rack::Test unless we wrap tests in EM.synchrony blocks
|
41
|
-
use Rack::FiberPool, :size => 25, :rescue_exception => rescue_exception
|
42
|
-
end
|
43
|
-
use Rack::MethodOverride
|
44
|
-
|
45
|
-
class << self
|
46
|
-
include Flapjack::ThinPikelet
|
47
|
-
|
48
|
-
attr_accessor :redis
|
49
|
-
|
50
|
-
alias_method :thin_bootstrap, :bootstrap
|
51
|
-
alias_method :thin_cleanup, :cleanup
|
52
|
-
|
53
|
-
def bootstrap(opts = {})
|
54
|
-
thin_bootstrap(opts)
|
55
|
-
@redis = Flapjack::RedisPool.new(:config => opts[:redis_config], :size => 1)
|
56
|
-
|
57
|
-
if config && config['access_log']
|
58
|
-
access_logger = Flapjack::RackLogger.new(config['access_log'])
|
59
|
-
use Rack::CommonLogger, access_logger
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def cleanup
|
64
|
-
@redis.empty! if @redis
|
65
|
-
thin_cleanup
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
include Flapjack::Utility
|
71
|
-
|
72
|
-
set :views, settings.root + '/web/views'
|
73
|
-
|
74
|
-
def redis
|
75
|
-
self.class.instance_variable_get('@redis')
|
76
|
-
end
|
77
|
-
|
78
|
-
def logger
|
79
|
-
self.class.instance_variable_get('@logger')
|
80
|
-
end
|
81
|
-
|
82
|
-
get '/' do
|
83
|
-
self_stats
|
84
|
-
|
85
|
-
# TODO (?) recast as Entity.all do |e|; e.checks.do |ec|; ...
|
86
|
-
@states = redis.keys('*:*:states').map { |r|
|
87
|
-
parts = r.split(':')[0..1]
|
88
|
-
[parts[0], parts[1]] + entity_check_state(parts[0], parts[1])
|
89
|
-
}.compact.sort_by {|parts| parts }
|
90
|
-
haml :index
|
91
|
-
end
|
92
|
-
|
93
|
-
get '/failing' do
|
94
|
-
self_stats
|
95
|
-
@states = redis.zrange('failed_checks', 0, -1).map {|key|
|
96
|
-
parts = key.split(':')
|
97
|
-
[parts[0], parts[1]] + entity_check_state(parts[0], parts[1])
|
98
|
-
}.compact.sort_by {|parts| parts}
|
99
|
-
haml :index
|
100
|
-
end
|
101
|
-
|
102
|
-
get '/self_stats' do
|
103
|
-
self_stats
|
104
|
-
haml :self_stats
|
105
|
-
end
|
106
|
-
|
107
|
-
get '/check' do
|
108
|
-
@entity = params[:entity]
|
109
|
-
@check = params[:check]
|
110
|
-
|
111
|
-
entity_check = get_entity_check(@entity, @check)
|
112
|
-
return 404 if entity_check.nil?
|
113
|
-
|
114
|
-
last_change = entity_check.last_change
|
115
|
-
|
116
|
-
@check_state = entity_check.state
|
117
|
-
@check_last_update = entity_check.last_update
|
118
|
-
@check_last_change = last_change
|
119
|
-
@check_summary = entity_check.summary
|
120
|
-
@last_notifications = entity_check.last_notifications_of_each_type
|
121
|
-
@scheduled_maintenances = entity_check.maintenances(nil, nil, :scheduled => true)
|
122
|
-
@acknowledgement_id = entity_check.failed? ?
|
123
|
-
entity_check.event_count_at(entity_check.last_change) : nil
|
124
|
-
|
125
|
-
@current_scheduled_maintenance = entity_check.current_maintenance(:scheduled => true)
|
126
|
-
@current_unscheduled_maintenance = entity_check.current_maintenance(:scheduled => false)
|
127
|
-
|
128
|
-
@contacts = entity_check.contacts
|
129
|
-
|
130
|
-
haml :check
|
131
|
-
end
|
132
|
-
|
133
|
-
post '/acknowledgements/:entity/:check' do
|
134
|
-
@entity = params[:entity]
|
135
|
-
@check = params[:check]
|
136
|
-
@summary = params[:summary]
|
137
|
-
@acknowledgement_id = params[:acknowledgement_id]
|
138
|
-
|
139
|
-
dur = ChronicDuration.parse(params[:duration] || '')
|
140
|
-
@duration = (dur.nil? || (dur <= 0)) ? (4 * 60 * 60) : dur
|
141
|
-
|
142
|
-
entity_check = get_entity_check(@entity, @check)
|
143
|
-
return 404 if entity_check.nil?
|
144
|
-
|
145
|
-
ack = entity_check.create_acknowledgement('summary' => (@summary || ''),
|
146
|
-
'acknowledgement_id' => @acknowledgement_id, 'duration' => @duration)
|
147
|
-
|
148
|
-
redirect back
|
149
|
-
end
|
150
|
-
|
151
|
-
# FIXME: there is bound to be a more idiomatic / restful way of doing this
|
152
|
-
# (probably using 'delete' or 'patch')
|
153
|
-
post '/end_unscheduled_maintenance/:entity/:check' do
|
154
|
-
@entity = params[:entity]
|
155
|
-
@check = params[:check]
|
156
|
-
|
157
|
-
entity_check = get_entity_check(@entity, @check)
|
158
|
-
return 404 if entity_check.nil?
|
159
|
-
|
160
|
-
entity_check.end_unscheduled_maintenance
|
161
|
-
|
162
|
-
redirect back
|
163
|
-
end
|
164
|
-
|
165
|
-
# create scheduled maintenance
|
166
|
-
post '/scheduled_maintenances/:entity/:check' do
|
167
|
-
start_time = Chronic.parse(params[:start_time]).to_i
|
168
|
-
raise ArgumentError, "start time parsed to zero" unless start_time > 0
|
169
|
-
duration = ChronicDuration.parse(params[:duration])
|
170
|
-
summary = params[:summary]
|
171
|
-
|
172
|
-
entity_check = get_entity_check(params[:entity], params[:check])
|
173
|
-
return 404 if entity_check.nil?
|
174
|
-
|
175
|
-
entity_check.create_scheduled_maintenance(:start_time => start_time,
|
176
|
-
:duration => duration,
|
177
|
-
:summary => summary)
|
178
|
-
redirect back
|
179
|
-
end
|
180
|
-
|
181
|
-
# modify scheduled maintenance
|
182
|
-
patch '/scheduled_maintenances/:entity/:check' do
|
183
|
-
entity_check = get_entity_check(params[:entity], params[:check])
|
184
|
-
return 404 if entity_check.nil?
|
185
|
-
|
186
|
-
end_time = Chronic.parse(params[:end_time]).to_i
|
187
|
-
start_time = params[:start_time].to_i
|
188
|
-
raise ArgumentError, "start time parsed to zero" unless start_time > 0
|
189
|
-
|
190
|
-
patches = {}
|
191
|
-
patches[:end_time] = end_time if end_time && (end_time > start_time)
|
192
|
-
|
193
|
-
raise ArgumentError.new("no valid data received to patch with") if patches.empty?
|
194
|
-
|
195
|
-
entity_check.update_scheduled_maintenance(start_time, patches)
|
196
|
-
redirect back
|
197
|
-
end
|
198
|
-
|
199
|
-
# delete a scheduled maintenance
|
200
|
-
delete '/scheduled_maintenances/:entity/:check' do
|
201
|
-
entity_check = get_entity_check(params[:entity], params[:check])
|
202
|
-
return 404 if entity_check.nil?
|
203
|
-
|
204
|
-
entity_check.delete_scheduled_maintenance(:start_time => params[:start_time].to_i)
|
205
|
-
redirect back
|
206
|
-
end
|
207
|
-
|
208
|
-
get '/contacts' do
|
209
|
-
@contacts = Flapjack::Data::Contact.all(:redis => redis)
|
210
|
-
haml :contacts
|
211
|
-
end
|
212
|
-
|
213
|
-
get "/contacts/:contact" do
|
214
|
-
contact_id = params[:contact]
|
215
|
-
|
216
|
-
if contact_id
|
217
|
-
@contact = Flapjack::Data::Contact.find_by_id(contact_id, :redis => redis)
|
218
|
-
end
|
219
|
-
|
220
|
-
unless @contact
|
221
|
-
status 404
|
222
|
-
return
|
223
|
-
end
|
224
|
-
|
225
|
-
if @contact.media.has_key?('pagerduty')
|
226
|
-
@pagerduty_credentials = @contact.pagerduty_credentials
|
227
|
-
end
|
228
|
-
|
229
|
-
@entities_and_checks = @contact.entities_and_checks.sort_by {|ec|
|
230
|
-
ec[:entity].name
|
231
|
-
}
|
232
|
-
|
233
|
-
haml :contact
|
234
|
-
end
|
235
|
-
|
236
|
-
private
|
237
|
-
|
238
|
-
def get_entity_check(entity, check)
|
239
|
-
entity_obj = (entity && entity.length > 0) ?
|
240
|
-
Flapjack::Data::Entity.find_by_name(entity, :redis => redis) : nil
|
241
|
-
return if entity_obj.nil? || (check.nil? || check.length == 0)
|
242
|
-
Flapjack::Data::EntityCheck.for_entity(entity_obj, check, :redis => redis)
|
243
|
-
end
|
244
|
-
|
245
|
-
def entity_check_state(entity_name, check)
|
246
|
-
entity = Flapjack::Data::Entity.find_by_name(entity_name,
|
247
|
-
:redis => redis)
|
248
|
-
return if entity.nil?
|
249
|
-
entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
|
250
|
-
check, :redis => redis)
|
251
|
-
latest_notif =
|
252
|
-
{:problem => entity_check.last_problem_notification,
|
253
|
-
:recovery => entity_check.last_recovery_notification,
|
254
|
-
:acknowledgement => entity_check.last_acknowledgement_notification
|
255
|
-
}.max_by {|n| n[1] || 0}
|
256
|
-
[(entity_check.state || '-'),
|
257
|
-
(entity_check.last_change || '-'),
|
258
|
-
(entity_check.last_update || '-'),
|
259
|
-
entity_check.in_unscheduled_maintenance?,
|
260
|
-
entity_check.in_scheduled_maintenance?,
|
261
|
-
latest_notif[0],
|
262
|
-
latest_notif[1]
|
263
|
-
]
|
264
|
-
end
|
265
|
-
|
266
|
-
def self_stats
|
267
|
-
@fqdn = `/bin/hostname -f`.chomp
|
268
|
-
@pid = Process.pid
|
269
|
-
@instance_id = "#{@fqdn}:#{@pid}"
|
270
|
-
|
271
|
-
@keys = redis.keys '*'
|
272
|
-
@count_failing_checks = redis.zcard 'failed_checks'
|
273
|
-
@count_all_checks = redis.keys('check:*:*').length
|
274
|
-
@executive_instances = redis.zrange('executive_instances', '0', '-1', :withscores => true)
|
275
|
-
@event_counters = redis.hgetall('event_counters')
|
276
|
-
@event_counters_instance = redis.hgetall("event_counters:#{@instance_id}")
|
277
|
-
@boot_time = Time.at(redis.zscore('executive_instances', @instance_id).to_i)
|
278
|
-
@uptime = Time.now.to_i - @boot_time.to_i
|
279
|
-
@uptime_string = time_period_in_words(@uptime)
|
280
|
-
@event_rate_all = (@uptime > 0) ?
|
281
|
-
(@event_counters_instance['all'].to_f / @uptime) : 0
|
282
|
-
@events_queued = redis.llen('events')
|
283
|
-
end
|
284
|
-
|
285
|
-
end
|
286
|
-
end
|
data/spec.old/check_sandbox/echo
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# top level
|
2
|
-
[notifier]
|
3
|
-
notifier-directories = /usr/lib/flapjack/notifiers/ /path/to/my/notifiers
|
4
|
-
notifiers = mailer, xmpp
|
5
|
-
|
6
|
-
[persistence]
|
7
|
-
backend = couchdb
|
8
|
-
version = 0.8
|
9
|
-
host = localhost
|
10
|
-
port = 5984
|
11
|
-
database = flapjack_production
|
12
|
-
|
13
|
-
[transport]
|
14
|
-
backend = beanstalkd
|
15
|
-
basedir = /usr/lib/flapjack/persistence/
|
16
|
-
host = localhost
|
17
|
-
port = 11300
|
18
|
-
|
19
|
-
[mailer-notifier]
|
20
|
-
from_address = foo@bar.com
|
21
|
-
|
22
|
-
[xmpp-notifier]
|
23
|
-
jid = foo@bar.com
|
24
|
-
password = barfoo
|
25
|
-
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# top level
|
2
|
-
[notifier]
|
3
|
-
notifier-directories = /usr/lib/flapjack/notifiers/ /path/to/my/notifiers
|
4
|
-
notifiers = mailer, xmpp
|
5
|
-
|
6
|
-
# persistence layers
|
7
|
-
[persistence]
|
8
|
-
backend = data_mapper
|
9
|
-
uri = sqlite3:///tmp/flapjack.db
|
10
|
-
|
11
|
-
# message transports
|
12
|
-
[transport]
|
13
|
-
backend = beanstalkd
|
14
|
-
host = localhost
|
15
|
-
port = 11300
|
16
|
-
|
17
|
-
# notifiers
|
18
|
-
[mailer-notifier]
|
19
|
-
from_address = foo@bar.com
|
20
|
-
|
21
|
-
[xmpp-notifier]
|
22
|
-
jid = foo@bar.com
|
23
|
-
password = barfoo
|
24
|
-
|
25
|
-
# filters
|
26
|
-
[filters]
|
27
|
-
chain = ok, downtime, any_parents_failed
|
28
|
-
|
29
|
-
#[pre-filters-actions]
|
30
|
-
# chain =
|
31
|
-
#
|
32
|
-
#[post-filters-actions]
|
33
|
-
# chain =
|
34
|
-
#
|
35
|
-
#[pre-notification-actions]
|
36
|
-
# chain =
|
37
|
-
#
|
38
|
-
#[post-notification-actions]
|
39
|
-
# chain =
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# recipients
|
2
|
-
|
3
|
-
[John Doe]
|
4
|
-
email = johndoe@example.org
|
5
|
-
jid = john@example.org
|
6
|
-
phone = +61 400 111 222
|
7
|
-
pager = 61400111222
|
8
|
-
|
9
|
-
[Jane Doe]
|
10
|
-
email = janedoe@example.org
|
11
|
-
jid = jane@example.org
|
12
|
-
phone = +61 222 333 111
|
13
|
-
pager = 61222333111
|
14
|
-
|
data/spec.old/helpers.rb
DELETED
data/spec.old/inifile_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'flapjack', 'inifile')
|
4
|
-
require File.join(File.dirname(__FILE__), 'helpers')
|
5
|
-
|
6
|
-
describe "inifile reader" do
|
7
|
-
|
8
|
-
it "should turn sections into keys" do
|
9
|
-
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n[splades]\nbar = baz"
|
10
|
-
ini = Flapjack::Inifile.new(example)
|
11
|
-
ini.keys.sort.should == %w{forks splades spoons}
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should nest parameters under a section" do
|
15
|
-
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n[splades]\nbar = baz"
|
16
|
-
ini = Flapjack::Inifile.new(example)
|
17
|
-
ini['forks']['hello'].should == "world"
|
18
|
-
ini['spoons']['foo'].should == "bar"
|
19
|
-
ini['splades']['bar'].should == "baz"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should read a file" do
|
23
|
-
filename = File.join(File.dirname(__FILE__), 'simple.ini')
|
24
|
-
ini = Flapjack::Inifile.read(filename)
|
25
|
-
ini['forks']['hello'].should == "world"
|
26
|
-
ini['spoons']['foo'].should == "bar"
|
27
|
-
ini['splades']['bar'].should == "baz"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should ignore commented lines" do
|
31
|
-
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n# comment goes here\n[splades]\nbar = baz"
|
32
|
-
ini = Flapjack::Inifile.new(example)
|
33
|
-
ini['spoons'].keys.include?(/#/).should be_false
|
34
|
-
ini['spoons'].keys.include?(/comment goes here/).should be_false
|
35
|
-
ini['spoons'].values.include?(/#/).should be_false
|
36
|
-
ini['spoons'].values.include?(/comment goes here/).should be_false
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should ignore blank lines" do
|
40
|
-
example = "\n\n\n\n\n\n\n[spoons]\n\n\n\n[of]\n[doom]"
|
41
|
-
ini = Flapjack::Inifile.new(example)
|
42
|
-
ini.keys.sort.should == %w(doom of spoons)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should ignore mid-line comments" do
|
46
|
-
example = "[forks] ; a comment \nhello = world ; another comment\n\n"
|
47
|
-
ini = Flapjack::Inifile.new(example)
|
48
|
-
ini.keys.include?("forks").should be_true
|
49
|
-
ini['forks']['hello'].should == 'world'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should append re-opened sections" do
|
53
|
-
example = "[forks]\nhello = world\n[forks]\nfoo = bar\n\n[forks]\nbar = baz"
|
54
|
-
ini = Flapjack::Inifile.new(example)
|
55
|
-
ini.keys.include?("forks").should be_true
|
56
|
-
ini["forks"].keys.sort.should == %w(bar foo hello)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should dump the raw config" do
|
60
|
-
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n[splades]\nbar = baz"
|
61
|
-
ini = Flapjack::Inifile.new(example)
|
62
|
-
ini.all.size.should == 3
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
end
|