outpost 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.rdoc +16 -0
  3. data/Gemfile +9 -3
  4. data/Gemfile.lock +39 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.markdown +40 -8
  7. data/Rakefile +14 -0
  8. data/TODO.md +7 -0
  9. data/lib/outpost.rb +1 -1
  10. data/lib/outpost/application.rb +143 -0
  11. data/lib/outpost/expectations/response_body.rb +23 -9
  12. data/lib/outpost/expectations/response_code.rb +5 -0
  13. data/lib/outpost/expectations/response_time.rb +10 -1
  14. data/lib/outpost/notifiers.rb +2 -0
  15. data/lib/outpost/notifiers/campfire.rb +50 -0
  16. data/lib/outpost/notifiers/email.rb +59 -0
  17. data/lib/outpost/report.rb +7 -1
  18. data/lib/outpost/scout.rb +82 -0
  19. data/lib/outpost/scout_config.rb +10 -4
  20. data/lib/outpost/scouts/http.rb +28 -7
  21. data/lib/outpost/scouts/ping.rb +26 -6
  22. data/lib/outpost/version.rb +4 -1
  23. data/outpost.gemspec +0 -2
  24. data/test/integration/{basic_dsl_test.rb → basic_application_test.rb} +5 -5
  25. data/test/integration/more_complex_test.rb +20 -8
  26. data/test/integration/notifiers_test.rb +51 -0
  27. data/test/outpost/dsl_test.rb +74 -3
  28. data/test/outpost/expectations/response_body_test.rb +13 -15
  29. data/test/outpost/expectations/response_code_test.rb +5 -7
  30. data/test/outpost/expectations/response_time_test.rb +9 -11
  31. data/test/outpost/notifiers/campfire_test.rb +72 -0
  32. data/test/outpost/notifiers/email_test.rb +90 -0
  33. data/test/outpost/scout_test.rb +5 -6
  34. data/test/outpost/scouts/http_test.rb +51 -0
  35. data/test/outpost/scouts/ping_test.rb +41 -0
  36. data/test/support/nothing_raised.rb +10 -0
  37. data/test/support/server.rb +0 -1
  38. data/test/support/stubs.rb +11 -0
  39. data/test/test_helper.rb +8 -6
  40. metadata +32 -22
  41. data/lib/outpost/dsl.rb +0 -54
@@ -0,0 +1,90 @@
1
+ require 'test_helper'
2
+
3
+ describe Outpost::Notifiers::Email do
4
+ before(:each) do
5
+ Mail.defaults do
6
+ delivery_method :test
7
+ end
8
+ end
9
+
10
+ after(:each) do
11
+ Mail::TestMailer.deliveries = []
12
+ end
13
+
14
+ describe "#initialize" do
15
+ it "should raise error when :from is not present" do
16
+ assert_raises ArgumentError do
17
+ Outpost::Notifiers::Email.new(:to => 'mail@example.com')
18
+ end
19
+ end
20
+
21
+ it "should raise error when :to is not present" do
22
+ assert_raises ArgumentError do
23
+ Outpost::Notifiers::Email.new(:from => 'mail@example.com')
24
+ end
25
+ end
26
+
27
+ it "should not raise error when both :from and :to are supplied" do
28
+ assert_nothing_raised do
29
+ Outpost::Notifiers::Email.new(
30
+ :from => 'mail@example.com',
31
+ :to => 'mailer@example.com'
32
+ )
33
+ end
34
+ end
35
+
36
+ it "should not be destructive" do
37
+ options = {:from => 'mail@example.com', :to => 'mailer@example.com'}
38
+ Outpost::Notifiers::Email.new(options)
39
+ refute_empty options.keys
40
+ end
41
+ end
42
+
43
+ describe "#notify" do
44
+ it "should send a simple email" do
45
+ subject = Outpost::Notifiers::Email.new(
46
+ :from => 'mail@example.com',
47
+ :to => 'mailer@example.com'
48
+ )
49
+
50
+ subject.notify(outpost_stub)
51
+
52
+ message = Mail::TestMailer.deliveries.first
53
+
54
+ assert_equal ["mail@example.com"], message.from
55
+ assert_equal ["mailer@example.com"], message.to
56
+ assert_equal "Outpost notification", message.subject
57
+ report = "This is the report for test outpost: System is UP!\n\n1\n2"
58
+ assert_equal report, message.body.to_s
59
+ end
60
+
61
+ it "should be able to customize subject" do
62
+ subject = Outpost::Notifiers::Email.new(
63
+ :from => 'mail@example.com',
64
+ :to => 'mailer@example.com',
65
+ :subject => 'OMG'
66
+ )
67
+
68
+ subject.notify(outpost_stub)
69
+
70
+ message = Mail::TestMailer.deliveries.first
71
+
72
+ assert_equal ["mail@example.com"], message.from
73
+ assert_equal ["mailer@example.com"], message.to
74
+ assert_equal "OMG", message.subject
75
+ report = "This is the report for test outpost: System is UP!\n\n1\n2"
76
+ assert_equal report, message.body.to_s
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def outpost_stub
83
+ build_stub(
84
+ :name => 'test outpost',
85
+ :last_status => :up,
86
+ :messages => ['1', '2']
87
+ )
88
+ end
89
+ end
90
+
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'ostruct'
3
2
 
4
3
  describe Outpost::Scout do
5
4
  NoisyError = Class.new(StandardError)
@@ -78,11 +77,11 @@ describe Outpost::Scout do
78
77
 
79
78
  private
80
79
  def config_mock
81
- OpenStruct.new.tap do |config|
82
- config.reports = {}
83
- config.reports[{:response => true}] = :up
84
- config.reports[{:response => false}] = :down
85
- end
80
+ reports = {
81
+ {:response => true} => :up,
82
+ {:response => false} => :down
83
+ }
84
+ build_stub(:reports => reports)
86
85
  end
87
86
 
88
87
  def add_expectation(expectation, callable)
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ describe Outpost::Scouts::Http do
4
+ class NetHttpStub
5
+ class << self
6
+ def response(&block); @response = block; end
7
+
8
+ def get_response(*args)
9
+ @response.call
10
+ end
11
+ end
12
+ end
13
+
14
+ before(:each) do
15
+ config_stub = config_stub(:host => 'localhost', :http_class => NetHttpStub)
16
+ @subject = Outpost::Scouts::Http.new("description", config_stub)
17
+ end
18
+
19
+ it "should get the response code and response body" do
20
+ NetHttpStub.response { response_stub('200', 'Body') }
21
+ @subject.execute
22
+
23
+ assert_equal 200 , @subject.response_code
24
+ assert_equal 'Body', @subject.response_body
25
+ end
26
+
27
+ it "should set response code and body as nil when connection refused" do
28
+ NetHttpStub.response { raise Errno::ECONNREFUSED }
29
+ @subject.execute
30
+
31
+ refute @subject.response_code
32
+ refute @subject.response_body
33
+ end
34
+
35
+ it "should set response code and body as nil when socket error" do
36
+ NetHttpStub.response { raise SocketError }
37
+
38
+ refute @subject.response_code
39
+ refute @subject.response_body
40
+ end
41
+
42
+ private
43
+
44
+ def config_stub(options={})
45
+ build_stub(:options => options)
46
+ end
47
+
48
+ def response_stub(code, body)
49
+ build_stub(:code => code, :body => body)
50
+ end
51
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ describe Outpost::Scouts::Ping do
4
+ class PingStub
5
+ def initialize(ping_successful, duration=nil)
6
+ @ping_successful = ping_successful
7
+ @duration = duration
8
+ end
9
+
10
+ def ping(*args); @ping_successful; end
11
+ def duration; @duration; end
12
+ end
13
+
14
+ it "should set the time of ping in milliseconds" do
15
+ config = config_stub(:pinger => PingStub.new(true, 0.225))
16
+ subject = Outpost::Scouts::Ping.new "test", config
17
+ subject.execute
18
+
19
+ assert_equal 225, subject.response_time
20
+ end
21
+
22
+ it "should set the time to nil when it fails" do
23
+ config = config_stub(:pinger => PingStub.new(false))
24
+ subject = Outpost::Scouts::Ping.new "test", config
25
+ subject.execute
26
+
27
+ refute subject.response_time
28
+ end
29
+
30
+ private
31
+
32
+ def config_stub(options={})
33
+ options = {:host => 'localhost'}.merge options
34
+
35
+ build_stub(:options => options)
36
+ end
37
+
38
+ def pinger_stub(should_respond, time=nil)
39
+ build_stub(:ping => should_respond, :duration => time)
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ module Support
2
+ module NothingRaised
3
+ # Inspired by assert_raises from minitest
4
+ def assert_nothing_raised(&block)
5
+ block.call
6
+ rescue Exception => e
7
+ flunk "No exception expected, but #{mu_pp(e.class)} was raised."
8
+ end
9
+ end
10
+ end
@@ -20,5 +20,4 @@ class Server
20
20
  end
21
21
  end
22
22
  end
23
-
24
23
  end
@@ -0,0 +1,11 @@
1
+ module Support
2
+ module Stubs
3
+ def build_stub(params={})
4
+ OpenStruct.new.tap do |stub|
5
+ params.each do |key, val|
6
+ stub.send "#{key}=", val
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
data/test/test_helper.rb CHANGED
@@ -1,21 +1,23 @@
1
+ require 'rubygems'
1
2
  require 'bundler'
2
3
  Bundler.setup(:default, :test)
3
4
 
4
5
  require 'ruby-debug'
6
+ require 'ostruct'
5
7
  require 'minitest/spec'
6
8
  require 'minitest/autorun'
7
9
 
8
10
  # Integration test helpers
9
11
  require 'support/test_app'
10
12
  require 'support/server'
13
+ require 'support/stubs'
14
+ require 'support/nothing_raised'
11
15
 
12
16
  require 'outpost'
13
17
  require 'outpost/expectations'
18
+ require 'outpost/notifiers'
19
+ require 'outpost/scouts'
14
20
 
15
- # Inspired by assert_raises from minitest
16
- def assert_nothing_raised(&block)
17
- block.call
18
- rescue Exception => e
19
- flunk "No exception expected, but #{mu_pp(e.class)} was raised."
20
- end
21
+ include Support::Stubs
22
+ include Support::NothingRaised
21
23
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outpost
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 1
8
+ - 2
8
9
  - 0
9
- version: 0.1.0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Vinicius Baggio Fuentes
@@ -14,24 +15,10 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-02-01 00:00:00 -02:00
18
+ date: 2011-02-12 00:00:00 -02:00
18
19
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: net-ping
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 3
31
- - 7
32
- version: 1.3.7
33
- type: :runtime
34
- version_requirements: *id001
20
+ dependencies: []
21
+
35
22
  description: Simple service monitoring with a clean DSL for configuration.
36
23
  email: vinibaggio@gmail.com
37
24
  executables: []
@@ -41,16 +28,23 @@ extensions: []
41
28
  extra_rdoc_files: []
42
29
 
43
30
  files:
31
+ - .gitignore
32
+ - CHANGELOG.rdoc
44
33
  - Gemfile
45
34
  - Gemfile.lock
35
+ - MIT-LICENSE
46
36
  - README.markdown
47
37
  - Rakefile
38
+ - TODO.md
48
39
  - lib/outpost.rb
49
- - lib/outpost/dsl.rb
40
+ - lib/outpost/application.rb
50
41
  - lib/outpost/expectations.rb
51
42
  - lib/outpost/expectations/response_body.rb
52
43
  - lib/outpost/expectations/response_code.rb
53
44
  - lib/outpost/expectations/response_time.rb
45
+ - lib/outpost/notifiers.rb
46
+ - lib/outpost/notifiers/campfire.rb
47
+ - lib/outpost/notifiers/email.rb
54
48
  - lib/outpost/report.rb
55
49
  - lib/outpost/scout.rb
56
50
  - lib/outpost/scout_config.rb
@@ -59,16 +53,23 @@ files:
59
53
  - lib/outpost/scouts/ping.rb
60
54
  - lib/outpost/version.rb
61
55
  - outpost.gemspec
62
- - test/integration/basic_dsl_test.rb
56
+ - test/integration/basic_application_test.rb
63
57
  - test/integration/more_complex_test.rb
58
+ - test/integration/notifiers_test.rb
64
59
  - test/outpost/dsl_test.rb
65
60
  - test/outpost/expectations/response_body_test.rb
66
61
  - test/outpost/expectations/response_code_test.rb
67
62
  - test/outpost/expectations/response_time_test.rb
63
+ - test/outpost/notifiers/campfire_test.rb
64
+ - test/outpost/notifiers/email_test.rb
68
65
  - test/outpost/report_test.rb
69
66
  - test/outpost/scout_config_test.rb
70
67
  - test/outpost/scout_test.rb
68
+ - test/outpost/scouts/http_test.rb
69
+ - test/outpost/scouts/ping_test.rb
70
+ - test/support/nothing_raised.rb
71
71
  - test/support/server.rb
72
+ - test/support/stubs.rb
72
73
  - test/support/test_app.rb
73
74
  - test/test_helper.rb
74
75
  has_rdoc: true
@@ -85,6 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - ">="
87
88
  - !ruby/object:Gem::Version
89
+ hash: 3
88
90
  segments:
89
91
  - 0
90
92
  version: "0"
@@ -93,6 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  requirements:
94
96
  - - ">="
95
97
  - !ruby/object:Gem::Version
98
+ hash: 3
96
99
  segments:
97
100
  - 0
98
101
  version: "0"
@@ -104,15 +107,22 @@ signing_key:
104
107
  specification_version: 3
105
108
  summary: Simple service monitoring with a clean DSL for configuration.
106
109
  test_files:
107
- - test/integration/basic_dsl_test.rb
110
+ - test/integration/basic_application_test.rb
108
111
  - test/integration/more_complex_test.rb
112
+ - test/integration/notifiers_test.rb
109
113
  - test/outpost/dsl_test.rb
110
114
  - test/outpost/expectations/response_body_test.rb
111
115
  - test/outpost/expectations/response_code_test.rb
112
116
  - test/outpost/expectations/response_time_test.rb
117
+ - test/outpost/notifiers/campfire_test.rb
118
+ - test/outpost/notifiers/email_test.rb
113
119
  - test/outpost/report_test.rb
114
120
  - test/outpost/scout_config_test.rb
115
121
  - test/outpost/scout_test.rb
122
+ - test/outpost/scouts/http_test.rb
123
+ - test/outpost/scouts/ping_test.rb
124
+ - test/support/nothing_raised.rb
116
125
  - test/support/server.rb
126
+ - test/support/stubs.rb
117
127
  - test/support/test_app.rb
118
128
  - test/test_helper.rb
data/lib/outpost/dsl.rb DELETED
@@ -1,54 +0,0 @@
1
- module Outpost
2
- class DSL
3
- class << self
4
- attr_reader :scouts
5
-
6
- def using(scouts, &block)
7
- @scouts ||= Hash.new { |h, k| h[k] = {} }
8
-
9
- config = ScoutConfig.new
10
- config.instance_eval(&block)
11
-
12
- scouts.each do |scout, description|
13
- @scouts[scout][:description] = description
14
- @scouts[scout][:config] = config
15
- end
16
- end
17
- end
18
-
19
- attr_reader :last_status, :reports
20
-
21
- def run
22
- @reports = self.class.scouts.map do |scout, options|
23
- run_scout(scout, options)
24
- end
25
-
26
- statuses = @reports.map { |r| r.status }
27
-
28
- @last_status = Report.summarize(statuses)
29
- end
30
-
31
- def up?
32
- @last_status == :up
33
- end
34
-
35
- def down?
36
- @last_status == :down
37
- end
38
-
39
- def messages
40
- reports.map { |r| r.to_s }
41
- end
42
-
43
- def run_scout(scout, options)
44
- scout_instance = scout.new(options[:description], options[:config])
45
-
46
- params = {
47
- :name => scout.name,
48
- :description => options[:description],
49
- :status => scout_instance.run
50
- }
51
- Report.new(params)
52
- end
53
- end
54
- end