From 211b1b27d5777f780648f50a09aa40b4407b3ed8 Mon Sep 17 00:00:00 2001 From: Ivan Vanderbyl Date: Tue, 17 Jan 2012 11:23:17 +1030 Subject: [PATCH 1/6] Added TestPilot Github Service --- services/test_pilot.rb | 19 ++++++++ test/test_pilot_test.rb | 99 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 services/test_pilot.rb create mode 100644 test/test_pilot_test.rb diff --git a/services/test_pilot.rb b/services/test_pilot.rb new file mode 100644 index 000000000..66ee9e5fc --- /dev/null +++ b/services/test_pilot.rb @@ -0,0 +1,19 @@ +class Service::TestPilot < Service + string :token + + def receive_push + http.ssl[:verify] = false + http_post test_pilot_url, {:payload => payload.to_json}.merge(authentication_token) + end + + def test_pilot_url + "http://testpilot.me/callbacks/github" + end + + protected + + def authentication_param + {:token => token} + end +end + diff --git a/test/test_pilot_test.rb b/test/test_pilot_test.rb new file mode 100644 index 000000000..be6efdefe --- /dev/null +++ b/test/test_pilot_test.rb @@ -0,0 +1,99 @@ +require File.expand_path('../helper', __FILE__) + +class TestPilotTest < Service::TestCase + def setup + @stubs = Faraday::Adapter::Test::Stubs.new + @svc = service(data, payload) + end + + def test_reads_token_from_data + assert_equal "pHDyK9RkyHaBdJqqEcsN", @svc.token + end + + def test_constructs_post_receive_url + assert_equal 'http://testpilot.me/callbacks/github', + @svc.test_pilot_url + end + + def test_posts_payload + @stubs.post '/callbacks/github' do |env| + assert_equal env[:body]['token'], token + assert_equal payload, JSON.parse(Rack::Utils.parse_query(env[:body])['payload']) + end + @svc.receive_push + end + + def test_strips_whitespace_from_form_values + data = { + 'token' => 'pHDyK9RkyHaBdJqqEcsN ' + } + + svc = service(data, payload) + assert_equal 'pHDyK9RkyHaBdJqqEcsN', svc.token + end + + def service(*args) + super Service::Travis, *args + end + + def data + { + 'token' => 'pHDyK9RkyHaBdJqqEcsN' + } + end + + def payload2 + { + "after" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", + "ref" => "refs/heads/master", + "before" => "4c8124ffcf4039d292442eeccabdeca5af5c5017", + "compare" => "http://github.com/mojombo/grit/compare/4c8124ffcf4039d292442eeccabdeca5af5c5017...a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", + "forced" => false, + "created" => false, + "deleted" => false, + + "repository" => { + "name" => "grit", + "url" => "http://github.com/mojombo/grit", + "owner" => { "name" => "mojombo", "email" => "tom@mojombo.com" } + }, + + "commits" => [ + { + "distinct" => true, + "removed" => [], + "message" => "[#WEB-249 status:31 resolution:1] stub git call for Grit#heads test", + "added" => [], + "timestamp" => "2007-10-10T00:11:02-07:00", + "modified" => ["lib/grit/grit.rb", "test/helper.rb", "test/test_grit.rb"], + "url" => "http://github.com/mojombo/grit/commit/06f63b43050935962f84fe54473a7c5de7977325", + "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, + "id" => "06f63b43050935962f84fe54473a7c5de7977325" + }, + { + "distinct" => true, + "removed" => [], + "message" => "clean up heads test", + "added" => [], + "timestamp" => "2007-10-10T00:18:20-07:00", + "modified" => ["test/test_grit.rb"], + "url" => "http://github.com/mojombo/grit/commit/5057e76a11abd02e83b7d3d3171c4b68d9c88480", + "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, + "id" => "5057e76a11abd02e83b7d3d3171c4b68d9c88480" + }, + { + "distinct" => true, + "removed" => [], + "message" => "add more comments throughout", + "added" => [], + "timestamp" => "2007-10-10T00:50:39-07:00", + "modified" => ["lib/grit.rb", "lib/grit/commit.rb", "lib/grit/grit.rb"], + "url" => "http://github.com/mojombo/grit/commit/a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", + "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, + "id" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425" + } + ] + } + end +end + From d28e4fdbcf31d258936c626c1e08562f94ae0ac9 Mon Sep 17 00:00:00 2001 From: Ivan Vanderbyl Date: Tue, 17 Jan 2012 11:40:27 +1030 Subject: [PATCH 2/6] Fixed TestPilot service tests --- services/test_pilot.rb | 6 +++++- test/test_pilot_test.rb | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/test_pilot.rb b/services/test_pilot.rb index 66ee9e5fc..b4ca3f622 100644 --- a/services/test_pilot.rb +++ b/services/test_pilot.rb @@ -3,13 +3,17 @@ class Service::TestPilot < Service def receive_push http.ssl[:verify] = false - http_post test_pilot_url, {:payload => payload.to_json}.merge(authentication_token) + http_post test_pilot_url, {:payload => payload.to_json}.merge(authentication_param) end def test_pilot_url "http://testpilot.me/callbacks/github" end + def token + data['token'].strip + end + protected def authentication_param diff --git a/test/test_pilot_test.rb b/test/test_pilot_test.rb index be6efdefe..c84db436d 100644 --- a/test/test_pilot_test.rb +++ b/test/test_pilot_test.rb @@ -17,7 +17,7 @@ def test_constructs_post_receive_url def test_posts_payload @stubs.post '/callbacks/github' do |env| - assert_equal env[:body]['token'], token + assert_equal Rack::Utils.parse_query(env[:body])['token'], @svc.token assert_equal payload, JSON.parse(Rack::Utils.parse_query(env[:body])['payload']) end @svc.receive_push @@ -33,7 +33,7 @@ def test_strips_whitespace_from_form_values end def service(*args) - super Service::Travis, *args + super Service::TestPilot, *args end def data From dbfb2667a8326f300ac6b283d24b12cabbd939e1 Mon Sep 17 00:00:00 2001 From: Ivan Vanderbyl Date: Tue, 17 Jan 2012 12:19:13 +1030 Subject: [PATCH 3/6] Added TestPilot docs --- docs/test_pilot | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/test_pilot diff --git a/docs/test_pilot b/docs/test_pilot new file mode 100644 index 000000000..16870b901 --- /dev/null +++ b/docs/test_pilot @@ -0,0 +1,27 @@ +TestPilot CI +====== + +TestPilot CI is a fully managed distributed Continuous Integration and Deployment Service +for Ruby, Node.js, Clojure, Java, Python, and Scala applications. + +Install Notes +------------- + + 1. Create an account at http://testpilot.me + 2. Authorize TestPilot to connect with your Github account. + 3. After your repositories have been synced, activate the repository you want to test. + TestPilot will automatically add necessary token above for your project, alternatively you can + find the token under your account page at http://testpilot.me/my/account + + 4. Check the "Active" checkbox and click "Update Settings". + 5. Push some changes to this repository and TestPilot will automatically start your build process. + 6. You should receive an email from TestPilot once the build has completed + +For more details about TestPilot, go to http://testpilot.me + +Developer Notes +--------------- + +data + - token + From 15b11b5437169afecec6ff6b4a78400accc92026 Mon Sep 17 00:00:00 2001 From: Ivan Vanderbyl Date: Tue, 17 Jan 2012 17:19:52 +1030 Subject: [PATCH 4/6] Added params correctly --- services/test_pilot.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/test_pilot.rb b/services/test_pilot.rb index b4ca3f622..2fd4b4d19 100644 --- a/services/test_pilot.rb +++ b/services/test_pilot.rb @@ -3,7 +3,9 @@ class Service::TestPilot < Service def receive_push http.ssl[:verify] = false - http_post test_pilot_url, {:payload => payload.to_json}.merge(authentication_param) + http.params ||= {} + http.params.merge!(authentication_param) + http_post test_pilot_url, :payload => payload.to_json end def test_pilot_url @@ -11,12 +13,16 @@ def test_pilot_url end def token - data['token'].strip + data['token'].to_s.strip end protected def authentication_param + if token.empty? + raise_config_error "Needs a token" + end + {:token => token} end end From 581368163426a01722896decc6f771a31ba748b2 Mon Sep 17 00:00:00 2001 From: Ivan Vanderbyl Date: Sat, 21 Jan 2012 14:27:27 +1100 Subject: [PATCH 5/6] Fixed TestPilot tests --- services/test_pilot.rb | 3 -- test/test_pilot_test.rb | 90 ++++++++++------------------------------- 2 files changed, 22 insertions(+), 71 deletions(-) diff --git a/services/test_pilot.rb b/services/test_pilot.rb index 2fd4b4d19..d145e8a86 100644 --- a/services/test_pilot.rb +++ b/services/test_pilot.rb @@ -3,7 +3,6 @@ class Service::TestPilot < Service def receive_push http.ssl[:verify] = false - http.params ||= {} http.params.merge!(authentication_param) http_post test_pilot_url, :payload => payload.to_json end @@ -16,8 +15,6 @@ def token data['token'].to_s.strip end - protected - def authentication_param if token.empty? raise_config_error "Needs a token" diff --git a/test/test_pilot_test.rb b/test/test_pilot_test.rb index c84db436d..32c468a88 100644 --- a/test/test_pilot_test.rb +++ b/test/test_pilot_test.rb @@ -6,8 +6,18 @@ def setup @svc = service(data, payload) end + def service(*args) + super Service::TestPilot, *args + end + + def data + { + 'token' => 'pHDyK9RkyHaBdJqqEcs' + } + end + def test_reads_token_from_data - assert_equal "pHDyK9RkyHaBdJqqEcsN", @svc.token + assert_equal "pHDyK9RkyHaBdJqqEcs", @svc.token end def test_constructs_post_receive_url @@ -17,83 +27,27 @@ def test_constructs_post_receive_url def test_posts_payload @stubs.post '/callbacks/github' do |env| - assert_equal Rack::Utils.parse_query(env[:body])['token'], @svc.token + assert_equal env[:params]['token'], @svc.token assert_equal payload, JSON.parse(Rack::Utils.parse_query(env[:body])['payload']) end @svc.receive_push end - def test_strips_whitespace_from_form_values - data = { - 'token' => 'pHDyK9RkyHaBdJqqEcsN ' - } - + def test_it_raises_an_error_if_no_token_is_supplied + data = {'token' => ''} svc = service(data, payload) - assert_equal 'pHDyK9RkyHaBdJqqEcsN', svc.token - end - - def service(*args) - super Service::TestPilot, *args + assert_raises Service::ConfigurationError do + svc.receive_push + end end - def data - { - 'token' => 'pHDyK9RkyHaBdJqqEcsN' + def test_strips_whitespace_from_form_values + data = { + 'token' => 'pHDyK9RkyHaBdJqqEcs ' } - end - - def payload2 - { - "after" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", - "ref" => "refs/heads/master", - "before" => "4c8124ffcf4039d292442eeccabdeca5af5c5017", - "compare" => "http://github.com/mojombo/grit/compare/4c8124ffcf4039d292442eeccabdeca5af5c5017...a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", - "forced" => false, - "created" => false, - "deleted" => false, - "repository" => { - "name" => "grit", - "url" => "http://github.com/mojombo/grit", - "owner" => { "name" => "mojombo", "email" => "tom@mojombo.com" } - }, - - "commits" => [ - { - "distinct" => true, - "removed" => [], - "message" => "[#WEB-249 status:31 resolution:1] stub git call for Grit#heads test", - "added" => [], - "timestamp" => "2007-10-10T00:11:02-07:00", - "modified" => ["lib/grit/grit.rb", "test/helper.rb", "test/test_grit.rb"], - "url" => "http://github.com/mojombo/grit/commit/06f63b43050935962f84fe54473a7c5de7977325", - "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, - "id" => "06f63b43050935962f84fe54473a7c5de7977325" - }, - { - "distinct" => true, - "removed" => [], - "message" => "clean up heads test", - "added" => [], - "timestamp" => "2007-10-10T00:18:20-07:00", - "modified" => ["test/test_grit.rb"], - "url" => "http://github.com/mojombo/grit/commit/5057e76a11abd02e83b7d3d3171c4b68d9c88480", - "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, - "id" => "5057e76a11abd02e83b7d3d3171c4b68d9c88480" - }, - { - "distinct" => true, - "removed" => [], - "message" => "add more comments throughout", - "added" => [], - "timestamp" => "2007-10-10T00:50:39-07:00", - "modified" => ["lib/grit.rb", "lib/grit/commit.rb", "lib/grit/grit.rb"], - "url" => "http://github.com/mojombo/grit/commit/a47fd41f3aa4610ea527dcc1669dfdb9c15c5425", - "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" }, - "id" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425" - } - ] - } + svc = service(data, payload) + assert_equal 'pHDyK9RkyHaBdJqqEcs', svc.token end end From edfe6a85207e03a1ee3233709ba12bb69b142813 Mon Sep 17 00:00:00 2001 From: Ivan Vanderbyl Date: Sat, 21 Jan 2012 14:31:15 +1100 Subject: [PATCH 6/6] Replaced token with TOKEN --- test/test_pilot_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_pilot_test.rb b/test/test_pilot_test.rb index 32c468a88..00b4f4153 100644 --- a/test/test_pilot_test.rb +++ b/test/test_pilot_test.rb @@ -12,12 +12,12 @@ def service(*args) def data { - 'token' => 'pHDyK9RkyHaBdJqqEcs' + 'token' => 'TOKEN' } end def test_reads_token_from_data - assert_equal "pHDyK9RkyHaBdJqqEcs", @svc.token + assert_equal "TOKEN", @svc.token end def test_constructs_post_receive_url @@ -43,11 +43,11 @@ def test_it_raises_an_error_if_no_token_is_supplied def test_strips_whitespace_from_form_values data = { - 'token' => 'pHDyK9RkyHaBdJqqEcs ' + 'token' => 'TOKEN ' } svc = service(data, payload) - assert_equal 'pHDyK9RkyHaBdJqqEcs', svc.token + assert_equal 'TOKEN', svc.token end end