fake_sensu 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/README.md +3 -3
- data/Rakefile +17 -0
- data/lib/fake_sensu/api.rb +14 -8
- data/lib/fake_sensu/macros.rb +1 -1
- data/lib/fake_sensu/version.rb +1 -1
- data/spec/api_spec.rb +180 -0
- data/spec/spec_helper.rb +12 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1cfca405c017be8de4c70c975305d22da6f95c1
|
4
|
+
data.tar.gz: 2420b462ea0f1d4f27617587908ff5ba0aaa8b1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6414267654b15a85bcceeec9fd1b50a633e2033a92f2229f10edf3690f92876f32bdfa80a5fce6d36fa0c7bbdfd34dadd4b1ee26f90629face413c071e5ed195
|
7
|
+
data.tar.gz: 2bf21622a01a004b0a06bb8104de751e499dfb24b693ddefb9c4dc700702605b68285bfc1a4453519ab1ddf833cb9eecb135466eb3592eeae43707f2fa2c4be6
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -16,9 +16,9 @@ end
|
|
16
16
|
|
17
17
|
## Adding a new verision
|
18
18
|
If you want to add support for an additional sensu api version:
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
- spin up a vagrant vm with sensu on it
|
20
|
+
- run the test suite, killing it before the end (be sure to fully log out or the test suite will continue to run in the background and kill your data)
|
21
|
+
- run the generate_responses script against the sensu vm you created
|
22
22
|
|
23
23
|
```bash
|
24
24
|
./generate_responses http://foo:bar@192.168.5.5/4567
|
data/Rakefile
CHANGED
@@ -1 +1,18 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
desc 'Default: run specs.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
10
|
+
# Put spec opts in a file named .rspec in root
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Generate code coverage"
|
14
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
15
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
16
|
+
t.rcov = true
|
17
|
+
t.rcov_opts = ['--exclude', 'spec']
|
18
|
+
end
|
data/lib/fake_sensu/api.rb
CHANGED
@@ -5,7 +5,7 @@ module FakeSensu
|
|
5
5
|
class Api < Sinatra::Base
|
6
6
|
|
7
7
|
configure do
|
8
|
-
version = ENV['FAKE_SENSU_VERSION']
|
8
|
+
version = ENV['FAKE_SENSU_VERSION'] || "0.10.2"
|
9
9
|
response_path = File.dirname(__FILE__) + "/responses/#{version}.json"
|
10
10
|
responses = JSON.parse(File.read(response_path))["index"]
|
11
11
|
set :info, responses["info"]
|
@@ -81,9 +81,10 @@ module FakeSensu
|
|
81
81
|
get %r{/events/([\w\.-]+)$} do |client_name|
|
82
82
|
content_type :json
|
83
83
|
events = JSON.parse(settings.events)
|
84
|
+
@body = []
|
84
85
|
events.each do |event|
|
85
86
|
if event.has_value? client_name
|
86
|
-
@body
|
87
|
+
@body << event.to_json
|
87
88
|
end
|
88
89
|
end
|
89
90
|
@body ? "#{@body}" : ""
|
@@ -91,12 +92,15 @@ module FakeSensu
|
|
91
92
|
|
92
93
|
get %r{/events?/([\w\.-]+)/([\w\.-]+)$} do |client_name, check_name|
|
93
94
|
content_type :json
|
94
|
-
event_json = settings.events
|
95
|
+
event_json = JSON.parse(settings.events)
|
95
96
|
unless event_json.nil?
|
96
|
-
event_json
|
97
|
-
|
98
|
-
|
97
|
+
event_json.each do |event|
|
98
|
+
if event.has_value?(check_name) && event.has_value?(client_name)
|
99
|
+
@body = event.to_json
|
100
|
+
end
|
101
|
+
end
|
99
102
|
end
|
103
|
+
@body ? "#{@body}" : ""
|
100
104
|
end
|
101
105
|
|
102
106
|
delete %r{/events?/([\w\.-]+)/([\w\.-]+)$} do |client_name, check_name|
|
@@ -104,8 +108,10 @@ module FakeSensu
|
|
104
108
|
events = JSON.parse(settings.events)
|
105
109
|
events.each do |event|
|
106
110
|
if event["client"] == client_name && event["check"] == check_name
|
107
|
-
events.delete_if {|e|
|
108
|
-
|
111
|
+
events.delete_if {|e|
|
112
|
+
(e.has_value?(check_name) && e.has_value?(client_name))
|
113
|
+
}
|
114
|
+
settings.events = events.to_json
|
109
115
|
end
|
110
116
|
end
|
111
117
|
body ''
|
data/lib/fake_sensu/macros.rb
CHANGED
data/lib/fake_sensu/version.rb
CHANGED
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "FakeSensu::Api" do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
FakeSensu::Api
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe "GET /info" do
|
12
|
+
it "returns an info hash" do
|
13
|
+
get "/info"
|
14
|
+
last_response.should be_ok
|
15
|
+
body = last_response.body
|
16
|
+
body.should be_a String
|
17
|
+
JSON.parse(body).should be_a Hash
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
it "sets the version passed in" do
|
22
|
+
get "/info"
|
23
|
+
body = JSON.parse(last_response.body)
|
24
|
+
version = body["sensu"]["version"]
|
25
|
+
version.should eq "0.10.2"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "GET /clients" do
|
30
|
+
before :each do
|
31
|
+
get "/clients"
|
32
|
+
last_response.should be_ok
|
33
|
+
@body = JSON.parse(last_response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a clients array" do
|
37
|
+
@body.should be_a Array
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return 2 clients" do
|
41
|
+
@body.count.should eq 2
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should include a client with an fqdn-type name" do
|
45
|
+
fqdns = []
|
46
|
+
@body.each do |hash|
|
47
|
+
if hash["name"].include? "www.fqdn.com"
|
48
|
+
fqdns << hash
|
49
|
+
end
|
50
|
+
end
|
51
|
+
fqdns.count.should eq 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "GET /clients/:name" do
|
56
|
+
it "should return a client with an fqdn name" do
|
57
|
+
get "/clients/www.fqdn.com"
|
58
|
+
last_response.should be_ok
|
59
|
+
body = JSON.parse(last_response.body)
|
60
|
+
body.should be_a Hash
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "GET /checks" do
|
65
|
+
it "should return 2 checks" do
|
66
|
+
get "/checks"
|
67
|
+
last_response.should be_ok
|
68
|
+
body = JSON.parse(last_response.body)
|
69
|
+
body.should be_a Array
|
70
|
+
body.count.should eq 2
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "GET /check/request" do
|
75
|
+
it "should be successful" do
|
76
|
+
header = {'Content-Type' => 'application/json'}
|
77
|
+
body = {:check => "tokens"}.to_json
|
78
|
+
post "/check/request", body, header
|
79
|
+
last_response.should be_ok
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "GET /events" do
|
84
|
+
before :each do
|
85
|
+
get "/events"
|
86
|
+
@body = JSON.parse(last_response.body)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should be successful" do
|
90
|
+
last_response.should be_ok
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return 4 events" do
|
94
|
+
@body.count.should eq 4
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "GET /events/:client_name" do
|
99
|
+
it "should return events for a client" do
|
100
|
+
get "/events/www.fqdn.com"
|
101
|
+
body = JSON.parse(last_response.body)
|
102
|
+
last_response.should be_ok
|
103
|
+
body.count.should eq 2
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "GET /events/:client_name/:check_name" do
|
108
|
+
it "should return events for a client and check name" do
|
109
|
+
get "/events/www.fqdn.com/test"
|
110
|
+
body = JSON.parse(last_response.body)
|
111
|
+
last_response.should be_ok
|
112
|
+
body.should be_a Hash
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "DELETE /events/:client_name/:check_name" do
|
117
|
+
it "should resolve an event by client and check name" do
|
118
|
+
get "/events"
|
119
|
+
pre_events = JSON.parse(last_response.body)
|
120
|
+
pre_events.count.should eq 4
|
121
|
+
delete "/events/www.fqdn.com/test"
|
122
|
+
last_response.should be_ok
|
123
|
+
get "/events"
|
124
|
+
post_events = JSON.parse(last_response.body)
|
125
|
+
post_events.count.should eq 3
|
126
|
+
get "/reset"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "GET /stashes" do
|
131
|
+
it "should return a list of stashes" do
|
132
|
+
get "/stashes"
|
133
|
+
body = JSON.parse(last_response.body)
|
134
|
+
last_response.should be_ok
|
135
|
+
body.count.should eq 2
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "GET /stashes/:path" do
|
140
|
+
it "should return a single stash" do
|
141
|
+
get "/stashes/test/test"
|
142
|
+
body = eval(last_response.body)
|
143
|
+
body.should be_a Hash
|
144
|
+
body["key"].should eq "value"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "POST /stashes" do
|
149
|
+
it "should create a stash" do
|
150
|
+
get "/stashes"
|
151
|
+
stashes = JSON.parse(last_response.body)
|
152
|
+
stashes.count.should eq 2
|
153
|
+
header = {'Content-Type' => 'application/json'}
|
154
|
+
body = {:path => "test_stash",
|
155
|
+
:content =>
|
156
|
+
{:reason => "testing stashes"}}.to_json
|
157
|
+
post "/stashes", body, header
|
158
|
+
last_response.should be_ok
|
159
|
+
get "/stashes"
|
160
|
+
stashes = JSON.parse(last_response.body)
|
161
|
+
stashes.count.should eq 3
|
162
|
+
get "/reset"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "DELETE /stashes/:path" do
|
167
|
+
it "should resolve a stash" do
|
168
|
+
get "/stashes"
|
169
|
+
stashes = JSON.parse(last_response.body)
|
170
|
+
stashes.count.should eq 2
|
171
|
+
delete "/stashes/test/test"
|
172
|
+
last_response.should be_ok
|
173
|
+
get "/stashes"
|
174
|
+
stashes = JSON.parse(last_response.body)
|
175
|
+
stashes.count.should eq 1
|
176
|
+
get "/reset"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_sensu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Sebastian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- .gitignore
|
92
|
+
- .rspec
|
92
93
|
- CHANGELOG.md
|
93
94
|
- Gemfile
|
94
95
|
- LICENSE.txt
|
@@ -106,6 +107,8 @@ files:
|
|
106
107
|
- lib/fake_sensu/responses/0.9.12.json
|
107
108
|
- lib/fake_sensu/server.rb
|
108
109
|
- lib/fake_sensu/version.rb
|
110
|
+
- spec/api_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
109
112
|
homepage: http://www.github.com/asebastian/fake_sensu
|
110
113
|
licenses:
|
111
114
|
- MIT
|
@@ -131,4 +134,6 @@ rubygems_version: 2.0.3
|
|
131
134
|
signing_key:
|
132
135
|
specification_version: 4
|
133
136
|
summary: Mocking library/server for sensu
|
134
|
-
test_files:
|
137
|
+
test_files:
|
138
|
+
- spec/api_spec.rb
|
139
|
+
- spec/spec_helper.rb
|