litmus_paper 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ module LitmusPaper
2
+ module Dependency
3
+ class FileContents
4
+ def initialize(path, regex, options = {})
5
+ @path = path
6
+ @regex = regex
7
+ @timeout = options.fetch(:timeout, 5)
8
+ end
9
+
10
+ def available?
11
+ Timeout.timeout(@timeout) do
12
+ if File.read(@path).match(@regex)
13
+ true
14
+ else
15
+ LitmusPaper.logger.info("Available check of #{@path} failed, content did not match #{@regex.inspect}")
16
+ false
17
+ end
18
+ end
19
+ rescue Timeout::Error
20
+ LitmusPaper.logger.info("Timeout reading #{@path}")
21
+ false
22
+ rescue Exception => e
23
+ LitmusPaper.logger.info("Error reading #{@path}: '#{e.message}'")
24
+ false
25
+ end
26
+
27
+ def to_s
28
+ "Dependency::FileContents(#{@path}, #{@regex.inspect})"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module LitmusPaper
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
data/lib/litmus_paper.rb CHANGED
@@ -24,6 +24,7 @@ require 'facts/loadaverage'
24
24
  require 'litmus_paper/app'
25
25
  require 'litmus_paper/configuration'
26
26
  require 'litmus_paper/configuration_file'
27
+ require 'litmus_paper/dependency/file_contents'
27
28
  require 'litmus_paper/dependency/haproxy_backends'
28
29
  require 'litmus_paper/dependency/http'
29
30
  require 'litmus_paper/dependency/script'
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe LitmusPaper::Dependency::FileContents do
5
+ describe "#available?" do
6
+ it "is true when the file matches the regexp" do
7
+ file_path = SpecHelper.create_temp_file("yes")
8
+
9
+ check = LitmusPaper::Dependency::FileContents.new(file_path, /^yes$/)
10
+ check.should be_available
11
+ end
12
+
13
+ it "is false when the file does not match the regexp" do
14
+ file_path = SpecHelper.create_temp_file("no")
15
+
16
+ check = LitmusPaper::Dependency::FileContents.new(file_path, /^yes$/)
17
+ check.should_not be_available
18
+ end
19
+
20
+ it "is false when the script exceeds the timeout" do
21
+ check = LitmusPaper::Dependency::FileContents.new("/dev/zero", /^timeout$/, :timeout => 1)
22
+ check.should_not be_available
23
+ end
24
+ end
25
+
26
+ describe "to_s" do
27
+ it "returns the command" do
28
+ check = LitmusPaper::Dependency::FileContents.new("/path/to/file", /^a.regexp$/)
29
+ check.to_s.should == "Dependency::FileContents(/path/to/file, /^a.regexp$/)"
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litmus_paper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 1
10
- version: 0.7.1
9
+ - 2
10
+ version: 0.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Braintreeps
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-20 00:00:00 -06:00
19
- default_executable:
18
+ date: 2012-12-11 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: sinatra
@@ -163,6 +162,7 @@ files:
163
162
  - lib/litmus_paper/cli/server.rb
164
163
  - lib/litmus_paper/configuration.rb
165
164
  - lib/litmus_paper/configuration_file.rb
165
+ - lib/litmus_paper/dependency/file_contents.rb
166
166
  - lib/litmus_paper/dependency/haproxy_backends.rb
167
167
  - lib/litmus_paper/dependency/http.rb
168
168
  - lib/litmus_paper/dependency/script.rb
@@ -181,6 +181,7 @@ files:
181
181
  - spec/litmus_paper/cli/admin_spec.rb
182
182
  - spec/litmus_paper/cli/server_spec.rb
183
183
  - spec/litmus_paper/configuration_file_spec.rb
184
+ - spec/litmus_paper/dependency/file_contents_spec.rb
184
185
  - spec/litmus_paper/dependency/haproxy_backends_spec.rb
185
186
  - spec/litmus_paper/dependency/http_spec.rb
186
187
  - spec/litmus_paper/dependency/script_spec.rb
@@ -208,7 +209,6 @@ files:
208
209
  - spec/support/stub_facter.rb
209
210
  - spec/support/test.config
210
211
  - spec/support/test.d.config
211
- has_rdoc: true
212
212
  homepage: https://github.com/braintree/litmus_paper
213
213
  licenses: []
214
214
 
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  requirements: []
239
239
 
240
240
  rubyforge_project:
241
- rubygems_version: 1.3.7
241
+ rubygems_version: 1.8.15
242
242
  signing_key:
243
243
  specification_version: 3
244
244
  summary: Backend health tester for HA Services, partner project of big_brother
@@ -247,6 +247,7 @@ test_files:
247
247
  - spec/litmus_paper/cli/admin_spec.rb
248
248
  - spec/litmus_paper/cli/server_spec.rb
249
249
  - spec/litmus_paper/configuration_file_spec.rb
250
+ - spec/litmus_paper/dependency/file_contents_spec.rb
250
251
  - spec/litmus_paper/dependency/haproxy_backends_spec.rb
251
252
  - spec/litmus_paper/dependency/http_spec.rb
252
253
  - spec/litmus_paper/dependency/script_spec.rb