test-drive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +8 -0
- data/README.md +31 -0
- data/README.rdoc +19 -0
- data/Rakefile +65 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bin/test-drive +64 -0
- data/features/step_definitions/test-drive_steps.rb +1 -0
- data/features/support/env.rb +16 -0
- data/features/test-drive.feature +21 -0
- data/lib/test/drive/formatter.rb +35 -0
- data/lib/test/drive/git_helper.rb +24 -0
- data/lib/test/drive/jenkins_client.rb +56 -0
- data/lib/test/drive/version.rb +5 -0
- data/lib/test/drive.rb +9 -0
- data/spec/fixtures/build_details.json +202 -0
- data/spec/git_helper_spec.rb +11 -0
- data/spec/jenkins_client_spec.rb +31 -0
- data/spec/test-drive_spec.rb +4 -0
- data/test-drive.gemspec +32 -0
- metadata +217 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
M2E2M2JhMjM2MzBlMzNkZjQxNDJiZDMzZDhiYzUwMTE5ZDIwMmI5NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGJlNTJjYWU3NWExYzFiMTdhNjdjZmIyYmNjOTA2NjM3NjRhNzI0Zg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODlkMTA0MjhkODQzY2UxNzcxYTE2NmNhOGMyYTllMGQyNGM1NTdhOGI4ZWU1
|
10
|
+
NzQzYWUzNGJmMDU0NTNhODA1NzRmMTgzMWVhZTY3ZDg1MzRjNTg5MDUwYWY5
|
11
|
+
ZWUxMzlmMmU2MjZkYTY2MTAwNjM1YjQyNWQ1ODgwZTcyODQwYTg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzRjNDE0ZGYwMDdhYzdjYWI0YTMyMjhjYTZkMzdkM2Y5Y2U0YzlkYjczMDJk
|
14
|
+
MWQyZTU5MmJhNjMwYmU0MmRlMjYwZGIyM2Y0ODVlYzI3Y2MyYmMwZWM2M2I4
|
15
|
+
MGU5NDI3ZGM5ZTdiNjIxZmRjMjlkOWZiYWJmMmIxYzViNDhmMGI=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Name: test-drive
|
2
|
+
Copyright (c) 2015 Amplify Education
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Test::Drive
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'test-drive'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install test-drive
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/test-drive/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= test-drive - DESCRIBE YOUR GEM
|
2
|
+
|
3
|
+
Author:: YOUR NAME (YOUR EMAIL)
|
4
|
+
Copyright:: Copyright (c) 2015 YOUR NAME
|
5
|
+
|
6
|
+
|
7
|
+
DESCRIBE YOUR GEM HERE
|
8
|
+
|
9
|
+
== Links
|
10
|
+
|
11
|
+
* {Source on Github}[LINK TO GITHUB]
|
12
|
+
* RDoc[LINK TO RDOC.INFO]
|
13
|
+
|
14
|
+
== Install
|
15
|
+
|
16
|
+
== Examples
|
17
|
+
|
18
|
+
== Contributing
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
def dump_load_path
|
2
|
+
puts $LOAD_PATH.join("\n")
|
3
|
+
found = nil
|
4
|
+
$LOAD_PATH.each do |path|
|
5
|
+
if File.exists?(File.join(path,"rspec"))
|
6
|
+
puts "Found rspec in #{path}"
|
7
|
+
if File.exists?(File.join(path,"rspec","core"))
|
8
|
+
puts "Found core"
|
9
|
+
if File.exists?(File.join(path,"rspec","core","rake_task"))
|
10
|
+
puts "Found rake_task"
|
11
|
+
found = path
|
12
|
+
else
|
13
|
+
puts "!! no rake_task"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
puts "!!! no core"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
if found.nil?
|
21
|
+
puts "Didn't find rspec/core/rake_task anywhere"
|
22
|
+
else
|
23
|
+
puts "Found in #{path}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
require 'bundler'
|
27
|
+
require 'rake/clean'
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
rescue LoadError
|
32
|
+
dump_load_path
|
33
|
+
raise
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'cucumber'
|
37
|
+
require 'cucumber/rake/task'
|
38
|
+
gem 'rdoc' # we need the installed RDoc gem, not the system one
|
39
|
+
require 'rdoc/task'
|
40
|
+
|
41
|
+
include Rake::DSL
|
42
|
+
|
43
|
+
Bundler::GemHelper.install_tasks
|
44
|
+
|
45
|
+
|
46
|
+
RSpec::Core::RakeTask.new do |t|
|
47
|
+
# Put spec opts in a file named .rspec in root
|
48
|
+
end
|
49
|
+
|
50
|
+
CUKE_RESULTS = 'results.html'
|
51
|
+
CLEAN << CUKE_RESULTS
|
52
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
53
|
+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
|
54
|
+
t.fork = false
|
55
|
+
end
|
56
|
+
|
57
|
+
Rake::RDocTask.new do |rd|
|
58
|
+
|
59
|
+
rd.main = "README.rdoc"
|
60
|
+
|
61
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
62
|
+
end
|
63
|
+
|
64
|
+
task :default => [:spec,:features]
|
65
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "test/drive"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/test-drive
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'methadone'
|
5
|
+
require 'uuidtools'
|
6
|
+
require 'test/drive'
|
7
|
+
|
8
|
+
class App
|
9
|
+
include Methadone::Main
|
10
|
+
include Methadone::CLILogging
|
11
|
+
include Test::Drive
|
12
|
+
extend Test::Drive::Formatter
|
13
|
+
extend Test::Drive::GitHelper
|
14
|
+
|
15
|
+
|
16
|
+
main do |jenkins_url, user, api_key|
|
17
|
+
|
18
|
+
|
19
|
+
@jenkins_url = jenkins_url
|
20
|
+
@user = user
|
21
|
+
@api_key = api_key
|
22
|
+
@target_job = options['target-job']
|
23
|
+
|
24
|
+
@client = JenkinsClient.new @jenkins_url, @user, @api_key
|
25
|
+
|
26
|
+
create_patch options['file']
|
27
|
+
debug File.readlines File.open options['file']
|
28
|
+
|
29
|
+
tracking_id = UUIDTools::UUID.random_create.to_s
|
30
|
+
id_param = {'name' => 'TRACKING_ID', 'value' => tracking_id}
|
31
|
+
@client.upload_file_to_job(@target_job, tracking_id, options[:file])
|
32
|
+
|
33
|
+
build_number = @client.get_build_number(@target_job, id_param, 120)
|
34
|
+
|
35
|
+
@client.print_output(build_number, @target_job)
|
36
|
+
result = @client.wait_for_job_status(@target_job, build_number)
|
37
|
+
|
38
|
+
print_result(result)
|
39
|
+
git_push if result == 'SUCCESS' || result == 'UNSTABLE'
|
40
|
+
|
41
|
+
delete_patch options['file']
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
arg :jenkins_url, 'URL for the Jenkins server'
|
46
|
+
arg :user, 'Jenkins user ID'
|
47
|
+
arg :api_key, 'Jenkins API token'
|
48
|
+
|
49
|
+
options['file'] = 'patch'
|
50
|
+
on '-f PATCH_FILE', '--file', 'Path to patch file'
|
51
|
+
|
52
|
+
options['target-job'] = 'TestDrive'
|
53
|
+
on '-j TARGET_JOB', '--target-job', 'Jenkins job to be triggered'
|
54
|
+
|
55
|
+
|
56
|
+
description 'A simple command-line tool for running a Jenkins test job before pushing code to the remote repo'
|
57
|
+
|
58
|
+
version Test::Drive::VERSION
|
59
|
+
|
60
|
+
use_log_level_option :toggle_debug_on_signal => 'USR1'
|
61
|
+
|
62
|
+
go!
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
# Put your step definitions here
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
require 'methadone/cucumber'
|
3
|
+
|
4
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
5
|
+
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
6
|
+
|
7
|
+
Before do
|
8
|
+
# Using "announce" causes massive warnings on 1.9.2
|
9
|
+
@puts = true
|
10
|
+
@original_rubylib = ENV['RUBYLIB']
|
11
|
+
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
After do
|
15
|
+
ENV['RUBYLIB'] = @original_rubylib
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: My bootstrapped app kinda works
|
2
|
+
In order to get going on coding my awesome app
|
3
|
+
I want to have aruba and cucumber setup
|
4
|
+
So I don't have to do it myself
|
5
|
+
|
6
|
+
Scenario: App prints help
|
7
|
+
When I get help for "test-drive"
|
8
|
+
Then the exit status should be 0
|
9
|
+
And the banner should be present
|
10
|
+
And there should be a one line summary of what the app does
|
11
|
+
And the banner should document that this app takes options
|
12
|
+
And the following options should be documented:
|
13
|
+
|--version |
|
14
|
+
|--target-job |
|
15
|
+
|--file |
|
16
|
+
|--log-level |
|
17
|
+
|
18
|
+
And the banner should document that this app's arguments are:
|
19
|
+
|jenkins_url|which_is_required|
|
20
|
+
|user |which_is_required|
|
21
|
+
|api_key |which_is_required|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'artii'
|
2
|
+
require 'rainbow'
|
3
|
+
|
4
|
+
module Test
|
5
|
+
module Drive
|
6
|
+
module Formatter
|
7
|
+
COLORS = [
|
8
|
+
:red,
|
9
|
+
:green,
|
10
|
+
:yellow,
|
11
|
+
:blue,
|
12
|
+
:magenta,
|
13
|
+
:cyan,
|
14
|
+
:white
|
15
|
+
]
|
16
|
+
|
17
|
+
def print_result(result)
|
18
|
+
if result == 'SUCCESS' || result == 'UNSTABLE'
|
19
|
+
puts rainbowize '*********************************************************************************************************************************************'
|
20
|
+
puts rainbowize Artii::Base.new(font: 'slant').asciify('T E S T - D R I V E N .')
|
21
|
+
puts rainbowize '*********************************************************************************************************************************************'
|
22
|
+
else
|
23
|
+
puts Rainbow(Artii::Base.new.asciify result).red
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def rainbowize(string)
|
29
|
+
rainbow_string = ''
|
30
|
+
string.length.times { |i| rainbow_string << Rainbow(string[i]).color(COLORS[i % COLORS.length]) }
|
31
|
+
rainbow_string
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
|
3
|
+
module Test
|
4
|
+
module Drive
|
5
|
+
module GitHelper
|
6
|
+
include Methadone::SH
|
7
|
+
|
8
|
+
def create_patch filename
|
9
|
+
res = sh "git pull --rebase && git diff --binary origin > #{filename}"
|
10
|
+
unless res == 0
|
11
|
+
raise IOError.new 'Failed to create patch'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete_patch filename
|
16
|
+
`rm #{filename}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def git_push
|
20
|
+
`git push origin master`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'jenkins_api_client'
|
2
|
+
|
3
|
+
module Test
|
4
|
+
module Drive
|
5
|
+
class JenkinsClient
|
6
|
+
attr_accessor :client
|
7
|
+
|
8
|
+
def initialize jenkins_url, user, api_key
|
9
|
+
@jenkins_url = jenkins_url
|
10
|
+
@user = user
|
11
|
+
@api_key = api_key
|
12
|
+
|
13
|
+
@client = JenkinsApi::Client.new :server_url => jenkins_url,
|
14
|
+
:username => user,
|
15
|
+
:password => api_key,
|
16
|
+
:log_level => 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_build_number(target_job, tracking_id, timeout_in_seconds, sleep_interval=10)
|
20
|
+
(timeout_in_seconds/10).times do
|
21
|
+
sleep sleep_interval
|
22
|
+
build_details = @client.job.get_build_details(target_job, 0)
|
23
|
+
if build_details['actions'][0]['parameters'].include?(tracking_id)
|
24
|
+
return build_details['number']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
raise 'Build number not found within the time specified!'
|
28
|
+
end
|
29
|
+
|
30
|
+
def print_output(build_number, target_job)
|
31
|
+
offset = 0
|
32
|
+
loop do
|
33
|
+
job_output = @client.job.get_console_output(target_job, build_number, offset)
|
34
|
+
|
35
|
+
print job_output['output']
|
36
|
+
break unless job_output['more']
|
37
|
+
|
38
|
+
offset = job_output['size']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def wait_for_job_status(target_job, build_number)
|
43
|
+
loop do
|
44
|
+
details = @client.job.get_build_details(target_job, build_number)
|
45
|
+
return details['result'] if details['result']
|
46
|
+
sleep 5
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def upload_file_to_job(target_job, tracking_id, path_to_file)
|
51
|
+
res = `curl -i #{@jenkins_url}/job/#{target_job}/build -F file0=@#{path_to_file} -F json='{"parameter": [{"name":"#{path_to_file}", "file":"file0"}, {"name":"TRACKING_ID", "value":"#{tracking_id}"}]}' --user '#{@user}':'#{@api_key}'`
|
52
|
+
raise "Failed to send patch to Jenkins: \n#{res}" unless $? == 0
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/test/drive.rb
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
{
|
2
|
+
"actions" : [
|
3
|
+
{
|
4
|
+
"parameters" : [
|
5
|
+
{
|
6
|
+
"name" : "patch"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"name" : "TRACKING_ID",
|
10
|
+
"value" : "ab301010-0368-4440-88d4-4da91641d46f"
|
11
|
+
}
|
12
|
+
]
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"causes" : [
|
16
|
+
{
|
17
|
+
"shortDescription" : "Started by user Test User",
|
18
|
+
"userId" : "user@test.com",
|
19
|
+
"userName" : "Test User"
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
{
|
24
|
+
|
25
|
+
},
|
26
|
+
{
|
27
|
+
|
28
|
+
},
|
29
|
+
{
|
30
|
+
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"buildsByBranchName" : {
|
34
|
+
"origin/master" : {
|
35
|
+
"buildNumber" : 59,
|
36
|
+
"buildResult" : null,
|
37
|
+
"marked" : {
|
38
|
+
"SHA1" : "fcd766bc5b0339cd54f6535bc186f7fcfefdc0cc",
|
39
|
+
"branch" : [
|
40
|
+
{
|
41
|
+
"SHA1" : "fcd766bc5b0339cd54f6535bc186f7fcfefdc0cc",
|
42
|
+
"name" : "origin/master"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
},
|
46
|
+
"revision" : {
|
47
|
+
"SHA1" : "fcd766bc5b0339cd54f6535bc186f7fcfefdc0cc",
|
48
|
+
"branch" : [
|
49
|
+
{
|
50
|
+
"SHA1" : "fcd766bc5b0339cd54f6535bc186f7fcfefdc0cc",
|
51
|
+
"name" : "origin/master"
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
},
|
56
|
+
"refs/remotes/origin/master" : {
|
57
|
+
"buildNumber" : 60,
|
58
|
+
"buildResult" : null,
|
59
|
+
"marked" : {
|
60
|
+
"SHA1" : "f51b1fc60fed0e3260b0c6c375a8ff7a84c81fa3",
|
61
|
+
"branch" : [
|
62
|
+
{
|
63
|
+
"SHA1" : "f51b1fc60fed0e3260b0c6c375a8ff7a84c81fa3",
|
64
|
+
"name" : "refs/remotes/origin/master"
|
65
|
+
}
|
66
|
+
]
|
67
|
+
},
|
68
|
+
"revision" : {
|
69
|
+
"SHA1" : "f51b1fc60fed0e3260b0c6c375a8ff7a84c81fa3",
|
70
|
+
"branch" : [
|
71
|
+
{
|
72
|
+
"SHA1" : "f51b1fc60fed0e3260b0c6c375a8ff7a84c81fa3",
|
73
|
+
"name" : "refs/remotes/origin/master"
|
74
|
+
}
|
75
|
+
]
|
76
|
+
}
|
77
|
+
}
|
78
|
+
},
|
79
|
+
"lastBuiltRevision" : {
|
80
|
+
"SHA1" : "f51b1fc60fed0e3260b0c6c375a8ff7a84c81fa3",
|
81
|
+
"branch" : [
|
82
|
+
{
|
83
|
+
"SHA1" : "f51b1fc60fed0e3260b0c6c375a8ff7a84c81fa3",
|
84
|
+
"name" : "refs/remotes/origin/master"
|
85
|
+
}
|
86
|
+
]
|
87
|
+
},
|
88
|
+
"remoteUrls" : [
|
89
|
+
"ssh://git@github.com:test_user/test_repo.git"
|
90
|
+
],
|
91
|
+
"scmName" : ""
|
92
|
+
},
|
93
|
+
{
|
94
|
+
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"buildsByBranchName" : {
|
98
|
+
"origin/master" : {
|
99
|
+
"buildNumber" : 60,
|
100
|
+
"buildResult" : null,
|
101
|
+
"marked" : {
|
102
|
+
"SHA1" : "5161254bc5872410ce7443e4197bd875b83463ee",
|
103
|
+
"branch" : [
|
104
|
+
{
|
105
|
+
"SHA1" : "5161254bc5872410ce7443e4197bd875b83463ee",
|
106
|
+
"name" : "origin/master"
|
107
|
+
}
|
108
|
+
]
|
109
|
+
},
|
110
|
+
"revision" : {
|
111
|
+
"SHA1" : "5161254bc5872410ce7443e4197bd875b83463ee",
|
112
|
+
"branch" : [
|
113
|
+
{
|
114
|
+
"SHA1" : "5161254bc5872410ce7443e4197bd875b83463ee",
|
115
|
+
"name" : "origin/master"
|
116
|
+
}
|
117
|
+
]
|
118
|
+
}
|
119
|
+
}
|
120
|
+
},
|
121
|
+
"lastBuiltRevision" : {
|
122
|
+
"SHA1" : "5161254bc5872410ce7443e4197bd875b83463ee",
|
123
|
+
"branch" : [
|
124
|
+
{
|
125
|
+
"SHA1" : "5161254bc5872410ce7443e4197bd875b83463ee",
|
126
|
+
"name" : "origin/master"
|
127
|
+
}
|
128
|
+
]
|
129
|
+
},
|
130
|
+
"remoteUrls" : [
|
131
|
+
"ssh://git@github.com:test_user/test_repo.git"
|
132
|
+
],
|
133
|
+
"scmName" : ""
|
134
|
+
},
|
135
|
+
{
|
136
|
+
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"failCount" : 0,
|
140
|
+
"skipCount" : 0,
|
141
|
+
"totalCount" : 26,
|
142
|
+
"urlName" : "testReport"
|
143
|
+
}
|
144
|
+
],
|
145
|
+
"artifacts" : [
|
146
|
+
{
|
147
|
+
"displayPath" : null,
|
148
|
+
"fileName" : "test_results.log",
|
149
|
+
"relativePath" : "test-repo-9999/logs/test_results.log"
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"displayPath" : null,
|
153
|
+
"fileName" : "newrelic_agent.log",
|
154
|
+
"relativePath" : "test-repo-9999/newrelic_agent.log"
|
155
|
+
}
|
156
|
+
],
|
157
|
+
"building" : false,
|
158
|
+
"description" : null,
|
159
|
+
"duration" : 401028,
|
160
|
+
"estimatedDuration" : 140653,
|
161
|
+
"executor" : null,
|
162
|
+
"fullDisplayName" : "TestDrive #60",
|
163
|
+
"id" : "2015-02-12_22-23-35",
|
164
|
+
"keepLog" : false,
|
165
|
+
"number" : 60,
|
166
|
+
"result" : "SUCCESS",
|
167
|
+
"timestamp" : 1423779815000,
|
168
|
+
"url" : "https://jenkins.ampaxs.com/job/TestDrive/60/",
|
169
|
+
"builtOn" : "Barcelona",
|
170
|
+
"changeSet" : {
|
171
|
+
"items" : [
|
172
|
+
{
|
173
|
+
"affectedPaths" : [
|
174
|
+
"ci/deployment_smoke_tests.sh"
|
175
|
+
],
|
176
|
+
"commitId" : "87a38d6a98090ff6f6d52d04699b16142f7752dc",
|
177
|
+
"timestamp" : 1423759012000,
|
178
|
+
"author" : {
|
179
|
+
"absoluteUrl" : "https://jenkins.test.com/user/user@test.com",
|
180
|
+
"fullName" : "Test User"
|
181
|
+
},
|
182
|
+
"comment" : "test message\n",
|
183
|
+
"date" : "2015-02-12T16:36:52+0000 -0500",
|
184
|
+
"id" : "87a38d6a98090ff6f6d52d04699b16142f7752dc",
|
185
|
+
"msg" : "test message",
|
186
|
+
"paths" : [
|
187
|
+
{
|
188
|
+
"editType" : "edit",
|
189
|
+
"file" : "lib/test_file.sh"
|
190
|
+
}
|
191
|
+
]
|
192
|
+
}
|
193
|
+
],
|
194
|
+
"kind" : "git"
|
195
|
+
},
|
196
|
+
"culprits" : [
|
197
|
+
{
|
198
|
+
"absoluteUrl" : "https://jenkins.test.com/user/user@test.com",
|
199
|
+
"fullName" : "Test User"
|
200
|
+
}
|
201
|
+
]
|
202
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test/drive'
|
2
|
+
include Test::Drive::GitHelper
|
3
|
+
|
4
|
+
describe 'GitHelper' do
|
5
|
+
describe '#create_patch' do
|
6
|
+
it 'raises an error when patch is not generated' do
|
7
|
+
expect(self).to receive(:sh).and_return(64)
|
8
|
+
expect { create_patch "temp-patch" }.to raise_error IOError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test/drive'
|
2
|
+
require 'json'
|
3
|
+
include Test::Drive
|
4
|
+
|
5
|
+
describe 'JenkinsClient' do
|
6
|
+
let(:test_client) {
|
7
|
+
test_client = JenkinsClient.new '0.0.0.0', 'user', 'api_key'
|
8
|
+
test_client.client = instance_double JenkinsApi::Client, job: double(JenkinsApi::Client::Job)
|
9
|
+
allow(test_client.client.job).to receive(:get_build_details).and_return(JSON.parse(File.read 'spec/fixtures/build_details.json'))
|
10
|
+
test_client
|
11
|
+
}
|
12
|
+
|
13
|
+
describe '#new' do
|
14
|
+
it 'creates a new Jenkins client' do
|
15
|
+
expect(test_client).to be_an_instance_of JenkinsClient
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#get_build_number' do
|
20
|
+
it 'returns build number' do
|
21
|
+
id_hash = {'name' => 'TRACKING_ID', 'value' => 'ab301010-0368-4440-88d4-4da91641d46f'}
|
22
|
+
build_number = test_client.get_build_number 'TestDrive', id_hash, 10, 0
|
23
|
+
expect(build_number).to eq 60
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'raises an error if job is not found' do
|
27
|
+
id_hash = {'name' => 'TRACKING_ID', 'value' => 'xxxxxxxx'}
|
28
|
+
expect { test_client.get_build_number 'TestDrive', id_hash, 10, 0 }.to raise_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test-drive.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'test/drive/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "test-drive"
|
8
|
+
spec.version = Test::Drive::VERSION
|
9
|
+
spec.authors = ["Natasha Badillo"]
|
10
|
+
spec.email = ["nbadillo@amplify.com"]
|
11
|
+
spec.summary = "Test-Drive for Jenkins"
|
12
|
+
spec.description = "A simple command-line tool for running a Jenkins test job before pushing code to the remote repo"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "mit"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = ['test-drive']
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency('methadone', '~> 1.8.0')
|
22
|
+
spec.add_runtime_dependency "jenkins_api_client"
|
23
|
+
spec.add_runtime_dependency "uuidtools"
|
24
|
+
spec.add_runtime_dependency "artii"
|
25
|
+
spec.add_runtime_dependency "rainbow"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency('rdoc')
|
30
|
+
spec.add_development_dependency('aruba')
|
31
|
+
spec.add_development_dependency('rspec')
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test-drive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Natasha Badillo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: methadone
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jenkins_api_client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: uuidtools
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: artii
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rainbow
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rdoc
|
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'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: aruba
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: A simple command-line tool for running a Jenkins test job before pushing
|
154
|
+
code to the remote repo
|
155
|
+
email:
|
156
|
+
- nbadillo@amplify.com
|
157
|
+
executables:
|
158
|
+
- test-drive
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- .gitignore
|
163
|
+
- .rspec
|
164
|
+
- .travis.yml
|
165
|
+
- Gemfile
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.md
|
168
|
+
- README.rdoc
|
169
|
+
- Rakefile
|
170
|
+
- bin/console
|
171
|
+
- bin/setup
|
172
|
+
- bin/test-drive
|
173
|
+
- features/step_definitions/test-drive_steps.rb
|
174
|
+
- features/support/env.rb
|
175
|
+
- features/test-drive.feature
|
176
|
+
- lib/test/drive.rb
|
177
|
+
- lib/test/drive/formatter.rb
|
178
|
+
- lib/test/drive/git_helper.rb
|
179
|
+
- lib/test/drive/jenkins_client.rb
|
180
|
+
- lib/test/drive/version.rb
|
181
|
+
- spec/fixtures/build_details.json
|
182
|
+
- spec/git_helper_spec.rb
|
183
|
+
- spec/jenkins_client_spec.rb
|
184
|
+
- spec/test-drive_spec.rb
|
185
|
+
- test-drive.gemspec
|
186
|
+
homepage: ''
|
187
|
+
licenses:
|
188
|
+
- mit
|
189
|
+
metadata: {}
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ! '>='
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ! '>='
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubyforge_project:
|
206
|
+
rubygems_version: 2.4.6
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: Test-Drive for Jenkins
|
210
|
+
test_files:
|
211
|
+
- features/step_definitions/test-drive_steps.rb
|
212
|
+
- features/support/env.rb
|
213
|
+
- features/test-drive.feature
|
214
|
+
- spec/fixtures/build_details.json
|
215
|
+
- spec/git_helper_spec.rb
|
216
|
+
- spec/jenkins_client_spec.rb
|
217
|
+
- spec/test-drive_spec.rb
|