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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dff4d0749aa831436d6b59d107a3f108a430aba
4
- data.tar.gz: 398d376529f78a657e2116260331f437da771bd9
3
+ metadata.gz: b1cfca405c017be8de4c70c975305d22da6f95c1
4
+ data.tar.gz: 2420b462ea0f1d4f27617587908ff5ba0aaa8b1b
5
5
  SHA512:
6
- metadata.gz: f9aae81c5ea46d2c848db3401f6ff7172347e4c29476b92d191c51188a9ea9942f3090819c735bc15986b9604809a1640d76af0133882c0e0649c729a0c7228b
7
- data.tar.gz: 884a131392c201e7e71aac2590add1a1678ba3a265e976d49900c6d3e5ee6e37ac5b8ca4ecb712628ddf5ddfafb82ab2ae032f2a025a28a68b1c7f5a0001059f
6
+ metadata.gz: 6414267654b15a85bcceeec9fd1b50a633e2033a92f2229f10edf3690f92876f32bdfa80a5fce6d36fa0c7bbdfd34dadd4b1ee26f90629face413c071e5ed195
7
+ data.tar.gz: 2bf21622a01a004b0a06bb8104de751e499dfb24b693ddefb9c4dc700702605b68285bfc1a4453519ab1ddf833cb9eecb135466eb3592eeae43707f2fa2c4be6
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.4
2
+ * Fix bugs
3
+ * Add specs
4
+
1
5
  ## 0.1.3
2
6
  * Adds second client with fqdn in client name
3
7
 
data/Gemfile CHANGED
@@ -3,3 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'sinatra'
4
4
  gem 'rest-client'
5
5
  gem 'thin'
6
+
7
+ group :test, :development do
8
+ gem "rspec"
9
+ end
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
- 1) spin up a vagrant vm with sensu on it
20
- 2) 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
- 3) run the generate_responses script against the sensu vm you created
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
@@ -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 = event.to_json
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[client_name]
95
+ event_json = JSON.parse(settings.events)
95
96
  unless event_json.nil?
96
- event_json[:client_name] = check
97
- event_json[:check_name] = check_name
98
- @body = event_json
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| e.has_value? check_name}
108
- # settings.events = events.to_s
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 ''
@@ -2,7 +2,7 @@ module FakeSensu
2
2
  module FakeSensuMacros
3
3
 
4
4
  def reset_fake_sensu!
5
- RestClient.get("http://localhost:4567/reset")
5
+ RestClient.get("http://localhost:9292/reset")
6
6
  end
7
7
 
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module FakeSensu
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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
@@ -0,0 +1,12 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+ require 'rack/test'
4
+ require 'fake_sensu'
5
+ require 'fake_sensu/api'
6
+
7
+ ENV['RACK_ENV'] = 'test'
8
+
9
+ RSpec.configure do |config|
10
+ config.order = "random"
11
+ config.include Rack::Test::Methods
12
+ end
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.3
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-08-31 00:00:00.000000000 Z
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