Skip to content

Commit

Permalink
added rough spec restored from data recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
auxesis committed Dec 15, 2009
1 parent 24134c1 commit ee836af
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions spec/persistence/sqlite3_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'flapjack', 'persistence', 'couch')
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'flapjack', 'transports', 'result')
require File.join(File.dirname(__FILE__), '..', 'helpers')

describe "couchdb persistence backend" do

it "should query its parent's statuses" do

backend_options = { :host => "localhost",
:port => "5984",
:database => "flapjack_production",
:log => MockLogger.new }

# setup adapter
backend = Flapjack::Persistence::Couch.new(backend_options)

# check is failing
#parent = Flapjack::Persistence::Couch::Document.new(:command => "exit 1", :name => "failing parent")
#parent.save.should be_true


db.execute(%(INSERT INTO "checks" ("id", "command", "status", "enabled", "name") VALUES (1, 'exit 2', 2, 't', 'failing parent')))
# create check that is passing, but has a failing parent
db.execute(%(INSERT INTO "checks" ("id", "command", "status", "enabled", "name") VALUES (2, 'exit 0', 0, 't', 'passing child')))
db.execute(%(INSERT INTO "related_checks" ("id", "parent_id", "child_id") VALUES (1, 1, 2)))

# test that failing parent check doesn't fail
raw_result = {:check_id => 1, :retval => 2}
result = Flapjack::Transport::Result.new(:result => raw_result)

backend.any_parents_failed?(result).should be_false

# test that passing child check does fail
raw_result = {:check_id => 2, :retval => 0}
result = Flapjack::Transport::Result.new(:result => raw_result)
backend.any_parents_failed?(result).should be_true
end

it "should persist a result" do
backend_options = { :database => "/tmp/flapjack.db",
:auto_migrate => true,
:log => MockLogger.new }

# setup adapter
backend = Flapjack::Persistence::Sqlite3.new(backend_options)

# save check
db = SQLite3::Database.new(backend_options[:database])
db.execute(%(INSERT INTO "checks" ("id", "command", "status", "enabled", "name") VALUES (3, 'exit 2', 2, 't', 'failing parent')))

# test persistence
raw_result = {:check_id => 3, :retval => 2}
result = Flapjack::Transport::Result.new(:result => raw_result)

backend.save(result).should be_true

# verify it was updated
db.execute(%(SELECT status FROM "checks" WHERE id = '3')).first.first.to_i.should == 2
end

it "should create an event" do
backend_options = { :database => "/tmp/flapjack.db",
:auto_migrate => true,
:log => MockLogger.new }

# setup adapter
backend = Flapjack::Persistence::Sqlite3.new(backend_options)

# create a check to attach event to
db = SQLite3::Database.new(backend_options[:database])
db.execute(%(INSERT INTO "checks" ("id", "command", "status", "enabled", "name") VALUES (4, 'exit 2', 2, 't', 'failing parent')))

# test event is created
raw_result = {:check_id => 4, :retval => 2}
result = Flapjack::Transport::Result.new(:result => raw_result)

backend.create_event(result).should be_true

# test event is actually created
db.execute(%(SELECT count(*) FROM "events" WHERE check_id = 4)).first.first.to_i.should == 1
end

end

0 comments on commit ee836af

Please sign in to comment.