jenkins_api_client 1.0.0.alpha.2 → 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG.md +56 -35
- data/CONTRIBUTORS.md +1 -13
- data/README.md +88 -2
- data/jenkins_api_client.gemspec +5 -3
- data/lib/jenkins_api_client/client.rb +56 -12
- data/lib/jenkins_api_client/job.rb +272 -54
- data/lib/jenkins_api_client/node.rb +6 -45
- data/lib/jenkins_api_client/urihelper.rb +17 -0
- data/lib/jenkins_api_client/user.rb +3 -1
- data/lib/jenkins_api_client/version.rb +1 -1
- data/lib/jenkins_api_client/view.rb +10 -7
- data/spec/func_tests/job_spec.rb +90 -7
- data/spec/func_tests/{node_spec.rb → node_spec.rb.pending} +0 -0
- data/spec/unit_tests/client_spec.rb +81 -27
- data/spec/unit_tests/fake_http_response.rb +9 -0
- data/spec/unit_tests/job_spec.rb +109 -6
- data/spec/unit_tests/system_spec.rb +2 -1
- metadata +5 -3
data/spec/unit_tests/job_spec.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require File.expand_path('../spec_helper', __FILE__)
|
2
2
|
require 'net/http'
|
3
|
+
require File.expand_path('../fake_http_response', __FILE__)
|
3
4
|
|
4
5
|
describe JenkinsApi::Client::Job do
|
5
6
|
context "With properly initialized Client and all methods defined" do
|
6
7
|
|
7
8
|
before do
|
8
9
|
mock_logger = Logger.new "/dev/null"
|
9
|
-
@client =
|
10
|
-
@client.should_receive(:logger).and_return(mock_logger)
|
10
|
+
@client = JenkinsApi::Client.new({:server_ip => '127.0.0.1'})
|
11
|
+
@client.should_receive(:logger).at_least(1).and_return(mock_logger)
|
11
12
|
@job = JenkinsApi::Client::Job.new(@client)
|
12
13
|
@sample_json_response = {
|
13
14
|
"jobs" => [
|
@@ -248,7 +249,7 @@ describe JenkinsApi::Client::Job do
|
|
248
249
|
msg = "/job/test_job/1/logText/progressiveText?start=0"
|
249
250
|
@client.should_receive(:api_get_request).
|
250
251
|
with(msg, nil, nil, true).
|
251
|
-
and_return(
|
252
|
+
and_return(FakeResponse.new)
|
252
253
|
@job.get_console_output('test_job', 1, 0, 'text')
|
253
254
|
end
|
254
255
|
|
@@ -380,19 +381,102 @@ describe JenkinsApi::Client::Job do
|
|
380
381
|
end
|
381
382
|
|
382
383
|
describe "#build" do
|
384
|
+
# First tests confirm the build method works the same as it used to
|
383
385
|
it "accepts the job name and builds the job" do
|
386
|
+
@client.should_receive(:api_get_request).with(
|
387
|
+
"/job/test_job").and_return({})
|
384
388
|
@client.should_receive(:api_post_request).with(
|
385
|
-
"/job/test_job/build", {},
|
389
|
+
"/job/test_job/build", {}, true).and_return(FakeResponse.new(302))
|
386
390
|
@job.build("test_job").should == 302
|
387
391
|
end
|
388
392
|
it "accepts the job name with params and builds the job" do
|
393
|
+
@client.should_receive(:api_get_request).with(
|
394
|
+
"/job/test_job").and_return({})
|
389
395
|
@client.should_receive(:api_post_request).with(
|
390
396
|
"/job/test_job/buildWithParameters",
|
391
397
|
{:branch => 'feature/new-stuff'},
|
392
|
-
|
393
|
-
).and_return(302)
|
398
|
+
true
|
399
|
+
).and_return(FakeResponse.new(302))
|
394
400
|
@job.build("test_job", {:branch => 'feature/new-stuff'}).should == 302
|
395
401
|
end
|
402
|
+
|
403
|
+
### OLD NON-QUEUE RESPONSE JENKINS ###
|
404
|
+
# Next tests confirm it deals with different jenkins versions and waits
|
405
|
+
# for build to start (or not)
|
406
|
+
it "accepts the job name and builds the job (w/timeout)" do
|
407
|
+
@client.should_receive(:api_get_request).with(
|
408
|
+
"/job/test_job").and_return({})
|
409
|
+
@client.should_receive(:api_post_request).with(
|
410
|
+
"/job/test_job/build", {}, true).and_return(FakeResponse.new(302))
|
411
|
+
@client.should_receive(:api_get_request).with(
|
412
|
+
"/job/test_job/1/").and_return({})
|
413
|
+
@client.should_receive(:get_jenkins_version).and_return("1.1")
|
414
|
+
@job.build("test_job", {}, {'build_start_timeout' => 10}).should == 1
|
415
|
+
end
|
416
|
+
|
417
|
+
# wait for build to start (or not) (initial response will fail)
|
418
|
+
it "accepts the job name and builds the job after short delay (w/timeout)" do
|
419
|
+
@client.should_receive(:api_get_request).with(
|
420
|
+
"/job/test_job").and_return({})
|
421
|
+
@client.should_receive(:api_post_request).with(
|
422
|
+
"/job/test_job/build", {}, true).and_return(FakeResponse.new(302))
|
423
|
+
@client.should_receive(:api_get_request).with(
|
424
|
+
"/job/test_job/1/").ordered.and_raise(JenkinsApi::Exceptions::NotFound.new(@client.logger))
|
425
|
+
@client.should_receive(:api_get_request).with(
|
426
|
+
"/job/test_job/1/").ordered.and_return({})
|
427
|
+
@client.should_receive(:get_jenkins_version).and_return("1.1")
|
428
|
+
@job.build("test_job", {}, {'build_start_timeout' => 3}).should == 1
|
429
|
+
end
|
430
|
+
|
431
|
+
# wait for build to start - will fail
|
432
|
+
it "accepts the job name and builds the job, but the job doesn't start" do
|
433
|
+
@client.should_receive(:api_get_request).with(
|
434
|
+
"/job/test_job").and_return({})
|
435
|
+
@client.should_receive(:api_post_request).with(
|
436
|
+
"/job/test_job/build", {}, true).and_return(FakeResponse.new(302))
|
437
|
+
@client.should_receive(:api_get_request).with(
|
438
|
+
"/job/test_job/1/").twice.ordered.and_raise(JenkinsApi::Exceptions::NotFound.new(@client.logger))
|
439
|
+
@client.should_receive(:get_jenkins_version).and_return("1.1")
|
440
|
+
expect( lambda { @job.build("test_job", {}, {'build_start_timeout' => 3}) }).to raise_error(Timeout::Error)
|
441
|
+
end
|
442
|
+
|
443
|
+
### JENKINS POST 1.519 (QUEUE RESPONSE) ###
|
444
|
+
# Next tests confirm it deals with different jenkins versions and waits
|
445
|
+
# for build to start (or not)
|
446
|
+
it "accepts the job name and builds the job (w/timeout)" do
|
447
|
+
@client.should_receive(:api_get_request).with(
|
448
|
+
"/job/test_job").and_return({})
|
449
|
+
@client.should_receive(:api_post_request).with(
|
450
|
+
"/job/test_job/build", {}, true).and_return({"location" => "/item/42/"})
|
451
|
+
@client.should_receive(:api_get_request).with(
|
452
|
+
"/queue/item/42").and_return({'executable' => {'number' => 1}})
|
453
|
+
@client.should_receive(:get_jenkins_version).and_return("1.519")
|
454
|
+
@job.build("test_job", {}, {'build_start_timeout' => 10}).should == 1
|
455
|
+
end
|
456
|
+
|
457
|
+
# wait for build to start (or not) (initial response will fail)
|
458
|
+
it "accepts the job name and builds the job after short delay (w/timeout)" do
|
459
|
+
@client.should_receive(:api_get_request).with(
|
460
|
+
"/job/test_job").and_return({})
|
461
|
+
@client.should_receive(:api_post_request).with(
|
462
|
+
"/job/test_job/build", {}, true).and_return({"location" => "/item/42/"})
|
463
|
+
@client.should_receive(:api_get_request).with(
|
464
|
+
"/queue/item/42").and_return({}, {'executable' => {'number' => 1}})
|
465
|
+
@client.should_receive(:get_jenkins_version).and_return("1.519")
|
466
|
+
@job.build("test_job", {}, {'build_start_timeout' => 3}).should == 1
|
467
|
+
end
|
468
|
+
|
469
|
+
# wait for build to start - will fail
|
470
|
+
it "accepts the job name and builds the job, but the job doesn't start" do
|
471
|
+
@client.should_receive(:api_get_request).with(
|
472
|
+
"/job/test_job").and_return({})
|
473
|
+
@client.should_receive(:api_post_request).with(
|
474
|
+
"/job/test_job/build", {}, true).and_return({"location" => "/item/42/"})
|
475
|
+
@client.should_receive(:api_get_request).with(
|
476
|
+
"/queue/item/42").and_return({}, {})
|
477
|
+
@client.should_receive(:get_jenkins_version).and_return("1.519")
|
478
|
+
expect( lambda { @job.build("test_job", {}, {'build_start_timeout' => 3}) }).to raise_error(Timeout::Error)
|
479
|
+
end
|
396
480
|
end
|
397
481
|
|
398
482
|
describe "#poll" do
|
@@ -515,6 +599,25 @@ describe JenkinsApi::Client::Job do
|
|
515
599
|
end
|
516
600
|
end
|
517
601
|
|
602
|
+
describe "#get_promotions" do
|
603
|
+
it "accepts the jon name and returns the promotions" do
|
604
|
+
mock_job_promotions_response = {
|
605
|
+
"processes" => [ { "name" => "dev",
|
606
|
+
"url" => "not_required",
|
607
|
+
"color" => "blue",
|
608
|
+
},
|
609
|
+
{ "name" => "stage",
|
610
|
+
"url" => "not_required",
|
611
|
+
"color" => "notbuilt",
|
612
|
+
},
|
613
|
+
], }
|
614
|
+
|
615
|
+
@client.should_receive(:api_get_request).with('/job/test_job/promotion').and_return(
|
616
|
+
mock_job_promotions_response)
|
617
|
+
@client.should_receive(:api_get_request).and_return({'target' => {'number' => 42}})
|
618
|
+
@job.get_promotions("test_job").should == {'dev' => 42, 'stage' => nil}
|
619
|
+
end
|
620
|
+
end
|
518
621
|
end
|
519
622
|
end
|
520
623
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fake_http_response', __FILE__)
|
2
3
|
|
3
4
|
describe JenkinsApi::Client::System do
|
4
5
|
context "With properly initialized Client" do
|
@@ -65,7 +66,7 @@ describe JenkinsApi::Client::System do
|
|
65
66
|
|
66
67
|
describe "#wait_for_ready" do
|
67
68
|
it "exits if the response body doesn't have the wait message" do
|
68
|
-
@client.should_receive(:get_root).and_return(
|
69
|
+
@client.should_receive(:get_root).and_return(FakeResponse.new)
|
69
70
|
@system.wait_for_ready
|
70
71
|
end
|
71
72
|
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: 1.0.0.
|
4
|
+
version: 1.0.0.beta.1
|
5
5
|
prerelease: 6
|
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-11-
|
12
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -227,13 +227,14 @@ files:
|
|
227
227
|
- lib/jenkins_api_client/node.rb
|
228
228
|
- lib/jenkins_api_client/plugin_manager.rb
|
229
229
|
- lib/jenkins_api_client/system.rb
|
230
|
+
- lib/jenkins_api_client/urihelper.rb
|
230
231
|
- lib/jenkins_api_client/user.rb
|
231
232
|
- lib/jenkins_api_client/version.rb
|
232
233
|
- lib/jenkins_api_client/view.rb
|
233
234
|
- scripts/login_with_irb.rb
|
234
235
|
- spec/func_tests/client_spec.rb
|
235
236
|
- spec/func_tests/job_spec.rb
|
236
|
-
- spec/func_tests/node_spec.rb
|
237
|
+
- spec/func_tests/node_spec.rb.pending
|
237
238
|
- spec/func_tests/plugin_spec.rb
|
238
239
|
- spec/func_tests/spec_helper.rb
|
239
240
|
- spec/func_tests/system_spec.rb
|
@@ -241,6 +242,7 @@ files:
|
|
241
242
|
- spec/func_tests/view_spec.rb
|
242
243
|
- spec/unit_tests/build_queue_spec.rb
|
243
244
|
- spec/unit_tests/client_spec.rb
|
245
|
+
- spec/unit_tests/fake_http_response.rb
|
244
246
|
- spec/unit_tests/fixtures/files/available_plugins.json
|
245
247
|
- spec/unit_tests/fixtures/files/computer_sample.xml
|
246
248
|
- spec/unit_tests/fixtures/files/installed_plugins.json
|