Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
6d5e76c0
Commit
6d5e76c0
authored
Jan 29, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new pending specs
parent
c762688d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
200 additions
and
104 deletions
+200
-104
models.rb
lib/models.rb
+2
-1
noahapp_application_spec.rb
spec/noahapp_application_spec.rb
+27
-0
noahapp_configuration_spec.rb
spec/noahapp_configuration_spec.rb
+28
-0
noahapp_host_spec.rb
spec/noahapp_host_spec.rb
+108
-103
noahapp_service_spec.rb
spec/noahapp_service_spec.rb
+27
-0
spec_helper.rb
spec/spec_helper.rb
+8
-0
No files found.
lib/models.rb
View file @
6d5e76c0
...
...
@@ -23,7 +23,8 @@ class Host < Ohm::Model
def
to_hash
arr
=
[]
services
.
sort
.
each
{
|
s
|
arr
<<
s
.
to_hash
}
super
.
merge
(
:name
=>
name
,
:status
=>
status
,
:updated_at
=>
updated_at
,
:services
=>
arr
)
h
=
{
:name
=>
name
,
:status
=>
status
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
,
:services
=>
arr
}
super
.
merge
(
h
)
end
def
is_new?
...
...
spec/noahapp_application_spec.rb
0 → 100644
View file @
6d5e76c0
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Application API"
,
:reset_redis
=>
false
,
:populate_sample_data
=>
true
do
describe
"calling"
do
describe
"GET"
do
it
"all applications should work"
it
"named application should work"
it
"named configuration for application should work"
it
"named configuration should work with mime-type"
it
"invalud application should not work"
it
"invalid configuration for application should not work"
end
describe
"PUT"
do
it
"new application should work"
it
"new application with missing name should not work"
it
"existing application should work"
end
describe
"DELETE"
do
it
"existing application should work"
it
"invalid application should not work"
end
end
end
spec/noahapp_configuration_spec.rb
0 → 100644
View file @
6d5e76c0
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Configuration API"
,
:reset_redis
=>
false
,
:populate_sample_data
=>
true
do
describe
"calling"
do
describe
"GET"
do
it
"all configurations should work"
it
"named application should work"
it
"named configuration for application should work"
it
"named configuration should work with mime-type"
it
"invalid application should not work"
it
"invalid configuration for application should not work"
end
describe
"PUT"
do
it
"new configuration should work"
it
"existing configuration should work"
it
"new configuration with missing format should not work"
it
"new configuration with missing body should not work"
end
describe
"DELETE"
do
it
"existing configuration should work"
it
"invalid configuration should not work"
end
end
end
spec/noahapp_host_spec.rb
View file @
6d5e76c0
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"
NoahApp
Host API"
,
:reset_redis
=>
false
,
:populate_sample_data
=>
true
do
describe
"
Using the
Host API"
,
:reset_redis
=>
false
,
:populate_sample_data
=>
true
do
it
"GET /h"
do
get
'/h'
last_response
.
should
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
end
describe
"calling"
do
it
"GET /h/localhost"
do
get
'/h/localhost'
last_response
.
should
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
host
=
JSON
.
parse
(
last_response
.
body
)
services
=
host
[
"services"
]
host
[
"name"
].
should
==
"localhost"
host
[
"status"
].
should
==
"up"
services
.
size
.
should
==
2
services
.
first
[
"name"
].
should
==
"redis"
services
.
first
[
"status"
].
should
==
"up"
services
.
first
[
"host"
].
should
==
"localhost"
services
.
last
[
"name"
].
should
==
"noah"
services
.
last
[
"status"
].
should
==
"up"
services
.
last
[
"host"
].
should
==
"localhost"
end
it
"GET /h/localhost/noah"
do
get
'/h/localhost/noah'
last_response
.
should
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
service
=
JSON
.
parse
(
last_response
.
body
)
service
[
"name"
].
should
==
"noah"
service
[
"status"
].
should
==
"up"
service
[
"host"
].
should
==
"localhost"
end
it
"GET /h should work"
do
get
'/h'
last_response
.
should
be_ok
last_response
.
should
return_json
end
it
"PUT /h/:hostname - new host"
do
host_data
=
{
:name
=>
"host99.domain.com"
,
:status
=>
"down"
}.
to_json
put
'/h/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"result"
].
should
==
"success"
response
[
"id"
].
nil?
.
should
==
false
response
[
"name"
].
should
==
"host99.domain.com"
response
[
"status"
].
should
==
"down"
response
[
"new_record"
].
should
==
true
end
it
"GET existing host should work"
do
get
'/h/localhost'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
it
"PUT /h/:hostname - existing host"
do
sleep
3
host_data
=
{
:name
=>
"localhost"
,
:status
=>
"pending"
}.
to_json
put
'/h/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"new_record"
].
should
==
false
end
services
=
response
[
"services"
]
it
"PUT /h/:hostname - missing name parameter"
do
host_data
=
{
:status
=>
"pending"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Missing Parameters"
end
response
[
"name"
].
should
==
"localhost"
response
[
"status"
].
should
==
"up"
services
.
size
.
should
==
2
services
.
first
[
"name"
].
should
==
"redis"
services
.
first
[
"status"
].
should
==
"up"
services
.
first
[
"host"
].
should
==
"localhost"
services
.
last
[
"name"
].
should
==
"noah"
services
.
last
[
"status"
].
should
==
"up"
services
.
last
[
"host"
].
should
==
"localhost"
end
it
"PUT /h/:hostname - missing status parameter"
do
host_data
=
{
:name
=>
"host100.domain.com"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Missing Parameters"
end
it
"PUT /h/:hostname - invalid status parameter"
do
host_data
=
{
:name
=>
"host100.domain.com"
,
:status
=>
"fscked"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"[[:status, :not_member]]"
end
it
"GET existing host's service should work"
do
get
'/h/localhost/noah'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
it
"DELETE /h/:hostname - existing host"
do
h
=
Host
.
find
(
:name
=>
"localhost"
).
first
svc_size
=
h
.
services
.
size
host_data
=
{
:name
=>
"localhost"
}
delete
'/h/localhost'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"result"
].
should
==
"success"
response
[
"id"
].
should
==
h
.
id
response
[
"name"
].
should
==
"localhost"
response
[
"service_count"
].
should
==
svc_size
.
to_s
end
response
[
"name"
].
should
==
"noah"
response
[
"status"
].
should
==
"up"
response
[
"host"
].
should
==
"localhost"
end
it
"PUT new host should work"
do
host_data
=
{
:name
=>
"host99.domain.com"
,
:status
=>
"down"
}.
to_json
put
'/h/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
response
[
"id"
].
nil?
.
should
==
false
response
[
"name"
].
should
==
"host99.domain.com"
response
[
"status"
].
should
==
"down"
response
[
"new_record"
].
should
==
true
end
it
"PUT existing host should work"
do
sleep
3
host_data
=
{
:name
=>
"host99.domain.com"
,
:status
=>
"pending"
}.
to_json
put
'/h/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"new_record"
].
should
==
false
end
it
"PUT host missing name parameter should not work"
do
host_data
=
{
:status
=>
"pending"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Missing Parameters"
end
it
"PUT host missing status parameter should not work"
do
host_data
=
{
:name
=>
"host100.domain.com"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Missing Parameters"
end
it
"PUT host with invalid status parameter should not work"
do
host_data
=
{
:name
=>
"host100.domain.com"
,
:status
=>
"fscked"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"[[:status, :not_member]]"
end
it
"DELETE existing host should work"
do
h
=
Host
.
find
(
:name
=>
"localhost"
).
first
svc_size
=
h
.
services
.
size
host_data
=
{
:name
=>
"localhost"
}
delete
'/h/localhost'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
response
[
"id"
].
should
==
h
.
id
response
[
"name"
].
should
==
"localhost"
response
[
"service_count"
].
should
==
svc_size
.
to_s
end
it
"DELETE invalid host should not work"
do
host_data
=
{
:name
=>
"invalid_host.asdf.com"
}
delete
'/h/invalid_host.asdf.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
last_response
.
status
.
should
==
404
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Resource not found"
end
it
"DELETE /h/:hostname - invalid host"
do
host_data
=
{
:name
=>
"invalid_host.asdf.com"
}
delete
'/h/invalid_host.asdf.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
last_response
.
status
.
should
==
404
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Resource not found"
end
end
spec/noahapp_service_spec.rb
0 → 100644
View file @
6d5e76c0
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Service API"
,
:reset_redis
=>
false
,
:populate_sample_data
=>
true
do
describe
"calling"
do
describe
"GET"
do
it
"all services should work"
it
"all named services should work"
it
"named service for host should work"
end
describe
"PUT"
do
it
"new service should work"
it
"new service without host should not work"
it
"new service with invalid status should not work"
it
"new service with missing name should not work"
it
"new service with missing status should not work"
it
"existing service should work"
end
describe
"DELETE"
do
it
"existing host should work"
it
"invalid host should not work"
end
end
end
spec/spec_helper.rb
View file @
6d5e76c0
...
...
@@ -19,6 +19,7 @@ RSpec.configure do |config|
config
.
formatter
=
"documentation"
config
.
before
(
:each
,
:reset_redis
=>
true
)
{
Ohm
::
redis
.
flushdb
}
config
.
after
(
:each
,
:reset_redis
=>
true
)
{
Ohm
::
redis
.
flushdb
}
config
.
after
(
:all
,
:populate_sample_data
=>
true
)
{
Ohm
::
redis
.
flushdb
}
config
.
before
(
:all
,
:populate_sample_data
=>
true
)
do
Ohm
::
redis
.
flushdb
h
=
Host
.
create
(
:name
=>
'localhost'
,
:status
=>
"up"
)
...
...
@@ -71,3 +72,10 @@ end
def
app
NoahApp
end
RSpec
::
Matchers
.
define
:return_json
do
|
attribute
|
match
do
|
last_response
|
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment