subordinate 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/lib/subordinate/authentication.rb +2 -16
- data/lib/subordinate/client.rb +14 -23
- data/lib/subordinate/client/job.rb +5 -5
- data/lib/subordinate/client/system.rb +5 -15
- data/lib/subordinate/client/view.rb +2 -4
- data/lib/subordinate/configuration.rb +3 -6
- data/lib/subordinate/connection.rb +24 -3
- data/lib/subordinate/error.rb +45 -0
- data/lib/subordinate/request.rb +21 -21
- data/lib/subordinate/version.rb +1 -1
- data/spec/spec_helper.rb +14 -13
- data/spec/subordinate/client/job_spec.rb +10 -5
- data/spec/subordinate/client/system_spec.rb +12 -12
- data/spec/subordinate/client/view_spec.rb +5 -31
- data/spec/subordinate/configuration_spec.rb +15 -83
- data/spec/subordinate/error_spec.rb +58 -0
- data/subordinate.gemspec +1 -0
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MTExMzMxNjYwNzkxMzM1ZDQ0YzJhYmNjYWVmNTYzNzlhZDI0YjE4YTgwOWVh
|
10
|
-
OGM5NWUxZTZhYzFkNjRmNDAwOGIyNzhhZjhhYWU5MWQxYjcxOTAxMzRlZTFl
|
11
|
-
YmIyOTBhNjg1MmE3N2RjZDA1ZTk1M2U3MjRiY2Q2ODhjZjYwZWM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZTJiMzcwOWE2NDJhMjg4ZDRkNTU4ZGRmOGU4OGI1YzQ4NTE3N2NkODRhNDk4
|
14
|
-
MjU2MTUwMjViOWYwY2E2MTlhYzk3MDBmYTlhMThhOGY3Y2MwYmNmMWYyZGE4
|
15
|
-
M2Q3MGMzM2RkMTkwOWE1NzBmODljNTU4OGYyNzRlMjIxODljNmI=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2fcc3f8225a4165734cf15cd4991414242ed0780
|
4
|
+
data.tar.gz: 59259f7cc29b1938f48740b25097a6a0bc47ece3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2f5738a31937943c7852ff24a6ee68176ee91cc72c3d622e44f5dcf394aff5262cbdef5b5a6d09c2c7e262062a83f9df2f1eff63d137eae564babb4371b945a
|
7
|
+
data.tar.gz: f440f7ae37de8c3e93adb8024111cc45f3477fc4d284eaccde6079538ed2c2cd40689eb66003a6aa70e481df6893bb04fc40e1568a3df9a15441e61368b73973
|
@@ -1,22 +1,8 @@
|
|
1
1
|
# Authentication Module
|
2
2
|
module Subordinate
|
3
3
|
module Authentication
|
4
|
-
def authentication
|
5
|
-
if username && api_token
|
6
|
-
{ :username => username, :api_token => api_token}
|
7
|
-
else
|
8
|
-
{}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
4
|
def authenticated?
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def username_and_token(username = "", api_token = "")
|
17
|
-
return if username.nil? || api_token.nil?
|
18
|
-
self.username = username
|
19
|
-
self.api_token = api_token
|
5
|
+
!!(username && api_token)
|
20
6
|
end
|
21
7
|
end
|
22
|
-
end
|
8
|
+
end
|
data/lib/subordinate/client.rb
CHANGED
@@ -2,15 +2,7 @@
|
|
2
2
|
require "subordinate/authentication"
|
3
3
|
require "subordinate/connection"
|
4
4
|
require "subordinate/request"
|
5
|
-
|
6
|
-
require "subordinate/client/job"
|
7
|
-
require "subordinate/client/system"
|
8
|
-
require "subordinate/client/build"
|
9
|
-
require "subordinate/client/queue"
|
10
|
-
require "subordinate/client/load"
|
11
|
-
require "subordinate/client/people"
|
12
|
-
require "subordinate/client/view"
|
13
|
-
require "subordinate/client/executor"
|
5
|
+
Dir[File.expand_path("../client/*.rb", __FILE__)].each {|f| require f }
|
14
6
|
|
15
7
|
module Subordinate
|
16
8
|
class Client
|
@@ -22,23 +14,13 @@ module Subordinate
|
|
22
14
|
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
23
15
|
send("#{key}=", options[key])
|
24
16
|
end
|
25
|
-
|
26
|
-
username_and_token(options[:username], options[:api_token])
|
27
|
-
build_endpoint
|
28
17
|
end
|
29
18
|
|
30
19
|
# Builds the api endpoint to reach the Jenkins Server
|
31
20
|
#
|
32
|
-
# @return [String] Endpoint
|
33
|
-
|
34
|
-
|
35
|
-
def build_endpoint
|
36
|
-
endpoint = ssl ? "https://" : "http://"
|
37
|
-
endpoint << "#{self.username}:#{self.api_token}@" if self.authenticated?
|
38
|
-
endpoint << "#{self.subdomain}." if self.subdomain
|
39
|
-
endpoint << "#{self.domain}" if self.domain
|
40
|
-
endpoint << ":#{self.port}" if self.port
|
41
|
-
self.api_endpoint = endpoint
|
21
|
+
# @return [String] Endpoint - the api endpoint to the server
|
22
|
+
def api_endpoint
|
23
|
+
build_endpoint
|
42
24
|
end
|
43
25
|
|
44
26
|
include Subordinate::Authentication
|
@@ -53,5 +35,14 @@ module Subordinate
|
|
53
35
|
include Subordinate::Client::People
|
54
36
|
include Subordinate::Client::View
|
55
37
|
include Subordinate::Client::Executor
|
38
|
+
|
39
|
+
private
|
40
|
+
def build_endpoint
|
41
|
+
endpoint = ssl ? "https://" : "http://"
|
42
|
+
endpoint << "#{self.subdomain}." if self.subdomain
|
43
|
+
endpoint << "#{self.domain}" if self.domain
|
44
|
+
endpoint << ":#{self.port}" if self.port
|
45
|
+
endpoint
|
46
|
+
end
|
56
47
|
end
|
57
|
-
end
|
48
|
+
end
|
@@ -34,7 +34,7 @@ module Subordinate
|
|
34
34
|
#
|
35
35
|
# @author Jason Truluck
|
36
36
|
def build_job(job, options = {})
|
37
|
-
post("job/#{job}/build", options)
|
37
|
+
post("job/#{job}/build", options)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Builds the job specified on the Jenkins server with specified parameters
|
@@ -51,7 +51,7 @@ module Subordinate
|
|
51
51
|
#
|
52
52
|
# @author Jason Truluck
|
53
53
|
def build_job_with_params(job, options = {})
|
54
|
-
post("job/#{job}/buildWithParameters", options)
|
54
|
+
post("job/#{job}/buildWithParameters", options)
|
55
55
|
end
|
56
56
|
|
57
57
|
# Disables the specified job on the Jenkins Server
|
@@ -67,7 +67,7 @@ module Subordinate
|
|
67
67
|
#
|
68
68
|
# @author Jason Truluck
|
69
69
|
def disable_job(job, options = {})
|
70
|
-
post("job/#{job}/disable", options)
|
70
|
+
post("job/#{job}/disable", options)
|
71
71
|
end
|
72
72
|
|
73
73
|
# Enables the specified job on the Jenkins Server
|
@@ -83,7 +83,7 @@ module Subordinate
|
|
83
83
|
#
|
84
84
|
# @author Jason Truluck
|
85
85
|
def enable_job(job, options = {})
|
86
|
-
post("job/#{job}/enable", options)
|
86
|
+
post("job/#{job}/enable", options)
|
87
87
|
end
|
88
88
|
|
89
89
|
# Deletes the specified job on the Jenkins Server
|
@@ -99,7 +99,7 @@ module Subordinate
|
|
99
99
|
#
|
100
100
|
# @author Jason Truluck
|
101
101
|
def delete_job(job, options = {})
|
102
|
-
post("job/#{job}/delete", options)
|
102
|
+
post("job/#{job}/delete", options)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -15,8 +15,6 @@ module Subordinate
|
|
15
15
|
#
|
16
16
|
# @example Get the root api response
|
17
17
|
# Subordinate::Client.root
|
18
|
-
#
|
19
|
-
# @author Jason Truluck
|
20
18
|
def root(options = {})
|
21
19
|
get('/api/json', options)
|
22
20
|
end
|
@@ -29,10 +27,8 @@ module Subordinate
|
|
29
27
|
#
|
30
28
|
# @example Send a quiet down request to the Jenkins server
|
31
29
|
# Subordinate::Client.quiet_down
|
32
|
-
#
|
33
|
-
# @author Jason Truluck
|
34
30
|
def quiet_down(options = {})
|
35
|
-
post('/quietDown', options)
|
31
|
+
post('/quietDown', options)
|
36
32
|
end
|
37
33
|
|
38
34
|
# Cancel a shut down request to the Jenkins Server
|
@@ -43,10 +39,8 @@ module Subordinate
|
|
43
39
|
#
|
44
40
|
# @example Send a quiet down request to the Jenkins server
|
45
41
|
# Subordinate::Client.cancel_quiet_down
|
46
|
-
#
|
47
|
-
# @author Jason Truluck
|
48
42
|
def cancel_quiet_down(options = {})
|
49
|
-
post('/cancelQuietDown', options)
|
43
|
+
post('/cancelQuietDown', options)
|
50
44
|
end
|
51
45
|
|
52
46
|
# Restarts the jenkins server, will not wait for jobs to finish
|
@@ -57,10 +51,8 @@ module Subordinate
|
|
57
51
|
#
|
58
52
|
# @example Sends a force restart request to the Jenkins server
|
59
53
|
# Subordinate::Client.restart(true)
|
60
|
-
#
|
61
|
-
# @author Jason Truluck
|
62
54
|
def restart(options = {})
|
63
|
-
post("restart", options)
|
55
|
+
post("restart", options)
|
64
56
|
end
|
65
57
|
|
66
58
|
# Safely Restarts the jenkins server, will wait for jobs to finish
|
@@ -71,11 +63,9 @@ module Subordinate
|
|
71
63
|
#
|
72
64
|
# @example Sends a restart request to the Jenkins server (defaults to no force)
|
73
65
|
# Subordinate::Client.restart
|
74
|
-
#
|
75
|
-
# @author Jason Truluck
|
76
66
|
def safe_restart(options = {})
|
77
|
-
post("safeRestart", options)
|
67
|
+
post("safeRestart", options)
|
78
68
|
end
|
79
69
|
end
|
80
70
|
end
|
81
|
-
end
|
71
|
+
end
|
@@ -54,7 +54,6 @@ module Subordinate
|
|
54
54
|
# @author Jason Truluck
|
55
55
|
def add_job_to_view(view_name, job, options = {})
|
56
56
|
options.merge!(
|
57
|
-
:with_query_params => true,
|
58
57
|
:name => job
|
59
58
|
)
|
60
59
|
post("view/#{view_name}/addJobToView", options)
|
@@ -75,11 +74,10 @@ module Subordinate
|
|
75
74
|
# @author Jason Truluck
|
76
75
|
def remove_job_from_view(view_name, job, options = {})
|
77
76
|
options.merge!(
|
78
|
-
|
79
|
-
:name => job
|
77
|
+
:name => job
|
80
78
|
)
|
81
79
|
post("view/#{view_name}/removeJobFromView", options)
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
85
|
-
end
|
83
|
+
end
|
@@ -22,12 +22,9 @@ module Subordinate
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def reset!
|
25
|
-
|
26
|
-
self.
|
27
|
-
self
|
28
|
-
self.subdomain = nil
|
29
|
-
self.port = nil
|
30
|
-
self.ssl = true
|
25
|
+
VALID_OPTIONS_KEYS.each {|key| instance_variable_set("@#{key}".to_sym, nil) }
|
26
|
+
self.ssl = true
|
27
|
+
self
|
31
28
|
end
|
32
29
|
end
|
33
30
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Connection
|
2
|
+
require "json"
|
2
3
|
require "faraday_middleware"
|
4
|
+
require "subordinate/error"
|
3
5
|
|
4
6
|
module Subordinate
|
5
7
|
module Connection
|
@@ -9,12 +11,31 @@ module Subordinate
|
|
9
11
|
}.merge(options)
|
10
12
|
|
11
13
|
connection = Faraday.new(options) do |build|
|
12
|
-
build.
|
13
|
-
|
14
|
+
build.request :url_encoded
|
15
|
+
if authenticated?
|
16
|
+
build.request :basic_auth, self.username, self.api_token
|
17
|
+
end
|
18
|
+
build.response :mashify
|
19
|
+
build.response :json, :content_type => /\bjson$/
|
20
|
+
build.use ErrorMiddleware
|
14
21
|
build.adapter Faraday.default_adapter
|
15
22
|
end
|
16
23
|
|
17
24
|
connection
|
18
25
|
end
|
26
|
+
# Middleware for responding to Errors returned from the api
|
27
|
+
class ErrorMiddleware < Faraday::Middleware
|
28
|
+
def initialize(app)
|
29
|
+
@app = app
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(env)
|
33
|
+
@app.call(env).on_complete do |env|
|
34
|
+
if error = Subordinate::Error.from(env[:response])
|
35
|
+
raise error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
19
40
|
end
|
20
|
-
end
|
41
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# lib/subordinate/error.rb
|
2
|
+
module Subordinate
|
3
|
+
class Error < StandardError
|
4
|
+
attr_accessor :response
|
5
|
+
|
6
|
+
def self.from(response)
|
7
|
+
status = response.status
|
8
|
+
|
9
|
+
if klass = case status
|
10
|
+
when 400 then Subordinate::BadRequest
|
11
|
+
when 401 then Subordinate::Unauthorized
|
12
|
+
when 404 then Subordinate::NotFound
|
13
|
+
when 422 then Subordinate::UnprocessableEntity
|
14
|
+
when 500 then Subordinate::InternalServerError
|
15
|
+
end
|
16
|
+
|
17
|
+
klass.new(response)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(response)
|
22
|
+
@response = response
|
23
|
+
super(error_message)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def error_message
|
28
|
+
message = "#{response.env[:method].upcase} "
|
29
|
+
message << "#{response.env[:url].to_s} | "
|
30
|
+
message << "#{response.status} "
|
31
|
+
message
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Raised when Jenkins REST Api returns a 400 HTTP status code
|
36
|
+
class BadRequest < Error; end
|
37
|
+
# Raised when Jenkins REST Api returns a 401 HTTP status code
|
38
|
+
class Unauthorized < Error; end
|
39
|
+
# Raised when Jenkins REST Api returns a 404 HTTP status code
|
40
|
+
class NotFound < Error; end
|
41
|
+
# Raised when Jenkins REST Api returns a 422 HTTP status code
|
42
|
+
class UnprocessableEntity < Error; end
|
43
|
+
# Raised when Jenkins REST Api returns a 500 HTTP status code
|
44
|
+
class InternalServerError < Error; end
|
45
|
+
end
|
data/lib/subordinate/request.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# lib/subordinate/request.rb
|
3
2
|
module Subordinate
|
4
3
|
module Request
|
5
4
|
def get(path, options = {})
|
6
|
-
|
7
|
-
response.body
|
5
|
+
request(:get, path, options)
|
8
6
|
end
|
9
7
|
|
10
8
|
def post(path, options = {})
|
11
|
-
|
12
|
-
|
9
|
+
request(:post, path, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def put(path, options = {})
|
13
|
+
request(:put, path, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(path, options = {})
|
17
|
+
request(:delete, path, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_response
|
21
|
+
@last_response
|
13
22
|
end
|
14
23
|
|
15
24
|
private
|
16
25
|
def request(method, path, options = {})
|
17
|
-
url = options.delete(:
|
26
|
+
url = options.delete(:api_endpoint) || api_endpoint
|
18
27
|
|
19
28
|
connection_options = {
|
20
29
|
:url => url
|
21
30
|
}
|
22
31
|
|
23
32
|
response = connection(connection_options).send(method) do |request|
|
24
|
-
|
25
|
-
when :get
|
26
|
-
request.url(path, options)
|
27
|
-
when :post
|
28
|
-
with_query_params = options.delete(:with_query_params) || false
|
29
|
-
if with_query_params
|
30
|
-
request.url(path, options)
|
31
|
-
else
|
32
|
-
request.path = path
|
33
|
-
request.body = MultiJson.dump(options) unless options.empty?
|
34
|
-
end
|
35
|
-
end
|
33
|
+
request.url(path, options)
|
36
34
|
end
|
37
|
-
|
35
|
+
|
36
|
+
@last_response = response
|
37
|
+
response.body
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
data/lib/subordinate/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'coveralls'
|
3
|
+
require "pry"
|
3
4
|
Coveralls.wear!
|
4
5
|
|
5
6
|
ENV["RAILS_ENV"] ||= 'test'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
File.open("coverage/covered_percent", "w") do |f|
|
14
|
-
f.puts result.source_files.covered_percent.to_f
|
15
|
-
end
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start 'rails'
|
9
|
+
class SimpleCov::Formatter::QualityFormatter
|
10
|
+
def format(result)
|
11
|
+
SimpleCov::Formatter::HTMLFormatter.new.format(result)
|
12
|
+
File.open("coverage/covered_percent", "w") do |f|
|
13
|
+
f.puts result.source_files.covered_percent.to_f
|
16
14
|
end
|
17
15
|
end
|
18
|
-
SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
|
19
16
|
end
|
17
|
+
SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
|
20
18
|
|
21
19
|
require 'subordinate'
|
22
20
|
require "webmock/rspec"
|
@@ -25,12 +23,15 @@ Dir[File.expand_path("spec/support/**/*.rb", __FILE__)].each {|f| require f}
|
|
25
23
|
|
26
24
|
RSpec.configure do |config|
|
27
25
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
26
|
+
config.color_enabled = true
|
28
27
|
config.order = "random"
|
29
28
|
end
|
30
29
|
|
31
30
|
def stub_jenkins(http_method = :any, endpoint = "/", status = 200, content_type = "application/json", response)
|
32
31
|
stub_request(http_method, "http://someusername:sometoken@jenkins.example.com:8080#{endpoint}").
|
33
|
-
to_return(
|
32
|
+
to_return(
|
33
|
+
:status => status,
|
34
34
|
:body => File.read(File.expand_path("../support/mocks/#{response}", __FILE__)),
|
35
|
-
:headers =>{'Accept' => content_type, 'Content-type' => content_type}
|
35
|
+
:headers =>{'Accept' => content_type, 'Content-type' => content_type}
|
36
|
+
)
|
36
37
|
end
|
@@ -138,7 +138,8 @@ describe Subordinate::Client do
|
|
138
138
|
it "builds the job specified" do
|
139
139
|
stub_jenkins(:post, "/job/Some-Job/build", 302, "empty.json")
|
140
140
|
|
141
|
-
subordinate.build_job("Some-Job")
|
141
|
+
subordinate.build_job("Some-Job")
|
142
|
+
expect(subordinate.last_response.status).to eq(302)
|
142
143
|
end
|
143
144
|
end
|
144
145
|
|
@@ -146,7 +147,8 @@ describe Subordinate::Client do
|
|
146
147
|
it "builds the job specified with the parameters specified" do
|
147
148
|
stub_jenkins(:post, "/job/Some-Job/buildWithParameters", 302, "empty.json")
|
148
149
|
|
149
|
-
subordinate.build_job_with_params("Some-Job")
|
150
|
+
subordinate.build_job_with_params("Some-Job")
|
151
|
+
expect(subordinate.last_response.status).to eq(302)
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
@@ -154,7 +156,8 @@ describe Subordinate::Client do
|
|
154
156
|
it "disables the specified job" do
|
155
157
|
stub_jenkins(:post, "/job/Some-Job/disable", 302, "empty.json")
|
156
158
|
|
157
|
-
subordinate.disable_job("Some-Job")
|
159
|
+
subordinate.disable_job("Some-Job")
|
160
|
+
expect(subordinate.last_response.status).to eq(302)
|
158
161
|
end
|
159
162
|
end
|
160
163
|
|
@@ -162,7 +165,8 @@ describe Subordinate::Client do
|
|
162
165
|
it "enables the specified job" do
|
163
166
|
stub_jenkins(:post, "/job/Some-Job/enable", 302, "empty.json")
|
164
167
|
|
165
|
-
subordinate.enable_job("Some-Job")
|
168
|
+
subordinate.enable_job("Some-Job")
|
169
|
+
expect(subordinate.last_response.status).to eq(302)
|
166
170
|
end
|
167
171
|
end
|
168
172
|
|
@@ -170,7 +174,8 @@ describe Subordinate::Client do
|
|
170
174
|
it "deletes the specified job" do
|
171
175
|
stub_jenkins(:post, "/job/Some-Job/delete", 302, "empty.json")
|
172
176
|
|
173
|
-
subordinate.delete_job("Some-Job")
|
177
|
+
subordinate.delete_job("Some-Job")
|
178
|
+
expect(subordinate.last_response.status).to eq(302)
|
174
179
|
end
|
175
180
|
end
|
176
181
|
end
|
@@ -88,19 +88,19 @@ describe Subordinate::Client do
|
|
88
88
|
|
89
89
|
describe "#quiet_down" do
|
90
90
|
it "will shut down the server" do
|
91
|
-
|
92
|
-
to_return(:status => 302, :body => "", :headers => {})
|
91
|
+
stub_jenkins(:post, "/quietDown", 302, "empty.json")
|
93
92
|
|
94
|
-
subordinate.quiet_down
|
93
|
+
subordinate.quiet_down
|
94
|
+
expect(subordinate.last_response.status).to eq(302)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
describe "#cancel_quiet_down" do
|
99
99
|
it "will cancel a shut down request to the server" do
|
100
|
-
|
101
|
-
to_return(:status => 302, :body => "", :headers => {})
|
100
|
+
stub_jenkins(:post, "/cancelQuietDown", 302, "empty.json")
|
102
101
|
|
103
|
-
subordinate.cancel_quiet_down
|
102
|
+
subordinate.cancel_quiet_down
|
103
|
+
expect(subordinate.last_response.status).to eq(302)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -108,19 +108,19 @@ describe Subordinate::Client do
|
|
108
108
|
# commented out since random order is used.
|
109
109
|
describe "#restart" do
|
110
110
|
it "will force restart the jenkins server" do
|
111
|
-
|
112
|
-
to_return(:status => 302, :body => "", :headers => {})
|
111
|
+
stub_jenkins(:post, "/restart", 302, "empty.json")
|
113
112
|
|
114
|
-
subordinate.restart
|
113
|
+
subordinate.restart
|
114
|
+
expect(subordinate.last_response.status).to eq(302)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
describe "#safe_restart" do
|
119
119
|
it "will restart the jenkins server" do
|
120
|
-
|
121
|
-
to_return(:status => 302, :body => "", :headers => {})
|
120
|
+
stub_jenkins(:post, "/safeRestart", 302, "empty.json")
|
122
121
|
|
123
|
-
subordinate.safe_restart
|
122
|
+
subordinate.safe_restart
|
123
|
+
expect(subordinate.last_response.status).to eq(302)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
@@ -16,7 +16,7 @@ describe Subordinate::Client do
|
|
16
16
|
|
17
17
|
describe "#view" do
|
18
18
|
before(:each) { stub_jenkins(:get, "/view/someview/api/json", "view.json") }
|
19
|
-
|
19
|
+
|
20
20
|
let(:current_response) { subordinate.view("someview") }
|
21
21
|
|
22
22
|
it "returns the view response" do
|
@@ -80,21 +80,8 @@ describe Subordinate::Client do
|
|
80
80
|
it "responds with a success" do
|
81
81
|
stub_jenkins(:post, "/view/someview/addJobToView?name=somejob", 200, "empty.json")
|
82
82
|
|
83
|
-
subordinate.add_job_to_view("someview", "somejob")
|
84
|
-
|
85
|
-
|
86
|
-
context "error" do
|
87
|
-
it "returns 404 when not found" do
|
88
|
-
stub_jenkins(:post, "/view/someview/addJobToView?name=somejob", 404, "empty.json")
|
89
|
-
|
90
|
-
subordinate.add_job_to_view("someview", "somejob").status.should == 404
|
91
|
-
end
|
92
|
-
|
93
|
-
it "returns 500 when server error" do
|
94
|
-
stub_jenkins(:post, "/view/someview/addJobToView?name=somejob", 500, "empty.json")
|
95
|
-
|
96
|
-
subordinate.add_job_to_view("someview", "somejob").status.should == 500
|
97
|
-
end
|
83
|
+
subordinate.add_job_to_view("someview", "somejob")
|
84
|
+
expect(subordinate.last_response.status).to eq(200)
|
98
85
|
end
|
99
86
|
end
|
100
87
|
|
@@ -102,21 +89,8 @@ describe Subordinate::Client do
|
|
102
89
|
it "responds with a success" do
|
103
90
|
stub_jenkins(:post, "/view/someview/removeJobFromView?name=somejob", 200, "empty.json")
|
104
91
|
|
105
|
-
subordinate.remove_job_from_view("someview", "somejob")
|
106
|
-
|
107
|
-
|
108
|
-
context "error" do
|
109
|
-
it "returns 404 when not found" do
|
110
|
-
stub_jenkins(:post, "/view/someview/removeJobFromView?name=somejob", 404, "empty.json")
|
111
|
-
|
112
|
-
subordinate.remove_job_from_view("someview", "somejob").status.should == 404
|
113
|
-
end
|
114
|
-
|
115
|
-
it "returns 500 when server error" do
|
116
|
-
stub_jenkins(:post, "/view/someview/removeJobFromView?name=somejob", 500, "empty.json")
|
117
|
-
|
118
|
-
subordinate.remove_job_from_view("someview", "somejob").status.should == 500
|
119
|
-
end
|
92
|
+
subordinate.remove_job_from_view("someview", "somejob")
|
93
|
+
expect(subordinate.last_response.status).to eq(200)
|
120
94
|
end
|
121
95
|
end
|
122
96
|
end
|
@@ -2,118 +2,50 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe Subordinate::Client do
|
5
|
-
before do
|
6
|
-
Subordinate.reset!
|
7
|
-
|
8
|
-
Subordinate.configure do |c|
|
9
|
-
c.subdomain = "jenkins"
|
10
|
-
c.domain = "example.com"
|
11
|
-
c.port = 8080
|
12
|
-
c.ssl = false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
5
|
describe "configuration" do
|
17
6
|
let(:domain) { "woofound.com" }
|
18
7
|
let(:subdomain) { "awesome" }
|
19
8
|
let(:port) { 2000 }
|
20
9
|
let(:ssl) { false }
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Subordinate.configure do |c|
|
26
|
-
c.domain = domain
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:client) { Subordinate.new }
|
31
|
-
|
32
|
-
it "sets the domain for the client" do
|
33
|
-
client.domain.should == domain
|
34
|
-
end
|
11
|
+
before(:each){
|
12
|
+
Subordinate.reset!
|
13
|
+
}
|
35
14
|
|
15
|
+
describe "with a domain" do
|
36
16
|
it "builds an endpoint with the domain" do
|
37
|
-
|
17
|
+
Subordinate.reset!
|
18
|
+
client = Subordinate.new(domain: domain)
|
19
|
+
client.api_endpoint.should eq("https://#{domain}")
|
38
20
|
end
|
39
21
|
end
|
40
22
|
|
41
23
|
# SUBDOMAIN
|
42
24
|
describe "with a subdomain" do
|
43
|
-
before do
|
44
|
-
Subordinate.reset!
|
45
|
-
Subordinate.configure do |c|
|
46
|
-
c.subdomain = subdomain
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
let(:client) { Subordinate.new }
|
51
|
-
|
52
|
-
it "sets the subdomain for the client" do
|
53
|
-
client.subdomain.should == subdomain
|
54
|
-
end
|
55
|
-
|
56
25
|
it "builds an endpoint with the subdomain" do
|
57
|
-
client.
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "without a subdomain" do
|
62
|
-
it "builds an endpoint without a subdomain" do
|
63
|
-
client = Subordinate.new(:subdomain => nil)
|
64
|
-
client.api_endpoint.should == "http://example.com:8080"
|
26
|
+
client = Subordinate.new(domain: domain, subdomain: subdomain)
|
27
|
+
client.api_endpoint.should eq("https://#{subdomain}.#{domain}")
|
65
28
|
end
|
66
29
|
end
|
67
30
|
|
68
31
|
# PORT
|
69
32
|
describe "with a port" do
|
70
|
-
before do
|
71
|
-
Subordinate.reset!
|
72
|
-
Subordinate.configure do |c|
|
73
|
-
c.port = port
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
let(:client) { Subordinate.new }
|
78
|
-
|
79
|
-
it "sets the port for the client" do
|
80
|
-
client.port.should == port
|
81
|
-
end
|
82
|
-
|
83
33
|
it "builds an endpoint with the port" do
|
84
|
-
client.
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "without a port" do
|
89
|
-
it "builds an endpoint without a port" do
|
90
|
-
client = Subordinate.new(:port => nil)
|
91
|
-
client.api_endpoint.should == "http://jenkins.example.com"
|
34
|
+
client = Subordinate.new(domain: domain, port: port)
|
35
|
+
client.api_endpoint.should eq("https://#{domain}:#{port}")
|
92
36
|
end
|
93
37
|
end
|
94
38
|
|
95
39
|
# SSL
|
96
40
|
describe "with a ssl" do
|
97
|
-
before do
|
98
|
-
Subordinate.reset!
|
99
|
-
Subordinate.configure do |c|
|
100
|
-
c.ssl = ssl
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
let(:client) { Subordinate.new }
|
105
|
-
|
106
|
-
it "sets the ssl for the client" do
|
107
|
-
client.ssl.should == ssl
|
108
|
-
end
|
109
|
-
|
110
41
|
it "builds an endpoint with the ssl set to false" do
|
111
|
-
client.
|
42
|
+
client = Subordinate.new(domain: domain, ssl: false)
|
43
|
+
client.api_endpoint.should eq("http://#{domain}")
|
112
44
|
end
|
113
45
|
|
114
46
|
it "builds an endpoint with the ssl set to true" do
|
115
|
-
client = Subordinate.new(:ssl
|
116
|
-
client.api_endpoint.should
|
47
|
+
client = Subordinate.new(domain: domain, ssl: true)
|
48
|
+
client.api_endpoint.should eq("https://#{domain}")
|
117
49
|
end
|
118
50
|
end
|
119
51
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# spec/subordinate/error.rb
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Subordinate::Error do
|
5
|
+
before do
|
6
|
+
Subordinate.reset!
|
7
|
+
Subordinate.configure do |c|
|
8
|
+
c.subdomain = "jenkins"
|
9
|
+
c.domain = "example.com"
|
10
|
+
c.port = 8080
|
11
|
+
c.ssl = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:client) { Subordinate::Client.new(:username => "someusername", :api_token => "sometoken") }
|
16
|
+
|
17
|
+
describe "#from" do
|
18
|
+
describe "400 Error" do
|
19
|
+
it "raises a Subordinate::BadRequest error" do
|
20
|
+
stub_jenkins(:get, "/api/json", 400, "application/json", "base.json")
|
21
|
+
|
22
|
+
expect{ client.root }.to raise_error(Subordinate::BadRequest)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "401 Error" do
|
27
|
+
it "raises a Subordinate::Unauthorized error" do
|
28
|
+
stub_jenkins(:get, "/api/json", 401, "base.json")
|
29
|
+
|
30
|
+
expect{ client.root }.to raise_error(Subordinate::Unauthorized)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "404 Error" do
|
35
|
+
it "raises a Subordinate::NotFound error" do
|
36
|
+
stub_jenkins(:get, "/api/json", 404, "base.json")
|
37
|
+
|
38
|
+
expect{ client.root }.to raise_error(Subordinate::NotFound)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "422 Error" do
|
43
|
+
it "raises a Subordinate::UnprocessableEntity error" do
|
44
|
+
stub_jenkins(:get, "/api/json", 422, "base.json")
|
45
|
+
|
46
|
+
expect{ client.root }.to raise_error(Subordinate::UnprocessableEntity)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "500 Error" do
|
51
|
+
it "raises a Subordinate::InternalServerError error" do
|
52
|
+
stub_jenkins(:get, "/api/json", 500, "base.json")
|
53
|
+
|
54
|
+
expect{ client.root }.to raise_error(Subordinate::InternalServerError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/subordinate.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_development_dependency "rspec", "~> 2.14.0"
|
22
22
|
gem.add_development_dependency "rake", "~> 10.1.0"
|
23
23
|
gem.add_development_dependency "webmock", "~> 1.13.0"
|
24
|
+
gem.add_development_dependency "pry"
|
24
25
|
gem.add_development_dependency "simplecov", "~> 0.7.0"
|
25
26
|
gem.add_development_dependency "coveralls", "~> 0.7.0"
|
26
27
|
gem.add_development_dependency "yard", "~> 0.8.0.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subordinate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Truluck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.13.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: simplecov
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,6 +204,7 @@ files:
|
|
190
204
|
- lib/subordinate/client/view.rb
|
191
205
|
- lib/subordinate/configuration.rb
|
192
206
|
- lib/subordinate/connection.rb
|
207
|
+
- lib/subordinate/error.rb
|
193
208
|
- lib/subordinate/request.rb
|
194
209
|
- lib/subordinate/version.rb
|
195
210
|
- spec/spec_helper.rb
|
@@ -203,6 +218,7 @@ files:
|
|
203
218
|
- spec/subordinate/client/view_spec.rb
|
204
219
|
- spec/subordinate/client_spec.rb
|
205
220
|
- spec/subordinate/configuration_spec.rb
|
221
|
+
- spec/subordinate/error_spec.rb
|
206
222
|
- spec/support/mocks/base.json
|
207
223
|
- spec/support/mocks/build.json
|
208
224
|
- spec/support/mocks/build_timestamp.txt
|
@@ -229,17 +245,17 @@ require_paths:
|
|
229
245
|
- lib
|
230
246
|
required_ruby_version: !ruby/object:Gem::Requirement
|
231
247
|
requirements:
|
232
|
-
- -
|
248
|
+
- - '>='
|
233
249
|
- !ruby/object:Gem::Version
|
234
250
|
version: '0'
|
235
251
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
252
|
requirements:
|
237
|
-
- -
|
253
|
+
- - '>='
|
238
254
|
- !ruby/object:Gem::Version
|
239
255
|
version: '0'
|
240
256
|
requirements: []
|
241
257
|
rubyforge_project:
|
242
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.1.10
|
243
259
|
signing_key:
|
244
260
|
specification_version: 4
|
245
261
|
summary: Jenkins API wrapper
|
@@ -255,6 +271,7 @@ test_files:
|
|
255
271
|
- spec/subordinate/client/view_spec.rb
|
256
272
|
- spec/subordinate/client_spec.rb
|
257
273
|
- spec/subordinate/configuration_spec.rb
|
274
|
+
- spec/subordinate/error_spec.rb
|
258
275
|
- spec/support/mocks/base.json
|
259
276
|
- spec/support/mocks/build.json
|
260
277
|
- spec/support/mocks/build_timestamp.txt
|