ipvs_litmus 0.0.1

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.
Files changed (44) hide show
  1. data/.gitignore +17 -0
  2. data/.rake_commit +1 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +22 -0
  7. data/README.md +31 -0
  8. data/Rakefile +6 -0
  9. data/bin/litmus +6 -0
  10. data/bin/litmusctl +7 -0
  11. data/config.ru +4 -0
  12. data/ipvs_litmus.gemspec +25 -0
  13. data/lib/facts/loadaverage.rb +6 -0
  14. data/lib/ipvs_litmus/app.rb +48 -0
  15. data/lib/ipvs_litmus/cli/admin.rb +86 -0
  16. data/lib/ipvs_litmus/cli/server.rb +62 -0
  17. data/lib/ipvs_litmus/configuration.rb +20 -0
  18. data/lib/ipvs_litmus/dependency/http.rb +27 -0
  19. data/lib/ipvs_litmus/forced_health.rb +18 -0
  20. data/lib/ipvs_litmus/health.rb +35 -0
  21. data/lib/ipvs_litmus/metric/available_memory.rb +32 -0
  22. data/lib/ipvs_litmus/metric/cpu_load.rb +22 -0
  23. data/lib/ipvs_litmus/service.rb +51 -0
  24. data/lib/ipvs_litmus/status_file.rb +26 -0
  25. data/lib/ipvs_litmus/version.rb +3 -0
  26. data/lib/ipvs_litmus.rb +44 -0
  27. data/spec/ipvs_litmus/app_spec.rb +215 -0
  28. data/spec/ipvs_litmus/cli/admin_spec.rb +58 -0
  29. data/spec/ipvs_litmus/cli/server_spec.rb +16 -0
  30. data/spec/ipvs_litmus/configuration_spec.rb +11 -0
  31. data/spec/ipvs_litmus/dependency/http_spec.rb +42 -0
  32. data/spec/ipvs_litmus/health_spec.rb +71 -0
  33. data/spec/ipvs_litmus/metric/available_memory_spec.rb +33 -0
  34. data/spec/ipvs_litmus/metric/cpu_load_spec.rb +39 -0
  35. data/spec/ipvs_litmus/service_spec.rb +65 -0
  36. data/spec/ipvs_litmus/status_file_spec.rb +39 -0
  37. data/spec/ipvs_litmus_spec.rb +22 -0
  38. data/spec/spec_helper.rb +21 -0
  39. data/spec/support/always_available_dependency.rb +5 -0
  40. data/spec/support/constant_metric.rb +9 -0
  41. data/spec/support/never_available_dependency.rb +5 -0
  42. data/spec/support/stub_facter.rb +9 -0
  43. data/spec/support/test.config +11 -0
  44. metadata +219 -0
@@ -0,0 +1,215 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::App do
4
+ def app
5
+ IPVSLitmus::App
6
+ end
7
+
8
+ describe "POST /force/*" do
9
+ it "creates a global upfile" do
10
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
11
+ IPVSLitmus.services['test'] = test_service
12
+
13
+ post "/force/up", :reason => "up for testing"
14
+ last_response.status.should == 201
15
+
16
+ get "/test/status"
17
+ last_response.status.should == 200
18
+ last_response.body.should match(/up for testing/)
19
+ end
20
+
21
+ it "creates a global downfile" do
22
+ test_service = IPVSLitmus::Service.new('test', [AlwaysAvailableDependency.new], [ConstantMetric.new(100)])
23
+ IPVSLitmus.services['test'] = test_service
24
+
25
+ post "/force/down", :reason => "down for testing"
26
+ last_response.status.should == 201
27
+
28
+ get "/test/status"
29
+ last_response.status.should == 503
30
+ last_response.body.should match(/down for testing/)
31
+ end
32
+
33
+ it "creates a service specific upfile" do
34
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
35
+ IPVSLitmus.services['test'] = test_service
36
+
37
+ post "/force/up/test", :reason => "up for testing"
38
+ last_response.status.should == 201
39
+
40
+ get "/test/status"
41
+ last_response.status.should == 200
42
+ last_response.body.should match(/up for testing/)
43
+ end
44
+ end
45
+
46
+ describe "DELETE /force/*" do
47
+ it "removes the global upfile" do
48
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
49
+ IPVSLitmus.services['test'] = test_service
50
+
51
+ post "/force/up", :reason => "up for testing"
52
+ last_response.status.should == 201
53
+
54
+ get "/test/status"
55
+ last_response.status.should == 200
56
+
57
+ delete "/force/up"
58
+ last_response.status.should == 200
59
+
60
+ get "/test/status"
61
+ last_response.status.should == 503
62
+ last_response.body.should_not match(/up for testing/)
63
+ end
64
+
65
+ it "removes the global downfile" do
66
+ test_service = IPVSLitmus::Service.new('test', [AlwaysAvailableDependency.new], [ConstantMetric.new(100)])
67
+ IPVSLitmus.services['test'] = test_service
68
+
69
+ post "/force/down", :reason => "down for testing"
70
+ last_response.status.should == 201
71
+
72
+ get "/test/status"
73
+ last_response.status.should == 503
74
+
75
+ delete "/force/down"
76
+ last_response.status.should == 200
77
+
78
+ get "/test/status"
79
+ last_response.should be_ok
80
+ last_response.body.should_not match(/down for testing/)
81
+ end
82
+
83
+ it "removes a service specific upfile" do
84
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
85
+ IPVSLitmus.services['test'] = test_service
86
+
87
+ post "/force/up/test", :reason => "up for testing"
88
+ last_response.status.should == 201
89
+
90
+ get "/test/status"
91
+ last_response.status.should == 200
92
+ last_response.body.should match(/up for testing/)
93
+
94
+ delete "/force/up/test"
95
+ last_response.status.should == 200
96
+
97
+ get "/test/status"
98
+ last_response.status.should == 503
99
+ end
100
+
101
+ it "404s if there is no upfile" do
102
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
103
+
104
+ delete "/up"
105
+
106
+ last_response.status.should == 404
107
+ end
108
+ end
109
+
110
+ describe "GET /:service/status" do
111
+ it "is successful when the service is passing" do
112
+ test_service = IPVSLitmus::Service.new('test', [AlwaysAvailableDependency.new], [ConstantMetric.new(100)])
113
+ IPVSLitmus.services['test'] = test_service
114
+
115
+ get "/test/status"
116
+
117
+ last_response.should be_ok
118
+ last_response.header["Content-Type"].should == "text/plain"
119
+ last_response.body.should match(/Health: 100/)
120
+ last_response.body.should match(/AlwaysAvailableDependency: OK/)
121
+ last_response.body.should match(/ConstantMetric: 100/)
122
+ end
123
+
124
+ it "is 'service unavailable' when the check fails" do
125
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
126
+ IPVSLitmus.services['test'] = test_service
127
+
128
+ get "/test/status"
129
+
130
+ last_response.status.should == 503
131
+ last_response.header["Content-Type"].should == "text/plain"
132
+ end
133
+
134
+ it "is 'not found' when the service is unknown" do
135
+ get "/unknown/status"
136
+
137
+ last_response.status.should == 404
138
+ last_response.header["Content-Type"].should == "text/plain"
139
+ end
140
+
141
+ it "is 'service unavailable' when an up file and down file exists" do
142
+ test_service = IPVSLitmus::Service.new('test', [AlwaysAvailableDependency.new], [ConstantMetric.new(100)])
143
+ IPVSLitmus.services['test'] = test_service
144
+
145
+ IPVSLitmus::StatusFile.new("up", "test").create("Up for testing")
146
+ IPVSLitmus::StatusFile.new("down", "test").create("Down for testing")
147
+
148
+ get "/test/status"
149
+
150
+ last_response.status.should == 503
151
+ last_response.body.should match(/Down for testing/)
152
+ end
153
+
154
+ it "is 'service available' when an up file exists" do
155
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
156
+ IPVSLitmus.services['test'] = test_service
157
+
158
+ IPVSLitmus::StatusFile.new("up", "test").create("Up for testing")
159
+
160
+ get "/test/status"
161
+
162
+ last_response.status.should == 200
163
+ last_response.body.should match(/Up for testing/)
164
+ end
165
+
166
+ it "is 'service available' when an up file exists" do
167
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
168
+ IPVSLitmus.services['test'] = test_service
169
+
170
+ IPVSLitmus::StatusFile.new("up", "test").create("Up for testing")
171
+
172
+ get "/test/status"
173
+
174
+ last_response.status.should == 200
175
+ last_response.body.should match(/Up for testing/)
176
+ end
177
+
178
+ it "is 'service unavailable' when a global down file and up file exists" do
179
+ test_service = IPVSLitmus::Service.new('test', [AlwaysAvailableDependency.new], [ConstantMetric.new(100)])
180
+ IPVSLitmus.services['test'] = test_service
181
+
182
+ IPVSLitmus::StatusFile.new("global_down").create("Down for testing")
183
+ IPVSLitmus::StatusFile.new("global_up").create("Up for testing")
184
+
185
+ get "/test/status"
186
+
187
+ last_response.status.should == 503
188
+ last_response.body.should match(/Down for testing/)
189
+ end
190
+
191
+ it "is 'service unavailable' when a global down file exists" do
192
+ test_service = IPVSLitmus::Service.new('test', [AlwaysAvailableDependency.new], [ConstantMetric.new(100)])
193
+ IPVSLitmus.services['test'] = test_service
194
+
195
+ IPVSLitmus::StatusFile.new("global_down").create("Down for testing")
196
+
197
+ get "/test/status"
198
+
199
+ last_response.status.should == 503
200
+ last_response.body.should match(/Down for testing/)
201
+ end
202
+
203
+ it "is successful when a global up file exists" do
204
+ test_service = IPVSLitmus::Service.new('test', [NeverAvailableDependency.new], [ConstantMetric.new(100)])
205
+ IPVSLitmus.services['test'] = test_service
206
+
207
+ IPVSLitmus::StatusFile.new("global_up").create("Up for testing")
208
+
209
+ get "/test/status"
210
+
211
+ last_response.status.should == 200
212
+ last_response.body.should match(/Up for testing/)
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe 'litmusctl' do
5
+ def _litmusctl(args)
6
+ `bundle exec ruby -I lib bin/litmusctl #{args} -p 9293`
7
+ end
8
+
9
+ before(:all) do
10
+ system "bundle exec ruby -I lib bin/litmus -p 9293 -d -D /tmp/ipvs -c #{TEST_CONFIG} -P /tmp/ipvs.pid"
11
+ end
12
+
13
+ after(:all) do
14
+ system "kill -9 `cat /tmp/ipvs.pid`"
15
+ end
16
+
17
+ describe 'status' do
18
+ it 'returns the status of a service' do
19
+ _litmusctl('status test').should match("Health: 0")
20
+ _litmusctl('status passing_test').should match(/Health: \d\d/)
21
+ end
22
+
23
+ it "returns 'NOT FOUND' for a service that doesn't exist" do
24
+ _litmusctl('status unknown').should match('NOT FOUND')
25
+ end
26
+ end
27
+
28
+ describe "force" do
29
+ it "can create a global downfile" do
30
+ _litmusctl('force down -r "for testing"').should match("File created")
31
+
32
+ status = _litmusctl('status test')
33
+ status.should match(/Health: 0/)
34
+ status.should match(/for testing/)
35
+ end
36
+
37
+ it "creates a downfile" do
38
+ _litmusctl('force down test -r "for testing"').should match("File created")
39
+
40
+ status = _litmusctl('status test')
41
+ status.should match(/Health: 0/)
42
+ status.should match(/for testing/)
43
+ end
44
+
45
+ it 'removes an upfile for the service' do
46
+ _litmusctl('force up test -r "for testing"').should match("File created")
47
+ _litmusctl('force up test -d').should match("File deleted")
48
+
49
+ status = _litmusctl('status passing_test')
50
+ status.should match(/Health: \d\d/)
51
+ status.should_not match(/for testing/)
52
+ end
53
+
54
+ it "returns not found if downfile doesn't exist" do
55
+ _litmusctl('force down test -d').should match("NOT FOUND")
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'ipvs_litmus/cli/server'
3
+
4
+ describe IPVSLitmus::CLI::Server do
5
+ describe 'parse!' do
6
+ it 'parses litmus config file options' do
7
+ options = IPVSLitmus::CLI::Server::Options.new.parse!(['-c', 'foo.conf'])
8
+ options[:litmus_config].should == 'foo.conf'
9
+ end
10
+
11
+ it 'parses the config dir options' do
12
+ options = IPVSLitmus::CLI::Server::Options.new.parse!(['-D', '/tmp/foo'])
13
+ options[:config_dir].should == '/tmp/foo'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::Configuration do
4
+ describe "evaluate" do
5
+ it "configures a service" do
6
+ config = IPVSLitmus::Configuration.new(TEST_CONFIG)
7
+ services = config.evaluate
8
+ services.has_key?('test').should == true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::Dependency::HTTP do
4
+ describe "#available?" do
5
+ it "is true when response is 200" do
6
+ check = IPVSLitmus::Dependency::HTTP.new('http://httpstat.us/200')
7
+ check.should be_available
8
+ end
9
+
10
+ it "is true when response is 200 and expected content matches" do
11
+ check = IPVSLitmus::Dependency::HTTP.new('http://httpstat.us/200', :content => "200 OK")
12
+ check.should be_available
13
+ end
14
+
15
+ it "is false when response is 200, but does not match content" do
16
+ check = IPVSLitmus::Dependency::HTTP.new('http://httpstat.us/200', :content => "BAD STUFF")
17
+ check.should be_available
18
+ end
19
+
20
+ it "is true when response is any 200 level response" do
21
+ check = IPVSLitmus::Dependency::HTTP.new('http://httpstat.us/201')
22
+ check.should be_available
23
+ check = IPVSLitmus::Dependency::HTTP.new('http://httpstat.us/202')
24
+ check.should be_available
25
+ end
26
+
27
+ it "is false when response is 500 " do
28
+ check = IPVSLitmus::Dependency::HTTP.new('http://httpstat.us/500')
29
+ check.should_not be_available
30
+ end
31
+
32
+ it "is false when the response is 404" do
33
+ check = IPVSLitmus::Dependency::HTTP.new('http://httpstat.us/404')
34
+ check.should_not be_available
35
+ end
36
+
37
+ it "is false when the dependency is not available" do
38
+ check = IPVSLitmus::Dependency::HTTP.new('http://127.0.0.1:7777')
39
+ check.should_not be_available
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::Health do
4
+ describe "ok?" do
5
+ it "is true when health is greater than 0" do
6
+ health = IPVSLitmus::Health.new
7
+ health.perform(ConstantMetric.new(50))
8
+ health.should be_ok
9
+ end
10
+
11
+ it "is false when health is 0" do
12
+ health = IPVSLitmus::Health.new
13
+ health.perform(ConstantMetric.new(0))
14
+ health.should_not be_ok
15
+ end
16
+ end
17
+
18
+ describe "perform" do
19
+ it "executes the check and adds its value to its health" do
20
+ health = IPVSLitmus::Health.new
21
+ health.perform(ConstantMetric.new(50))
22
+ health.perform(ConstantMetric.new(25))
23
+ health.value.should == 75
24
+ end
25
+ end
26
+
27
+ describe "ensure" do
28
+ it "checks the dependency and modifies the value accordingly" do
29
+ health = IPVSLitmus::Health.new
30
+ health.ensure(NeverAvailableDependency.new)
31
+ health.perform(ConstantMetric.new(50))
32
+ health.value.should == 0
33
+ end
34
+ end
35
+
36
+ describe "summary" do
37
+ it "includes the availablilty of dependencies" do
38
+ health = IPVSLitmus::Health.new
39
+ health.ensure(NeverAvailableDependency.new)
40
+ health.ensure(AlwaysAvailableDependency.new)
41
+
42
+ health.summary.should match(/NeverAvailableDependency: FAIL/)
43
+ health.summary.should match(/AlwaysAvailableDependency: OK/)
44
+ end
45
+
46
+ it "includes the health of individual metrics" do
47
+ health = IPVSLitmus::Health.new
48
+ health.perform(ConstantMetric.new(12))
49
+ health.perform(ConstantMetric.new(34))
50
+
51
+ health.summary.should match(/ConstantMetric: 12/)
52
+ health.summary.should match(/ConstantMetric: 34/)
53
+ end
54
+
55
+ it "only runs each metric once" do
56
+ health = IPVSLitmus::Health.new
57
+ metric = ConstantMetric.new(12)
58
+ metric.should_receive(:current_health).once.and_return(12)
59
+
60
+ health.perform(metric)
61
+ end
62
+
63
+ it "only runs each dependency once" do
64
+ health = IPVSLitmus::Health.new
65
+ dependency = AlwaysAvailableDependency.new
66
+ dependency.should_receive(:available?).once.and_return(true)
67
+
68
+ health.ensure(dependency)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::Metric::AvailableMemory do
4
+ describe "#current_health" do
5
+ it "multiplies weight by memory available" do
6
+ facter = StubFacter.new({"memorytotal" => "10 GB", "memoryfree" => "5 GB"})
7
+ memory = IPVSLitmus::Metric::AvailableMemory.new(50, facter)
8
+ memory.current_health.should == 25
9
+ end
10
+
11
+ describe "#memory_total" do
12
+ it "is a positive integer" do
13
+ metric = IPVSLitmus::Metric::AvailableMemory.new(50)
14
+ metric.memory_total.should > 1_000
15
+ end
16
+
17
+ it "is cached" do
18
+ Facter.should_receive(:value).once.and_return("10 MB")
19
+ metric = IPVSLitmus::Metric::AvailableMemory.new(50)
20
+ metric.memory_total
21
+ metric.memory_total
22
+ metric.memory_total
23
+ end
24
+ end
25
+
26
+ describe "#memory_free" do
27
+ it "is a positive integer" do
28
+ metric = IPVSLitmus::Metric::AvailableMemory.new(50)
29
+ metric.memory_free.should > 100
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::Metric::CPULoad do
4
+ describe "#current_health" do
5
+ it "is the percent of available cpu capacity" do
6
+ facter = StubFacter.new({"processorcount" => "4", "loadaverage" => "1.00 0.40 0.10"})
7
+ cpu_load = IPVSLitmus::Metric::CPULoad.new(40, facter)
8
+ cpu_load.current_health.should == 30
9
+ end
10
+
11
+ it "is zero when the load is above one per core" do
12
+ facter = StubFacter.new({"processorcount" => "4", "loadaverage" => "20.00 11.40 10.00"})
13
+ cpu_load = IPVSLitmus::Metric::CPULoad.new(50, facter)
14
+ cpu_load.current_health.should == 0
15
+ end
16
+ end
17
+
18
+ describe "#processor_count" do
19
+ it "is a positive integer" do
20
+ cpu_load = IPVSLitmus::Metric::CPULoad.new(50)
21
+ cpu_load.processor_count.should > 0
22
+ end
23
+
24
+ it "is cached" do
25
+ Facter.should_receive(:value).once.and_return("10")
26
+ cpu_load = IPVSLitmus::Metric::CPULoad.new(50)
27
+ cpu_load.processor_count
28
+ cpu_load.processor_count
29
+ cpu_load.processor_count
30
+ end
31
+ end
32
+
33
+ describe "#load_average" do
34
+ it "is a floating point" do
35
+ cpu_load = IPVSLitmus::Metric::CPULoad.new(50)
36
+ cpu_load.load_average.should > 0.0
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::Service do
4
+ describe "health" do
5
+ it "is the sum of all the metrics' weight" do
6
+ service = IPVSLitmus::Service.new('test')
7
+ service.measure_health ConstantMetric, :weight => 50
8
+ service.measure_health ConstantMetric, :weight => 25
9
+
10
+ service.current_health.value.should == 75
11
+ end
12
+
13
+ it "is 0 when a dependency fails" do
14
+ service = IPVSLitmus::Service.new('test')
15
+ service.depends NeverAvailableDependency
16
+ service.measure_health ConstantMetric, :weight => 50
17
+
18
+ service.current_health.value.should == 0
19
+ end
20
+
21
+ it "is 0 when a down file exists" do
22
+ service = IPVSLitmus::Service.new('test')
23
+ service.depends AlwaysAvailableDependency
24
+ service.measure_health ConstantMetric, :weight => 50
25
+
26
+ IPVSLitmus::StatusFile.new("down", "test").create("Down for testing")
27
+
28
+ service.current_health.value.should == 0
29
+ service.current_health.summary.should == "Down for testing"
30
+ end
31
+
32
+ it "is 0 when a global down file exists" do
33
+ service = IPVSLitmus::Service.new('test')
34
+ service.depends AlwaysAvailableDependency
35
+ service.measure_health ConstantMetric, :weight => 50
36
+
37
+ IPVSLitmus::StatusFile.new("down", "test").create("Down for testing")
38
+
39
+ service.current_health.value.should == 0
40
+ service.current_health.summary.should == "Down for testing"
41
+ end
42
+
43
+ it "is 100 when an up file exists" do
44
+ service = IPVSLitmus::Service.new('test')
45
+ service.depends NeverAvailableDependency
46
+ service.measure_health ConstantMetric, :weight => 50
47
+
48
+ IPVSLitmus::StatusFile.new("up", "test").create("Up for testing")
49
+
50
+ service.current_health.value.should == 100
51
+ service.current_health.summary.should == "Up for testing"
52
+ end
53
+
54
+ it "is 100 when a global up file exists" do
55
+ service = IPVSLitmus::Service.new('test')
56
+ service.depends NeverAvailableDependency
57
+ service.measure_health ConstantMetric, :weight => 50
58
+
59
+ IPVSLitmus::StatusFile.new("global_up").create("Up for testing")
60
+
61
+ service.current_health.value.should == 100
62
+ service.current_health.summary.should == "Up for testing"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus::StatusFile do
4
+ describe "create" do
5
+ it "creates a nested file" do
6
+ status_file = IPVSLitmus::StatusFile.new("foo", "bar")
7
+ status_file.create("for testing")
8
+
9
+ status_file.exists?.should == true
10
+ end
11
+
12
+ it "creates a file" do
13
+ status_file = IPVSLitmus::StatusFile.new("foo")
14
+ status_file.create("for testing")
15
+
16
+ status_file.exists?.should == true
17
+ end
18
+
19
+ it "writes the content" do
20
+ status_file = IPVSLitmus::StatusFile.new("foo")
21
+ status_file.create("for testing")
22
+
23
+ status_file.content.should == "for testing"
24
+ end
25
+ end
26
+
27
+ describe "delete" do
28
+ it "removes the file" do
29
+ status_file = IPVSLitmus::StatusFile.new("foo")
30
+ status_file.create("for testing")
31
+
32
+ status_file.exists?.should be_true
33
+
34
+ status_file.delete
35
+
36
+ status_file.exists?.should be_false
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe IPVSLitmus do
4
+ describe 'configure' do
5
+ it 'populates services from the config file' do
6
+ IPVSLitmus.configure(TEST_CONFIG)
7
+ IPVSLitmus.services.has_key?('test').should == true
8
+ end
9
+ end
10
+
11
+ describe "reload" do
12
+ it "will reconfigure the services" do
13
+ IPVSLitmus.configure(TEST_CONFIG)
14
+ IPVSLitmus.services["bar"] = :service
15
+
16
+ Process.kill("HUP", Process.pid)
17
+
18
+ IPVSLitmus.services.has_key?('bar').should == false
19
+ IPVSLitmus.services.has_key?('test').should == true
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'rspec'
4
+ require 'rack/test'
5
+ require 'ipvs_litmus'
6
+
7
+ Dir.glob("#{File.expand_path('support', File.dirname(__FILE__))}/**/*.rb").each { |f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec
11
+ config.include Rack::Test::Methods
12
+
13
+ config.before :each do
14
+ FileUtils.rm_rf(IPVSLitmus.config_dir)
15
+ IPVSLitmus.reset
16
+ end
17
+ end
18
+
19
+ IPVSLitmus.config_dir = "/tmp/ipvs"
20
+
21
+ TEST_CONFIG = File.expand_path('support/test.config', File.dirname(__FILE__))
@@ -0,0 +1,5 @@
1
+ class AlwaysAvailableDependency
2
+ def available?
3
+ true
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class ConstantMetric
2
+ def initialize(constant)
3
+ @constant = constant
4
+ end
5
+
6
+ def current_health
7
+ @constant
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class NeverAvailableDependency
2
+ def available?
3
+ false
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class StubFacter
2
+ def initialize(values)
3
+ @values = values
4
+ end
5
+
6
+ def value(key)
7
+ @values[key]
8
+ end
9
+ end