service-status 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,130 @@
1
+ require 'service_status/status'
2
+ require 'socket'
3
+ require 'timecop'
4
+ require 'json'
5
+
6
+ describe ServiceStatus::Status do
7
+ before :each do
8
+ @version = '0.0.1'
9
+ @hostname = Socket.gethostname
10
+ @app_name = 'killer-app'
11
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
12
+ end
13
+
14
+ it 'name' do
15
+ expect(@instance.name).to eql @app_name
16
+ end
17
+
18
+ it 'version' do
19
+ expect(@instance.version).to eql @version
20
+ end
21
+
22
+ it 'hostname' do
23
+ expect(@instance.hostname).to eql @hostname
24
+ end
25
+
26
+ it 'errors' do
27
+ expect(@instance.errors).to eql []
28
+ end
29
+
30
+ it 'checks' do
31
+ expect(@instance.checks).to eql []
32
+ end
33
+
34
+ it 'timestamp' do
35
+ Timecop.freeze
36
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
37
+ timestamp = Time.now.strftime '%Y-%m-%d %T'
38
+ expect(@instance.timestamp).to eql timestamp
39
+ Timecop.return
40
+ end
41
+
42
+ describe 'uptime' do
43
+ it 'seconds' do
44
+ Timecop.freeze
45
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
46
+ Timecop.travel(Time.now + 55)
47
+ expect(@instance.uptime).to eql '0d:00:00:55'
48
+ Timecop.return
49
+ end
50
+
51
+ it 'minutes' do
52
+ Timecop.freeze
53
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
54
+ Timecop.travel(Time.now + 301)
55
+ expect(@instance.uptime).to eql '0d:00:05:01'
56
+ Timecop.return
57
+ end
58
+
59
+ it 'hours' do
60
+ Timecop.freeze
61
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
62
+ Timecop.travel(Time.now + 5000)
63
+ expect(@instance.uptime).to eql '0d:01:23:20'
64
+ Timecop.return
65
+ end
66
+
67
+ it 'days' do
68
+ Timecop.freeze
69
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
70
+ Timecop.travel(Time.now + 100_000)
71
+ expect(@instance.uptime).to eql '1d:27:46:40'
72
+ Timecop.return
73
+ end
74
+ end
75
+
76
+ it 'diskusage' do
77
+ stats = double('stats')
78
+ expect(stats).to receive(:blocks) { '239189165' }
79
+ expect(stats).to receive(:blocks_available) { '106180000' }
80
+ expect(Sys::Filesystem).to receive(:stat).with('/') { stats }
81
+ expect(@instance.disk_usage).to eql '55%'
82
+ end
83
+
84
+ it 'status' do
85
+ expect(@instance.status).to eql 'online'
86
+ end
87
+
88
+ it 'to_json' do
89
+ Timecop.freeze(Time.local(2015, 04, 29, 14, 52, 47))
90
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
91
+ stats = double('stats')
92
+ expect(stats).to receive(:blocks) { '239189165' }
93
+ expect(stats).to receive(:blocks_available) { '106180000' }
94
+ expect(Sys::Filesystem).to receive(:stat).with('/') { stats }
95
+ disk_usage = '55%'
96
+ expect(@instance.to_json).to eql "{\"name\":\"#{@app_name}\",\"version\":\"#{@version}\",\"hostname\":\"#{@hostname}\",\"errors\":[],\"checks\":[],\"timestamp\":\"2015-04-29 14:52:47\",\"uptime\":\"0d:00:00:00\",\"diskusage\":\"#{disk_usage}\",\"status\":\"online\"}"
97
+ Timecop.return
98
+ end
99
+
100
+ describe 'add_check' do
101
+ it 'had a check that was ok' do
102
+ @instance.add_check('ElasticSearch', true)
103
+ expect(@instance.checks).to eql ['ElasticSearch']
104
+ expect(@instance.errors).to eql []
105
+ expect(@instance.status).to eql 'online'
106
+ end
107
+
108
+ it 'had a check that failed' do
109
+ @instance.add_check('ElasticSearch', false)
110
+ expect(@instance.checks).to eql ['ElasticSearch']
111
+ expect(@instance.errors).to eql ['ElasticSearch']
112
+ expect(@instance.status).to eql 'offline'
113
+ end
114
+ end
115
+
116
+ describe 'add_http_get_check', :vcr do
117
+ it 'ok' do
118
+ @instance.add_http_get_check('Responsys API', 'https://ws2.responsys.net/webservices/wsdl/ResponsysWS_Level1.wsdl')
119
+ expect(@instance.checks).to eql ['Responsys API']
120
+ expect(@instance.errors).to eql []
121
+ end
122
+
123
+ it 'fail' do
124
+ @instance.add_http_get_check('Responsys API', 'https://foobar.responsys.net/webservices/wsdl/ResponsysWS_Level1.wsdl')
125
+ expect(@instance.checks).to eql ['Responsys API']
126
+ expect(@instance.errors).to eql ['Responsys API']
127
+ expect(@instance.status).to eql 'offline'
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,118 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ #
20
+
21
+ require 'simplecov'
22
+ SimpleCov.start
23
+
24
+ SimpleCov.configure do
25
+ minimum_coverage '100%'
26
+ end
27
+
28
+ require "codeclimate-test-reporter"
29
+ CodeClimate::TestReporter.start
30
+
31
+ require 'vcr'
32
+
33
+ VCR.configure do |c|
34
+ c.ignore_hosts 'codeclimate.com'
35
+ c.cassette_library_dir = 'spec/cassettes'
36
+ c.hook_into :webmock
37
+ c.default_cassette_options = { match_requests_on: [:method, :uri, :body] }
38
+ c.before_record do |cx|
39
+ cx.request.headers = nil
40
+ cx.response.headers = nil
41
+ end
42
+
43
+ c.configure_rspec_metadata!
44
+ end
45
+
46
+ WebMock.disable_net_connect!(:allow => "codeclimate.com")
47
+
48
+ RSpec.configure do |config|
49
+ # rspec-expectations config goes here. You can use an alternate
50
+ # assertion/expectation library such as wrong or the stdlib/minitest
51
+ # assertions if you prefer.
52
+ config.expect_with :rspec do |expectations|
53
+ # This option will default to `true` in RSpec 4. It makes the `description`
54
+ # and `failure_message` of custom matchers include text for helper methods
55
+ # defined using `chain`, e.g.:
56
+ # be_bigger_than(2).and_smaller_than(4).description
57
+ # # => "be bigger than 2 and smaller than 4"
58
+ # ...rather than:
59
+ # # => "be bigger than 2"
60
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
61
+ end
62
+
63
+ # rspec-mocks config goes here. You can use an alternate test double
64
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
65
+ config.mock_with :rspec do |mocks|
66
+ # Prevents you from mocking or stubbing a method that does not exist on
67
+ # a real object. This is generally recommended, and will default to
68
+ # `true` in RSpec 4.
69
+ mocks.verify_partial_doubles = true
70
+ end
71
+
72
+ # The settings below are suggested to provide a good initial experience
73
+ # with RSpec, but feel free to customize to your heart's content.
74
+ # # These two settings work together to allow you to limit a spec run
75
+ # # to individual examples or groups you care about by tagging them with
76
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
77
+ # # get run.
78
+ # config.filter_run :focus
79
+ # config.run_all_when_everything_filtered = true
80
+ #
81
+ # # Limits the available syntax to the non-monkey patched syntax that is
82
+ # # recommended. For more details, see:
83
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
84
+ # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
85
+ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
86
+ # config.disable_monkey_patching!
87
+ #
88
+ # # This setting enables warnings. It's recommended, but in some cases may
89
+ # # be too noisy due to issues in dependencies.
90
+ # config.warnings = true
91
+ #
92
+ # # Many RSpec users commonly either run the entire suite or an individual
93
+ # # file, and it's useful to allow more verbose output when running an
94
+ # # individual spec file.
95
+ # if config.files_to_run.one?
96
+ # # Use the documentation formatter for detailed output,
97
+ # # unless a formatter has already been configured
98
+ # # (e.g. via a command-line flag).
99
+ # config.default_formatter = 'doc'
100
+ # end
101
+ #
102
+ # # Print the 10 slowest examples and example groups at the
103
+ # # end of the spec run, to help surface which specs are running
104
+ # # particularly slow.
105
+ # config.profile_examples = 10
106
+ #
107
+ # # Run specs in random order to surface order dependencies. If you find an
108
+ # # order dependency and want to debug it, you can fix the order by providing
109
+ # # the seed, which is printed after each run.
110
+ # # --seed 1234
111
+ # config.order = :random
112
+ #
113
+ # # Seed global randomization in this process using the `--seed` CLI option.
114
+ # # Setting this allows you to use `--seed` to deterministically reproduce
115
+ # # test failures related to randomization by passing the same `--seed` value
116
+ # # as the one that triggered the failure.
117
+ # Kernel.srand config.seed
118
+ end
metadata ADDED
@@ -0,0 +1,276 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: service-status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - William Griffiths
8
+ - Luke Farrar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-05-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sys-filesystem
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '10.4'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '10.4'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.7'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '3.1'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.1'
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard-rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '4.5'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '4.5'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rb-inotify
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '0.9'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '0.9'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rb-fsevent
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '0.9'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '0.9'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rb-fchange
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '0.0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: terminal-notifier-guard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: '1.6'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: '1.6'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rubocop
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ version: '0.28'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: '0.28'
154
+ - !ruby/object:Gem::Dependency
155
+ name: simplecov
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ version: '0.9'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ~>
166
+ - !ruby/object:Gem::Version
167
+ version: '0.9'
168
+ - !ruby/object:Gem::Dependency
169
+ name: codeclimate-test-reporter
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ~>
173
+ - !ruby/object:Gem::Version
174
+ version: '0.4'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ~>
180
+ - !ruby/object:Gem::Version
181
+ version: '0.4'
182
+ - !ruby/object:Gem::Dependency
183
+ name: webmock
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ~>
187
+ - !ruby/object:Gem::Version
188
+ version: '1.21'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ~>
194
+ - !ruby/object:Gem::Version
195
+ version: '1.21'
196
+ - !ruby/object:Gem::Dependency
197
+ name: vcr
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ~>
201
+ - !ruby/object:Gem::Version
202
+ version: '2.9'
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ~>
208
+ - !ruby/object:Gem::Version
209
+ version: '2.9'
210
+ - !ruby/object:Gem::Dependency
211
+ name: timecop
212
+ requirement: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ~>
215
+ - !ruby/object:Gem::Version
216
+ version: '0.7'
217
+ type: :development
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ~>
222
+ - !ruby/object:Gem::Version
223
+ version: '0.7'
224
+ description: When monitoring REST servers it is useful to have a standard /status
225
+ page. This gem provides such content.
226
+ email:
227
+ - william.griffiths@thebookpeople.co.uk
228
+ - luke.farrar@thebookpeople.co.uk
229
+ executables: []
230
+ extensions: []
231
+ extra_rdoc_files: []
232
+ files:
233
+ - .gitignore
234
+ - .rspec
235
+ - .rubocop.yml
236
+ - .travis.yml
237
+ - Gemfile
238
+ - Gemfile.lock
239
+ - Guardfile
240
+ - LICENSE
241
+ - README.md
242
+ - Rakefile
243
+ - lib/service_status/status.rb
244
+ - lib/service_status/version.rb
245
+ - service-status.gemspec
246
+ - spec/cassettes/ServiceStatus_Status/add_http_get_check/ok.yml
247
+ - spec/service_status_spec.rb
248
+ - spec/spec_helper.rb
249
+ homepage: https://github.com/TheBookPeople/service-status-ruby
250
+ licenses:
251
+ - GPLv3
252
+ metadata: {}
253
+ post_install_message:
254
+ rdoc_options: []
255
+ require_paths:
256
+ - lib
257
+ required_ruby_version: !ruby/object:Gem::Requirement
258
+ requirements:
259
+ - - ! '>='
260
+ - !ruby/object:Gem::Version
261
+ version: 2.0.0
262
+ required_rubygems_version: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - ! '>='
265
+ - !ruby/object:Gem::Version
266
+ version: '0'
267
+ requirements: []
268
+ rubyforge_project:
269
+ rubygems_version: 2.4.5
270
+ signing_key:
271
+ specification_version: 4
272
+ summary: Provides a simple JSON service status report.
273
+ test_files:
274
+ - spec/cassettes/ServiceStatus_Status/add_http_get_check/ok.yml
275
+ - spec/service_status_spec.rb
276
+ - spec/spec_helper.rb