Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 2712ec6

Browse files
committed
add some test
1 parent bb94f8f commit 2712ec6

File tree

5 files changed

+108
-9
lines changed

5 files changed

+108
-9
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ A simulated outage affect all systems below the broken one.
77

88
## Installation
99

10-
gem install sinatra
11-
git clone https://github.com/mariussturm/monitoring-mock.git
10+
$ gem install sinatra
11+
$ git clone https://github.com/mariussturm/monitoring-mock.git
1212

1313
## Configuration
1414
Configure your nework.
1515

16-
vi etc/mock.yaml
16+
$ vi etc/mock.yaml
1717

1818
Define a `type` for every entry.
1919

@@ -39,12 +39,12 @@ Define a `type` for every entry.
3939

4040
## Start the mock
4141

42-
cd monitoring-mock
43-
./mm.rb
42+
$ cd monitoring-mock
43+
$ ruby mm.rb
4444

4545
Or use your rack server of choice
4646

47-
thin start
47+
$ ruby mm.rb -s thin
4848

4949
## Dashboard
5050
You can get an overview of your simulated network under
@@ -57,9 +57,9 @@ Press the `Ok` or `Critical` button to toggle the state of an entry
5757
Every mock entry can be checked via HTTP. The mock delivers a JSON string
5858
as result.
5959

60-
curl http://localhost:4567/green
60+
$ curl http://localhost:4567/green
6161
{"status":0,"output":"Service OK","options":{"type":"datacenter"}}
6262

63-
curl http://localhost:4567/green/web1
63+
$ curl http://localhost:4567/green/web1
6464
{"status":2,"output":"Service is broken","options":{"type":"host"}}
6565

Rakefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'rake/testtask'
2+
3+
Rake::TestTask.new do |t|
4+
t.libs.push "./"
5+
t.test_files = FileList['test/*_test.rb']
6+
# t.verbose = true
7+
end
8+

config.ru

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ require File.join( File.dirname(__FILE__), 'mm.rb' )
1111

1212
run Sinatra::Application
1313

14-

test/mm_test.rb

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
require File.expand_path('test_helper.rb', 'test')
2+
3+
class GET_baseurl < MiniTest::Unit::TestCase
4+
include Rack::Test::Methods
5+
6+
def setup
7+
get '/'
8+
end
9+
10+
def test_succeeds
11+
assert last_response.status, 200
12+
end
13+
14+
def test_returns_valid_json
15+
assert_equal json_response['status'], 3
16+
end
17+
end
18+
19+
class GET_existing_entry < MiniTest::Unit::TestCase
20+
include Rack::Test::Methods
21+
22+
def setup
23+
get '/green'
24+
end
25+
26+
def test_succeeds
27+
assert_equal json_response['status'], 0
28+
end
29+
end
30+
31+
class GET_nonexisting_entry < MiniTest::Unit::TestCase
32+
include Rack::Test::Methods
33+
34+
def setup
35+
get '/yellow'
36+
end
37+
38+
def test_succeeds
39+
assert_equal json_response['status'], 3
40+
end
41+
end
42+
43+
class POST_toggle_entry < MiniTest::Unit::TestCase
44+
include Rack::Test::Methods
45+
46+
@before, @after = ''
47+
def setup
48+
get '/green'
49+
@before = json_response
50+
post '/toggle/green'
51+
get '/green'
52+
@after = json_response
53+
end
54+
55+
def test_succeeds
56+
assert_equal @before['status'], 0
57+
assert_equal @after['status'], 2
58+
end
59+
end
60+
61+
class GET_deep_entry_and_toggle_above < MiniTest::Unit::TestCase
62+
include Rack::Test::Methods
63+
64+
@before, @after = ''
65+
def setup
66+
get '/blue/web2'
67+
@before = json_response
68+
post '/toggle/blue'
69+
get '/blue/web2'
70+
@after = json_response
71+
end
72+
73+
def test_succeeds
74+
assert_equal @before['status'], 0
75+
assert_equal @after['status'], 2
76+
end
77+
end
78+

test/test_helper.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ENV['RACK_ENV'] = 'test'
2+
require 'minitest/autorun'
3+
require 'rack/test'
4+
5+
require 'mm'
6+
7+
def app
8+
Sinatra::Application
9+
end
10+
11+
def json_response
12+
JSON.parse last_response.body
13+
end
14+

0 commit comments

Comments
 (0)