jenkins_api_client 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +3 -0
  2. data/.jenkins.yml +9 -0
  3. data/.travis.yml +11 -15
  4. data/CHANGELOG.md +15 -0
  5. data/Gemfile +2 -2
  6. data/README.md +7 -9
  7. data/Rakefile +27 -14
  8. data/lib/jenkins_api_client.rb +36 -6
  9. data/lib/jenkins_api_client/build_queue.rb +213 -0
  10. data/lib/jenkins_api_client/cli/base.rb +10 -6
  11. data/lib/jenkins_api_client/cli/helper.rb +13 -4
  12. data/lib/jenkins_api_client/cli/job.rb +6 -9
  13. data/lib/jenkins_api_client/cli/node.rb +6 -4
  14. data/lib/jenkins_api_client/cli/system.rb +2 -1
  15. data/lib/jenkins_api_client/client.rb +31 -25
  16. data/lib/jenkins_api_client/job.rb +248 -95
  17. data/lib/jenkins_api_client/node.rb +128 -10
  18. data/lib/jenkins_api_client/system.rb +4 -2
  19. data/lib/jenkins_api_client/version.rb +2 -2
  20. data/lib/jenkins_api_client/view.rb +17 -4
  21. data/scripts/login_with_irb.rb +4 -3
  22. data/spec/func_tests/client_spec.rb +90 -0
  23. data/spec/func_tests/job_spec.rb +348 -0
  24. data/spec/func_tests/node_spec.rb +174 -0
  25. data/spec/{spec_helper.rb → func_tests/spec_helper.rb} +2 -2
  26. data/spec/func_tests/system_spec.rb +55 -0
  27. data/spec/func_tests/view_spec.rb +53 -0
  28. data/spec/unit_tests/client_spec.rb +211 -0
  29. data/spec/unit_tests/fixtures/files/computer_sample.xml +17 -0
  30. data/spec/unit_tests/fixtures/files/job_sample.xml +16 -0
  31. data/spec/unit_tests/job_spec.rb +355 -0
  32. data/spec/unit_tests/node_spec.rb +192 -0
  33. data/spec/unit_tests/spec_helper.rb +8 -0
  34. data/spec/unit_tests/system_spec.rb +54 -0
  35. data/spec/unit_tests/view_spec.rb +127 -0
  36. metadata +34 -23
  37. data/spec/client_spec.rb +0 -52
  38. data/spec/job_spec.rb +0 -158
  39. data/spec/node_spec.rb +0 -48
  40. data/spec/system_spec.rb +0 -46
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../../../lib/jenkins_api_client', __FILE__)
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:each) do
5
+ end
6
+
7
+ end
8
+
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe JenkinsApi::Client::System do
4
+ context "With properly initialized Client" do
5
+ before do
6
+ @client = mock
7
+ @system = JenkinsApi::Client::System.new(@client)
8
+ end
9
+
10
+ describe "InstanceMethods" do
11
+ describe "#initialize" do
12
+ it "initializes by receiving an instance of client object" do
13
+ expect(
14
+ lambda{ JenkinsApi::Client::System.new(@client) }
15
+ ).not_to raise_error
16
+ end
17
+ end
18
+
19
+ describe "#quiet_down" do
20
+ it "sends a request to put the server in quiet down mode" do
21
+ @client.should_receive(:api_post_request).with("/quietDown")
22
+ @system.quiet_down
23
+ end
24
+ end
25
+
26
+ describe "#cancel_quiet_down" do
27
+ it "sends a request to take the server away from quiet down mode" do
28
+ @client.should_receive(:api_post_request).with("/cancelQuietDown")
29
+ @system.cancel_quiet_down
30
+ end
31
+ end
32
+
33
+ describe "#restart" do
34
+ it "sends a safe restart request to the server" do
35
+ @client.should_receive(:api_post_request).with("/safeRestart")
36
+ @system.restart(false)
37
+ end
38
+ it "sends a force restart request to the server" do
39
+ @client.should_receive(:api_post_request).with("/restart")
40
+ @system.restart(true)
41
+ end
42
+ end
43
+
44
+ describe "#wait_for_ready" do
45
+ it "exits if the response body doesn't have the wait message" do
46
+ @client.should_receive(:get_root).and_return(Net::HTTP.get_response(URI('http://example.com/index.html')))
47
+ @client.should_receive(:debug)
48
+ @system.wait_for_ready
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,127 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe JenkinsApi::Client::View do
4
+ context "With properly initialized Client" do
5
+ before do
6
+ @client = mock
7
+ @view = JenkinsApi::Client::View.new(@client)
8
+ @sample_views_json = {
9
+ "views" => [
10
+ {"name" => "test_view"},
11
+ {"name" => "test_view2"}
12
+ ]
13
+ }
14
+ @sample_view_json = {
15
+ "jobs" => [
16
+ {"name" => "test_job"},
17
+ {"name" => "test_job2"}
18
+ ]
19
+ }
20
+ end
21
+
22
+ describe "InstanceMethods" do
23
+ describe "#initialize" do
24
+ it "initializes by receiving an instane of client object" do
25
+ expect(
26
+ lambda { JenkinsApi::Client::View.new(@client) }
27
+ ).not_to raise_error
28
+ end
29
+ end
30
+
31
+ describe "#create" do
32
+ it "creates a view by accepting a name" do
33
+ @client.should_receive(:api_post_request)
34
+ @view.create("test_view")
35
+ end
36
+ end
37
+
38
+ describe "#delete" do
39
+ it "deletes the view with the given name" do
40
+ @client.should_receive(:api_post_request).with("/view/test_view/doDelete")
41
+ @view.delete("test_view")
42
+ end
43
+ end
44
+
45
+ describe "#list" do
46
+ it "lists all views" do
47
+ @client.should_receive(:api_get_request).with("/").and_return(@sample_views_json)
48
+ response = @view.list
49
+ response.class.should == Array
50
+ response.size.should == 2
51
+ end
52
+
53
+ it "lists views matching specific filter" do
54
+ @client.should_receive(:api_get_request).with("/").and_return(@sample_views_json)
55
+ response = @view.list("test_view2")
56
+ response.class.should == Array
57
+ response.size.should == 1
58
+ end
59
+
60
+ it "lists views matching specific filter and matches case" do
61
+ @client.should_receive(:api_get_request).with("/").and_return(@sample_views_json)
62
+ response = @view.list("TEST_VIEW", false)
63
+ response.class.should == Array
64
+ response.size.should == 0
65
+ end
66
+ end
67
+
68
+ describe "#exists?" do
69
+ it "returns true a view that exists" do
70
+ @client.should_receive(:api_get_request).with("/").and_return(@sample_views_json)
71
+ @view.exists?("test_view2").should == true
72
+ end
73
+
74
+ it "returns false for non-existent view" do
75
+ @client.should_receive(:api_get_request).with("/").and_return(@sample_views_json)
76
+ @view.exists?("i_am_not_there").should == false
77
+ end
78
+ end
79
+
80
+ describe "#list_jobs" do
81
+ it "lists all jobs in the given view" do
82
+ @client.should_receive(:api_get_request).with("/").and_return(@sample_views_json)
83
+ @client.should_receive(:api_get_request).with("/view/test_view").and_return(@sample_view_json)
84
+ response = @view.list_jobs("test_view")
85
+ response.class.should == Array
86
+ response.size.should == 2
87
+ end
88
+
89
+ it "raises an error if called on a non-existent view" do
90
+ @client.should_receive(:api_get_request).with("/").and_return(@sample_views_json)
91
+ expect(
92
+ lambda { @view.list_jobs("i_am_not_there") }
93
+ ).to raise_error
94
+ end
95
+ end
96
+
97
+ describe "#add_job" do
98
+ it "adds the specified job to the specified view" do
99
+ @client.should_receive(:api_post_request)
100
+ @view.add_job("test_view", "test_job3")
101
+ end
102
+ end
103
+
104
+ describe "#remove_job" do
105
+ it "removes the specified job to the specified view" do
106
+ @client.should_receive(:api_post_request)
107
+ @view.remove_job("test_view", "test_job")
108
+ end
109
+ end
110
+
111
+ describe "#get_config" do
112
+ it "obtains the config from the server for the specified view" do
113
+ @client.should_receive(:get_config).with("/view/test_view")
114
+ @view.get_config("test_view")
115
+ end
116
+ end
117
+
118
+ describe "#post_config" do
119
+ it "posts the config to the server for the specified view" do
120
+ @client.should_receive(:post_config).with("/view/test_view/config.xml", "<view>test_view</view>")
121
+ @view.post_config("test_view", "<view>test_view</view>")
122
+ end
123
+ end
124
+
125
+ end
126
+ end
127
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-13 00:00:00.000000000 Z
12
+ date: 2013-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: 0.16.0
54
54
  type: :runtime
@@ -56,7 +56,7 @@ dependencies:
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.16.0
62
62
  - !ruby/object:Gem::Dependency
@@ -92,29 +92,29 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: 1.4.0
94
94
  - !ruby/object:Gem::Dependency
95
- name: bundler
95
+ name: builder
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>='
99
+ - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: '1.0'
102
- type: :development
101
+ version: 3.1.3
102
+ type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '1.0'
109
+ version: 3.1.3
110
110
  - !ruby/object:Gem::Dependency
111
- name: jeweler
111
+ name: bundler
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.6.4
117
+ version: '1.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,23 +122,23 @@ dependencies:
122
122
  requirements:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
- version: 1.6.4
125
+ version: '1.0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: builder
127
+ name: jeweler
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
131
- - - ~>
131
+ - - ! '>='
132
132
  - !ruby/object:Gem::Version
133
- version: 3.1.3
133
+ version: 1.6.4
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
139
- - - ~>
139
+ - - ! '>='
140
140
  - !ruby/object:Gem::Version
141
- version: 3.1.3
141
+ version: 1.6.4
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: simplecov
144
144
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +184,7 @@ extensions: []
184
184
  extra_rdoc_files: []
185
185
  files:
186
186
  - .gitignore
187
+ - .jenkins.yml
187
188
  - .travis.yml
188
189
  - CHANGELOG.md
189
190
  - Gemfile
@@ -193,6 +194,7 @@ files:
193
194
  - bin/jenkinscli
194
195
  - config/login.yml.example
195
196
  - lib/jenkins_api_client.rb
197
+ - lib/jenkins_api_client/build_queue.rb
196
198
  - lib/jenkins_api_client/cli/base.rb
197
199
  - lib/jenkins_api_client/cli/helper.rb
198
200
  - lib/jenkins_api_client/cli/job.rb
@@ -206,11 +208,20 @@ files:
206
208
  - lib/jenkins_api_client/version.rb
207
209
  - lib/jenkins_api_client/view.rb
208
210
  - scripts/login_with_irb.rb
209
- - spec/client_spec.rb
210
- - spec/job_spec.rb
211
- - spec/node_spec.rb
212
- - spec/spec_helper.rb
213
- - spec/system_spec.rb
211
+ - spec/func_tests/client_spec.rb
212
+ - spec/func_tests/job_spec.rb
213
+ - spec/func_tests/node_spec.rb
214
+ - spec/func_tests/spec_helper.rb
215
+ - spec/func_tests/system_spec.rb
216
+ - spec/func_tests/view_spec.rb
217
+ - spec/unit_tests/client_spec.rb
218
+ - spec/unit_tests/fixtures/files/computer_sample.xml
219
+ - spec/unit_tests/fixtures/files/job_sample.xml
220
+ - spec/unit_tests/job_spec.rb
221
+ - spec/unit_tests/node_spec.rb
222
+ - spec/unit_tests/spec_helper.rb
223
+ - spec/unit_tests/system_spec.rb
224
+ - spec/unit_tests/view_spec.rb
214
225
  homepage: https://github.com/arangamani/jenkins_api_client
215
226
  licenses: []
216
227
  post_install_message:
data/spec/client_spec.rb DELETED
@@ -1,52 +0,0 @@
1
- #
2
- # Specifying JenkinsApi::Client class capabilities
3
- # Author: Kannan Manickam <arangamani.kannan@gmail.com>
4
- #
5
-
6
- require File.expand_path('../spec_helper', __FILE__)
7
- require 'yaml'
8
-
9
- describe JenkinsApi::Client do
10
- context "Given valid credentials and server information in the ~/.jenkins_api_client/login.yml" do
11
- before(:all) do
12
- @creds_file = '~/.jenkins_api_client/login.yml'
13
- # Grabbing just the server IP in a variable so we can check for wrong credentials
14
- @server_ip = YAML.load_file(File.expand_path(@creds_file, __FILE__))[:server_ip]
15
- begin
16
- @client = JenkinsApi::Client.new(YAML.load_file(File.expand_path(@creds_file, __FILE__)))
17
- rescue Exception => e
18
- puts "WARNING: Credentials are not set properly."
19
- puts e.message
20
- end
21
- end
22
-
23
- it "Should be able to toggle the debug value" do
24
- value = @client.debug
25
- @client.toggle_debug.should_not == value
26
- end
27
-
28
- it "Should be able to initialize with valid credentials" do
29
- client1 = JenkinsApi::Client.new(YAML.load_file(File.expand_path(@creds_file, __FILE__)))
30
- client1.class.should == JenkinsApi::Client
31
- end
32
-
33
- it "Should fail if wrong credentials are given" do
34
- begin
35
- client2 = JenkinsApi::Client.new(:server_ip => @server_ip, :username => 'stranger', :password => 'hacked')
36
- client2.job.list_all
37
- rescue Exception => e
38
- e.class.should == JenkinsApi::Exceptions::UnautherizedException
39
- end
40
- end
41
-
42
- it "Should return a job object on call to job function" do
43
- @client.job.class.should == JenkinsApi::Client::Job
44
- end
45
-
46
- it "Should accept a YAML argument when creating a new client" do
47
- client3 = JenkinsApi::Client.new(YAML.load_file(File.expand_path(@creds_file, __FILE__)))
48
- client3.class.should == JenkinsApi::Client
49
- end
50
-
51
- end
52
- end
data/spec/job_spec.rb DELETED
@@ -1,158 +0,0 @@
1
- #
2
- # Specifying JenkinsApi::Client::Job class capabilities
3
- # Author: Kannan Manickam <arangamani.kannan@gmail.com>
4
- #
5
-
6
- require File.expand_path('../spec_helper', __FILE__)
7
- require 'yaml'
8
-
9
- describe JenkinsApi::Client::Job do
10
- context "With properly initialized client" do
11
- before(:all) do
12
- @helper = JenkinsApiSpecHelper::Helper.new
13
- @creds_file = '~/.jenkins_api_client/login.yml'
14
- @job_name_prefix = 'awesome_rspec_test_job'
15
- @filter = "^#{@job_name_prefix}.*"
16
- @job_name = ''
17
- begin
18
- @client = JenkinsApi::Client.new(YAML.load_file(File.expand_path(@creds_file, __FILE__)))
19
- rescue Exception => e
20
- puts "WARNING: Credentials are not set properly."
21
- puts e.message
22
- end
23
- # Creating 10 jobs to run the spec tests on
24
- begin
25
- 10.times do |num|
26
- xml = @helper.create_job_xml
27
- job = "#{@job_name_prefix}_#{num}"
28
- @job_name = job if num == 0
29
- @client.job.create(job, xml).to_i.should == 200
30
- end
31
- rescue Exception => e
32
- puts "WARNING: Can't create jobs for preparing to spec tests"
33
- end
34
- end
35
-
36
- it "Should be able to create a job" do
37
- xml = @helper.create_job_xml
38
- @client.job.create("some_random_nonexistent_job", xml).to_i.should == 200
39
- end
40
-
41
- it "Should be able to re-create a job" do
42
- @client.job.recreate("some_random_nonexistent_job").to_i.should == 200
43
- end
44
-
45
- it "Should be able to change the description of a job" do
46
- @client.job.change_description("some_random_nonexistent_job", "The description has been changed by the spec test").to_i.should == 200
47
- end
48
-
49
- it "Should be able to delete a job" do
50
- @client.job.delete("some_random_nonexistent_job").to_i.should == 302
51
- end
52
-
53
- it "Should list all jobs" do
54
- @client.job.list_all.class.should == Array
55
- end
56
-
57
- it "Should return job names based on the filter" do
58
- names = @client.job.list(@filter)
59
- names.class.should == Array
60
- names.each { |name|
61
- name.should match /#{@filter}/i
62
- }
63
- end
64
-
65
- it "Should be able to list jobs by status" do
66
- names = @client.job.list('success')
67
- names.class.should == Array
68
- names.each do |name|
69
- status = @client.job.get_current_build_status(name)
70
- status.should == 'success'
71
- end
72
- end
73
-
74
- it "Should return all job names with details" do
75
- @client.job.list_all_with_details.class.should == Array
76
- end
77
-
78
- it "Should list details of a particular job" do
79
- job_name = @client.job.list(@filter)[0]
80
- job_name.class.should == String
81
- @client.job.list_details(job_name).class.should == Hash
82
- end
83
-
84
- it "Should list upstream projects of the specified job" do
85
- @client.job.get_upstream_projects(@job_name).class.should == Array
86
- end
87
-
88
- it "Should list downstream projects of the specified job" do
89
- @client.job.get_downstream_projects(@job_name).class.should == Array
90
- end
91
-
92
- it "Should get builds of a specified job" do
93
- @client.job.get_builds(@job_name).class.should == Array
94
- end
95
-
96
- it "Should obtain the current build status for the specified job" do
97
- build_status = @client.job.get_current_build_status(@job_name)
98
- build_status.class.should == String
99
- valid_build_status = ["not_run", "aborted", "success", "failure", "unstable", "running"]
100
- valid_build_status.include?(build_status).should be_true
101
- end
102
-
103
- it "Should list all running jobs" do
104
- @client.job.list_running.class.should == Array
105
- end
106
-
107
- it "Should build the specified job" do
108
- @client.job.get_current_build_status(@job_name).should_not == "running"
109
- response = @client.job.build(@job_name)
110
- response.to_i.should == 302
111
- # Sleep for 20 seconds so we don't hit the Jenkins quiet period
112
- sleep 20
113
- @client.job.get_current_build_status(@job_name).should == "running"
114
- while @client.job.get_current_build_status(@job_name) == "running" do
115
- # Waiting for this job to finish so it doesn't affect other tests
116
- sleep 10
117
- end
118
- end
119
-
120
- it "Should be able to abort a recent build of a running job" do
121
- @client.job.get_current_build_status(@job_name).should_not == "running"
122
- @client.job.build(@job_name)
123
- sleep 20
124
- @client.job.get_current_build_status(@job_name).should == "running"
125
- sleep 20
126
- @client.job.stop_build(@job_name).should.to_i == 302
127
- sleep 20
128
- @client.job.get_current_build_status(@job_name).should == "aborted"
129
- end
130
-
131
- it "Should be able to restrict a job to a node" do
132
- @client.job.restrict_to_node(@job_name, 'master').to_i.should == 200
133
- # Run it again to make sure that the replace existing node works
134
- @client.job.restrict_to_node(@job_name, 'master').to_i.should == 200
135
- end
136
-
137
- it "Should be able to chain jobs" do
138
- #
139
- jobs = @client.job.list(@filter)
140
- jobs.class.should == Array
141
- start_jobs = @client.job.chain(jobs, 'success', ["all"])
142
- start_jobs.class.should == Array
143
- start_jobs.length.should == 1
144
-
145
- start_jobs = @client.job.chain(jobs, 'failure', ["not_run", "aborted", 'failure'], 3)
146
- start_jobs.class.should == Array
147
- start_jobs.length.should == 3
148
- end
149
-
150
- after(:all) do
151
- job_names = @client.job.list(@filter)
152
- job_names.each { |job_name|
153
- @client.job.delete(job_name)
154
- }
155
- end
156
-
157
- end
158
- end