eye 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +31 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +132 -0
- data/Rakefile +18 -0
- data/bin/eye +282 -0
- data/bin/loader_eye +56 -0
- data/examples/processes/em.rb +56 -0
- data/examples/processes/forking.rb +20 -0
- data/examples/processes/sample.rb +144 -0
- data/examples/rbenv.eye +11 -0
- data/examples/test.eye +65 -0
- data/examples/unicorn.eye +29 -0
- data/eye.gemspec +37 -0
- data/lib/eye.rb +25 -0
- data/lib/eye/application.rb +65 -0
- data/lib/eye/checker.rb +118 -0
- data/lib/eye/checker/cpu.rb +27 -0
- data/lib/eye/checker/file_ctime.rb +29 -0
- data/lib/eye/checker/file_size.rb +38 -0
- data/lib/eye/checker/http.rb +94 -0
- data/lib/eye/checker/memory.rb +27 -0
- data/lib/eye/checker/socket.rb +148 -0
- data/lib/eye/checker/validation.rb +49 -0
- data/lib/eye/child_process.rb +75 -0
- data/lib/eye/client.rb +32 -0
- data/lib/eye/control.rb +2 -0
- data/lib/eye/controller.rb +43 -0
- data/lib/eye/controller/commands.rb +64 -0
- data/lib/eye/controller/helpers.rb +61 -0
- data/lib/eye/controller/load.rb +224 -0
- data/lib/eye/controller/send_command.rb +88 -0
- data/lib/eye/controller/status.rb +136 -0
- data/lib/eye/dsl.rb +52 -0
- data/lib/eye/dsl/application_opts.rb +33 -0
- data/lib/eye/dsl/chain.rb +12 -0
- data/lib/eye/dsl/child_process_opts.rb +7 -0
- data/lib/eye/dsl/config_opts.rb +11 -0
- data/lib/eye/dsl/group_opts.rb +27 -0
- data/lib/eye/dsl/helpers.rb +12 -0
- data/lib/eye/dsl/main.rb +58 -0
- data/lib/eye/dsl/opts.rb +88 -0
- data/lib/eye/dsl/process_opts.rb +21 -0
- data/lib/eye/dsl/pure_opts.rb +132 -0
- data/lib/eye/dsl/validate.rb +41 -0
- data/lib/eye/group.rb +125 -0
- data/lib/eye/group/chain.rb +68 -0
- data/lib/eye/io/unix_server.rb +44 -0
- data/lib/eye/io/unix_socket.rb +39 -0
- data/lib/eye/loader.rb +13 -0
- data/lib/eye/logger.rb +80 -0
- data/lib/eye/process.rb +83 -0
- data/lib/eye/process/child.rb +61 -0
- data/lib/eye/process/commands.rb +256 -0
- data/lib/eye/process/config.rb +70 -0
- data/lib/eye/process/controller.rb +72 -0
- data/lib/eye/process/data.rb +46 -0
- data/lib/eye/process/monitor.rb +97 -0
- data/lib/eye/process/notify.rb +17 -0
- data/lib/eye/process/scheduler.rb +50 -0
- data/lib/eye/process/states.rb +92 -0
- data/lib/eye/process/states_history.rb +62 -0
- data/lib/eye/process/system.rb +60 -0
- data/lib/eye/process/trigger.rb +32 -0
- data/lib/eye/process/watchers.rb +67 -0
- data/lib/eye/server.rb +51 -0
- data/lib/eye/settings.rb +35 -0
- data/lib/eye/system.rb +145 -0
- data/lib/eye/system_resources.rb +83 -0
- data/lib/eye/trigger.rb +53 -0
- data/lib/eye/trigger/flapping.rb +24 -0
- data/lib/eye/utils.rb +5 -0
- data/lib/eye/utils/alive_array.rb +31 -0
- data/lib/eye/utils/celluloid_chain.rb +51 -0
- data/lib/eye/utils/leak_19.rb +7 -0
- data/lib/eye/utils/tail.rb +20 -0
- data/spec/checker/cpu_spec.rb +58 -0
- data/spec/checker/file_ctime_spec.rb +34 -0
- data/spec/checker/file_size_spec.rb +107 -0
- data/spec/checker/http_spec.rb +109 -0
- data/spec/checker/memory_spec.rb +64 -0
- data/spec/checker/socket_spec.rb +116 -0
- data/spec/checker_spec.rb +188 -0
- data/spec/child_process/child_process_spec.rb +46 -0
- data/spec/client_server_spec.rb +34 -0
- data/spec/controller/commands_spec.rb +92 -0
- data/spec/controller/controller_spec.rb +133 -0
- data/spec/controller/find_objects_spec.rb +150 -0
- data/spec/controller/group_spec.rb +110 -0
- data/spec/controller/intergration_spec.rb +327 -0
- data/spec/controller/load_spec.rb +326 -0
- data/spec/controller/races_spec.rb +70 -0
- data/spec/controller/stop_on_delete_spec.rb +157 -0
- data/spec/dsl/chain_spec.rb +140 -0
- data/spec/dsl/checks_spec.rb +202 -0
- data/spec/dsl/config_spec.rb +44 -0
- data/spec/dsl/dsl_spec.rb +73 -0
- data/spec/dsl/getter_spec.rb +223 -0
- data/spec/dsl/integration_spec.rb +311 -0
- data/spec/dsl/load_spec.rb +52 -0
- data/spec/dsl/process_spec.rb +330 -0
- data/spec/dsl/sub_procs_spec.rb +93 -0
- data/spec/dsl/with_server_spec.rb +104 -0
- data/spec/example/em.rb +57 -0
- data/spec/example/forking.rb +20 -0
- data/spec/example/sample.rb +154 -0
- data/spec/fixtures/dsl/0.rb +8 -0
- data/spec/fixtures/dsl/0a.rb +8 -0
- data/spec/fixtures/dsl/0c.rb +8 -0
- data/spec/fixtures/dsl/1.rb +5 -0
- data/spec/fixtures/dsl/bad.eye +6 -0
- data/spec/fixtures/dsl/configs/1.eye +3 -0
- data/spec/fixtures/dsl/configs/2.eye +1 -0
- data/spec/fixtures/dsl/configs/3.eye +1 -0
- data/spec/fixtures/dsl/configs/4.eye +3 -0
- data/spec/fixtures/dsl/empty.eye +20 -0
- data/spec/fixtures/dsl/include_test.eye +5 -0
- data/spec/fixtures/dsl/include_test/1.rb +6 -0
- data/spec/fixtures/dsl/include_test/ha.rb +4 -0
- data/spec/fixtures/dsl/include_test2.eye +5 -0
- data/spec/fixtures/dsl/integration.eye +30 -0
- data/spec/fixtures/dsl/integration2.eye +32 -0
- data/spec/fixtures/dsl/integration_locks.eye +30 -0
- data/spec/fixtures/dsl/integration_sor.eye +32 -0
- data/spec/fixtures/dsl/integration_sor2.eye +27 -0
- data/spec/fixtures/dsl/integration_sor3.eye +32 -0
- data/spec/fixtures/dsl/load.eye +25 -0
- data/spec/fixtures/dsl/load2.eye +7 -0
- data/spec/fixtures/dsl/load2_dup2.eye +13 -0
- data/spec/fixtures/dsl/load2_dup_pid.eye +7 -0
- data/spec/fixtures/dsl/load3.eye +10 -0
- data/spec/fixtures/dsl/load4.eye +7 -0
- data/spec/fixtures/dsl/load5.eye +8 -0
- data/spec/fixtures/dsl/load6.eye +17 -0
- data/spec/fixtures/dsl/load_dubls.eye +36 -0
- data/spec/fixtures/dsl/load_dup_ex_names.eye +15 -0
- data/spec/fixtures/dsl/load_error.eye +5 -0
- data/spec/fixtures/dsl/load_error_folder/load3.eye +10 -0
- data/spec/fixtures/dsl/load_error_folder/load4.eye +7 -0
- data/spec/fixtures/dsl/load_folder/load3.eye +10 -0
- data/spec/fixtures/dsl/load_folder/load4.eye +7 -0
- data/spec/fixtures/dsl/load_int.eye +8 -0
- data/spec/fixtures/dsl/load_int2.eye +13 -0
- data/spec/fixtures/dsl/load_logger.eye +26 -0
- data/spec/fixtures/dsl/load_logger2.eye +3 -0
- data/spec/fixtures/dsl/long_load.eye +5 -0
- data/spec/fixtures/dsl/subfolder1/proc1.rb +3 -0
- data/spec/fixtures/dsl/subfolder2.eye +9 -0
- data/spec/fixtures/dsl/subfolder2/common.rb +1 -0
- data/spec/fixtures/dsl/subfolder2/proc2.rb +3 -0
- data/spec/fixtures/dsl/subfolder2/sub/proc3.rb +6 -0
- data/spec/fixtures/dsl/subfolder3.eye +8 -0
- data/spec/fixtures/dsl/subfolder3/common.rb +1 -0
- data/spec/fixtures/dsl/subfolder3/proc4.rb +3 -0
- data/spec/fixtures/dsl/subfolder3/sub/proc5.rb +6 -0
- data/spec/fixtures/dsl/subfolder4.eye +6 -0
- data/spec/fixtures/dsl/subfolder4/a.rb +2 -0
- data/spec/fixtures/dsl/subfolder4/b.rb +1 -0
- data/spec/fixtures/dsl/subfolder4/c.rb +1 -0
- data/spec/mock_spec.rb +32 -0
- data/spec/process/checks/child_checks_spec.rb +79 -0
- data/spec/process/checks/cpu_spec.rb +114 -0
- data/spec/process/checks/ctime_spec.rb +43 -0
- data/spec/process/checks/fsize_spec.rb +22 -0
- data/spec/process/checks/http_spec.rb +52 -0
- data/spec/process/checks/intergration_spec.rb +32 -0
- data/spec/process/checks/memory_spec.rb +113 -0
- data/spec/process/child_process_spec.rb +125 -0
- data/spec/process/config_spec.rb +75 -0
- data/spec/process/controller_spec.rb +173 -0
- data/spec/process/monitoring_spec.rb +180 -0
- data/spec/process/restart_spec.rb +174 -0
- data/spec/process/scheduler_spec.rb +150 -0
- data/spec/process/start_spec.rb +261 -0
- data/spec/process/states_history_spec.rb +118 -0
- data/spec/process/stop_spec.rb +150 -0
- data/spec/process/system_spec.rb +100 -0
- data/spec/process/triggers/flapping_spec.rb +81 -0
- data/spec/process/update_config_spec.rb +63 -0
- data/spec/spec_helper.rb +120 -0
- data/spec/support/rr_celluloid.rb +36 -0
- data/spec/support/scheduler_hack.rb +16 -0
- data/spec/support/spec_support.rb +164 -0
- data/spec/system_resources_spec.rb +59 -0
- data/spec/system_spec.rb +170 -0
- data/spec/utils/alive_array_spec.rb +50 -0
- data/spec/utils/celluloid_chain_spec.rb +82 -0
- data/spec/utils/tail_spec.rb +21 -0
- metadata +558 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
def chhttp(cfg = {})
|
4
|
+
Eye::Checker.create(nil, {:type => :http, :every => 5.seconds,
|
5
|
+
:times => 1, :url => "http://localhost:3000/", :kind => :success,
|
6
|
+
:pattern => /OK/, :timeout => 2}.merge(cfg))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Eye::Checker::Http" do
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
FakeWeb.clean_registry
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "get_value" do
|
16
|
+
subject{ chhttp }
|
17
|
+
|
18
|
+
it "initialize" do
|
19
|
+
subject.instance_variable_get(:@kind).should == Net::HTTPSuccess
|
20
|
+
subject.instance_variable_get(:@pattern).should == /OK/
|
21
|
+
subject.instance_variable_get(:@open_timeout).should == 2
|
22
|
+
subject.instance_variable_get(:@read_timeout).should == 2
|
23
|
+
end
|
24
|
+
|
25
|
+
it "without url" do
|
26
|
+
chhttp(:url => nil).uri.should == URI.parse('http://127.0.0.1')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "get_value" do
|
30
|
+
FakeWeb.register_uri(:get, "http://localhost:3000/", :body => "Somebody OK")
|
31
|
+
subject.get_value[:result].body.should == "Somebody OK"
|
32
|
+
|
33
|
+
subject.human_value(subject.get_value).should == "200=0Kb"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "get_value exception" do
|
37
|
+
stub(subject.session).start{ raise Timeout::Error, "timeout" }
|
38
|
+
subject.get_value.should == {:exception => :timeout}
|
39
|
+
|
40
|
+
subject.human_value(subject.get_value).should == "T-out"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "get_value raised" do
|
44
|
+
stub(subject.session).start{ raise "something" }
|
45
|
+
subject.get_value.should == {:exception => "something"}
|
46
|
+
|
47
|
+
subject.human_value(subject.get_value).should == "Err"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "good?" do
|
53
|
+
subject{ chhttp }
|
54
|
+
|
55
|
+
it "good" do
|
56
|
+
FakeWeb.register_uri(:get, "http://localhost:3000/", :body => "Somebody OK")
|
57
|
+
subject.check.should == true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "good pattern is string" do
|
61
|
+
subject = chhttp(:pattern => "OK")
|
62
|
+
FakeWeb.register_uri(:get, "http://localhost:3000/", :body => "Somebody OK")
|
63
|
+
subject.check.should == true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "bad pattern" do
|
67
|
+
FakeWeb.register_uri(:get, "http://localhost:3000/", :body => "Somebody bad")
|
68
|
+
subject.check.should == false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "bad pattern string" do
|
72
|
+
subject = chhttp(:pattern => "OK")
|
73
|
+
FakeWeb.register_uri(:get, "http://localhost:3000/", :body => "Somebody bad")
|
74
|
+
subject.check.should == false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "not 200" do
|
78
|
+
FakeWeb.register_uri(:get, "http://localhost:3000/bla", :body => "Somebody OK", :status => [500, 'err'])
|
79
|
+
subject.check.should == false
|
80
|
+
end
|
81
|
+
|
82
|
+
it "without patter its ok" do
|
83
|
+
subject = chhttp(:pattern => nil)
|
84
|
+
FakeWeb.register_uri(:get, "http://localhost:3000/", :body => "Somebody OK")
|
85
|
+
subject.check.should == true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "validates" do
|
90
|
+
it "ok" do
|
91
|
+
Eye::Checker.validate!({:type => :http, :every => 5.seconds,
|
92
|
+
:times => 1, :url => "http://localhost:3000/", :kind => :success,
|
93
|
+
:pattern => /OK/, :timeout => 2})
|
94
|
+
end
|
95
|
+
|
96
|
+
it "without param url" do
|
97
|
+
expect{ Eye::Checker.validate!({:type => :http, :every => 5.seconds,
|
98
|
+
:times => 1, :kind => :success,
|
99
|
+
:pattern => /OK/, :timeout => 2}) }.to raise_error(Eye::Checker::Validation::Error)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "bad param timeout" do
|
103
|
+
expect{ Eye::Checker.validate!({:type => :http, :every => 5.seconds,
|
104
|
+
:times => 1, :kind => :success, :url => "http://localhost:3000/",
|
105
|
+
:pattern => /OK/, :timeout => :fix}) }.to raise_error(Eye::Checker::Validation::Error)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
def chmem(cfg = {})
|
4
|
+
Eye::Checker.create(123, {:type => :memory, :every => 5.seconds,
|
5
|
+
:times => 1}.merge(cfg))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Eye::Checker::Memory" do
|
9
|
+
|
10
|
+
describe "without below" do
|
11
|
+
subject{ chmem }
|
12
|
+
|
13
|
+
it "get_value" do
|
14
|
+
mock(Eye::SystemResources).memory(123){ 65 }
|
15
|
+
subject.get_value.should == 66560
|
16
|
+
end
|
17
|
+
|
18
|
+
it "without below always true" do
|
19
|
+
stub(subject).get_value{ 315 }
|
20
|
+
subject.check.should == true
|
21
|
+
|
22
|
+
stub(subject).get_value{ 320 }
|
23
|
+
subject.check.should == true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with below" do
|
28
|
+
subject{ chmem(:below => 300.megabytes) }
|
29
|
+
|
30
|
+
it "good" do
|
31
|
+
stub(subject).get_value{ 200.megabytes }
|
32
|
+
subject.check.should == true
|
33
|
+
|
34
|
+
stub(subject).get_value{ 250.megabytes }
|
35
|
+
subject.check.should == true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "good" do
|
39
|
+
stub(subject).get_value{ 250.megabytes }
|
40
|
+
subject.check.should == true
|
41
|
+
|
42
|
+
stub(subject).get_value{ 350.megabytes }
|
43
|
+
subject.check.should == false
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "validates" do
|
49
|
+
it "ok" do
|
50
|
+
Eye::Checker.validate!({:type => :memory, :every => 5.seconds, :times => 1, :below => 10.0.bytes})
|
51
|
+
end
|
52
|
+
|
53
|
+
it "bad param below" do
|
54
|
+
expect{ Eye::Checker.validate!({:type => :memory, :every => 5.seconds, :times => 1, :below => {1 => 2}}) }.to raise_error(Eye::Checker::Validation::Error)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "unknown params" do
|
58
|
+
expect{ Eye::Checker.validate!({:hello => true, :type => :memory, :every => 5.seconds, :times => 1, :below => 10.0.bytes})}.to raise_error(Eye::Checker::Validation::Error)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
def chsock(cfg = {})
|
4
|
+
Eye::Checker.create(nil, {:type => :socket, :every => 5.seconds,
|
5
|
+
:times => 1, :addr => 'tcp://127.0.0.1:33231', :send_data => "ping",
|
6
|
+
:expect_data => /pong/, :timeout => 2}.merge(cfg))
|
7
|
+
end
|
8
|
+
|
9
|
+
def chsockb(cfg = {})
|
10
|
+
Eye::Checker.create(nil, {:type => :socket, :every => 5.seconds,
|
11
|
+
:times => 1, :addr => 'tcp://127.0.0.1:33232', :protocol => :em_object, :send_data => {},
|
12
|
+
:expect_data => /pong/, :timeout => 2}.merge(cfg))
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Socket Checker" do
|
16
|
+
%w[ tcp://127.0.0.1:33231 unix:/tmp/em_test_sock_spec].each do |addr|
|
17
|
+
describe "socket: '#{addr}'" do
|
18
|
+
before :each do
|
19
|
+
start_ok_process(C.p4)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "good answer" do
|
23
|
+
c = chsock(:addr => addr)
|
24
|
+
c.get_value.should == {:result => 'pong'}
|
25
|
+
c.check.should == true
|
26
|
+
|
27
|
+
c = chsock(:addr => addr, :expect_data => "pong") # string result ok too
|
28
|
+
c.check.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "timeouted" do
|
32
|
+
c = chsock(:addr => addr, :send_data => "timeout")
|
33
|
+
c.get_value.should == {:exception => :timeout}
|
34
|
+
c.check.should == false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "bad answer" do
|
38
|
+
c = chsock(:addr => addr, :send_data => "bad")
|
39
|
+
c.get_value.should == {:result => 'what'}
|
40
|
+
c.check.should == false
|
41
|
+
|
42
|
+
c = chsock(:addr => addr, :send_data => "bad", :expect_data => "pong") # string result bad too
|
43
|
+
c.check.should == false
|
44
|
+
end
|
45
|
+
|
46
|
+
it "socket not found" do
|
47
|
+
@process.stop
|
48
|
+
c = chsock(:addr => addr.chop)
|
49
|
+
if addr =~ /tcp/
|
50
|
+
c.get_value.should == {:exception => "Connection refused - connect(2)"}
|
51
|
+
else
|
52
|
+
c.get_value[:exception].should include("No such file or directory")
|
53
|
+
end
|
54
|
+
c.check.should == false
|
55
|
+
end
|
56
|
+
|
57
|
+
it "check responding without send_data" do
|
58
|
+
c = chsock(:addr => addr, :send_data => nil, :expect_data => nil)
|
59
|
+
c.get_value.should == {:result => :listen}
|
60
|
+
c.check.should == true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "check responding without send_data" do
|
64
|
+
c = chsock(:addr => addr.chop, :send_data => nil, :expect_data => nil)
|
65
|
+
if addr =~ /tcp/
|
66
|
+
c.get_value.should == {:exception => "Connection refused - connect(2)"}
|
67
|
+
else
|
68
|
+
c.get_value[:exception].should include("No such file or directory")
|
69
|
+
end
|
70
|
+
c.check.should == false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "em object protocol" do
|
77
|
+
before :each do
|
78
|
+
start_ok_process(C.p4)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "good answer" do
|
82
|
+
c = chsockb(:send_data => {:command => 'ping'}, :expect_data => 'pong')
|
83
|
+
c.get_value.should == {:result => 'pong'}
|
84
|
+
c.check.should == true
|
85
|
+
|
86
|
+
c = chsockb(:send_data => {:command => 'ping'}, :expect_data => /pong/)
|
87
|
+
c.check.should == true
|
88
|
+
|
89
|
+
c = chsockb(:send_data => {:command => 'ping'}, :expect_data => lambda{|r| r == 'pong'})
|
90
|
+
c.check.should == true
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should correctly get big message" do
|
94
|
+
c = chsockb(:send_data => {:command => 'big'})
|
95
|
+
res = c.get_value[:result]
|
96
|
+
res.size.should == 9_999_999
|
97
|
+
end
|
98
|
+
|
99
|
+
it "when raised in proc, good? == false" do
|
100
|
+
c = chsockb(:send_data => {:command => 'ping'}, :expect_data => lambda{|r| raise 'haha'})
|
101
|
+
c.check.should == false
|
102
|
+
end
|
103
|
+
|
104
|
+
it "bad answer" do
|
105
|
+
c = chsockb(:send_data => {:command => 'bad'}, :expect_data => 'pong')
|
106
|
+
c.get_value.should == {:result => 'what'}
|
107
|
+
c.check.should == false
|
108
|
+
|
109
|
+
c = chsockb(:send_data => {:command => 'bad'}, :expect_data => /pong/)
|
110
|
+
c.check.should == false
|
111
|
+
|
112
|
+
c = chsockb(:send_data => {:command => 'bad'}, :expect_data => lambda{|r| r == 'pong'})
|
113
|
+
c.check.should == false
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
class Checker1 < Eye::Checker
|
5
|
+
|
6
|
+
def get_value
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def good?(value)
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Checker2 < Eye::Checker
|
16
|
+
param :bla, [String, Symbol]
|
17
|
+
param :bla2, [String, Symbol], true
|
18
|
+
param :bla3, [String, Symbol], true, "hi"
|
19
|
+
param :bla4, [String, Symbol], false, "hi2"
|
20
|
+
param :bla5, [Fixnum, Float]
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Eye::Checker" do
|
24
|
+
|
25
|
+
it "defaults" do
|
26
|
+
@c = Checker1.new(1, {:times => 3})
|
27
|
+
@c.max_tries.should == 3
|
28
|
+
@c.min_tries.should == 3
|
29
|
+
end
|
30
|
+
|
31
|
+
it "defaults" do
|
32
|
+
@c = Checker1.new(1, {:times => [3, 5]})
|
33
|
+
@c.max_tries.should == 5
|
34
|
+
@c.min_tries.should == 3
|
35
|
+
end
|
36
|
+
|
37
|
+
it "defaults" do
|
38
|
+
@c = Checker1.new(1, {})
|
39
|
+
@c.max_tries.should == 1
|
40
|
+
@c.min_tries.should == 1
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "one digit" do
|
44
|
+
before :each do
|
45
|
+
@c = Checker1.new(1, {:times => 3, :bla => 1})
|
46
|
+
end
|
47
|
+
|
48
|
+
it "times 3 from 3" do
|
49
|
+
@c.check.should == true
|
50
|
+
@c.check.should == true
|
51
|
+
@c.check.should == true
|
52
|
+
@c.check.should == true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "times 3 from 3" do
|
56
|
+
stub(@c).get_value{true}
|
57
|
+
@c.check.should == true
|
58
|
+
stub(@c).get_value{false}
|
59
|
+
@c.check.should == true
|
60
|
+
stub(@c).get_value{false}
|
61
|
+
@c.check.should == true
|
62
|
+
|
63
|
+
stub(@c).get_value{true}
|
64
|
+
@c.check.should == true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "times 3 from 3" do
|
68
|
+
stub(@c).get_value{true}
|
69
|
+
@c.check.should == true
|
70
|
+
stub(@c).get_value{false}
|
71
|
+
@c.check.should == true
|
72
|
+
stub(@c).get_value{false}
|
73
|
+
@c.check.should == true
|
74
|
+
|
75
|
+
stub(@c).get_value{false}
|
76
|
+
@c.check.should == false
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "two digits" do
|
82
|
+
before :each do
|
83
|
+
@c = Checker1.new(1, {:times => [2,5], :bla => 1})
|
84
|
+
end
|
85
|
+
|
86
|
+
it "2 from 5" do
|
87
|
+
@c.check.should == true
|
88
|
+
@c.check.should == true
|
89
|
+
@c.check.should == true
|
90
|
+
@c.check.should == true
|
91
|
+
@c.check.should == true
|
92
|
+
@c.check.should == true
|
93
|
+
end
|
94
|
+
|
95
|
+
it "times 2 from 5" do
|
96
|
+
stub(@c).get_value{true}
|
97
|
+
@c.check.should == true
|
98
|
+
stub(@c).get_value{false}
|
99
|
+
@c.check.should == true
|
100
|
+
stub(@c).get_value{true}
|
101
|
+
@c.check.should == true
|
102
|
+
|
103
|
+
stub(@c).get_value{true}
|
104
|
+
@c.check.should == true
|
105
|
+
|
106
|
+
stub(@c).get_value{true}
|
107
|
+
@c.check.should == true
|
108
|
+
|
109
|
+
stub(@c).get_value{true}
|
110
|
+
@c.check.should == true
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
it "times 2 from 5" do
|
115
|
+
stub(@c).get_value{true}
|
116
|
+
@c.check.should == true
|
117
|
+
stub(@c).get_value{false}
|
118
|
+
@c.check.should == true
|
119
|
+
stub(@c).get_value{false}
|
120
|
+
@c.check.should == true
|
121
|
+
|
122
|
+
stub(@c).get_value{true}
|
123
|
+
@c.check.should == true
|
124
|
+
|
125
|
+
stub(@c).get_value{true}
|
126
|
+
@c.check.should == false
|
127
|
+
|
128
|
+
stub(@c).get_value{true}
|
129
|
+
@c.check.should == false
|
130
|
+
|
131
|
+
stub(@c).get_value{true}
|
132
|
+
@c.check.should == true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "default validates" do
|
137
|
+
it "validate by default" do
|
138
|
+
Checker1.validate({:times => 3})
|
139
|
+
end
|
140
|
+
|
141
|
+
it "validate by default" do
|
142
|
+
expect{ Checker1.validate({:times => "jopa"}) }.to raise_error(Eye::Checker::Validation::Error)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "defaults every" do
|
147
|
+
@c = Checker1.new(nil, {:times => 3})
|
148
|
+
@c.every.should == 5
|
149
|
+
end
|
150
|
+
|
151
|
+
it "not defaults every" do
|
152
|
+
@c = Checker1.new(nil, {:times => 3, :every => 10})
|
153
|
+
@c.every.should == 10
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "validates" do
|
157
|
+
it "validate ok" do
|
158
|
+
Checker2.validate({:bla2 => :a111})
|
159
|
+
Checker2.validate({:bla2 => "111"})
|
160
|
+
Checker2.validate({:bla2 => "111", :bla => :bla})
|
161
|
+
Checker2.validate({:bla2 => "111", :bla5 => 10.minutes})
|
162
|
+
Checker2.validate({:bla2 => "111", :bla5 => 15.4.seconds})
|
163
|
+
|
164
|
+
c = Checker2.new(nil, :bla2 => :a111)
|
165
|
+
c.bla.should == nil
|
166
|
+
c.bla2.should == :a111
|
167
|
+
c.bla3.should == 'hi'
|
168
|
+
c.bla4.should == 'hi2'
|
169
|
+
|
170
|
+
c = Checker2.new(nil, :bla2 => :a111, :bla3 => "ho", :bla => 'bla')
|
171
|
+
c.bla.should == 'bla'
|
172
|
+
c.bla2.should == :a111
|
173
|
+
c.bla3.should == 'ho'
|
174
|
+
c.bla4.should == 'hi2'
|
175
|
+
end
|
176
|
+
|
177
|
+
it "validate bad" do
|
178
|
+
expect{ Checker2.validate({}) }.to raise_error
|
179
|
+
expect{ Checker2.validate({:bla => :bla}) }.to raise_error
|
180
|
+
expect{ Checker2.validate({:bla2 => 123}) }.to raise_error
|
181
|
+
expect{ Checker2.validate({:bla2 => :hi, :bla3 => {}}) }.to raise_error
|
182
|
+
expect{ Checker2.validate({:bla => :bla, :bla3 => 1, :bla4 => 2}) }.to raise_error
|
183
|
+
expect{ Checker2.validate({:bla2 => :hi, :bla5 => []}) }.to raise_error
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|