diff --git a/Gemfile b/Gemfile index 85cf5d16..add18133 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,8 @@ ruby '1.9.3' rescue nil source :rubygems gemspec +gem 'travis-core', github: 'travis-ci/travis-core', branch: 'sf-archive-logs' gem 'travis-support', github: 'travis-ci/travis-support' -gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' gem 'sinatra' #github: 'sinatra/sinatra' gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil diff --git a/Gemfile.lock b/Gemfile.lock index 63849b5c..b1b903d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: ba4e4a83b473393539728a3aeb8e3499ab1ef1bc + revision: 4637ea48abe8fb0976d8e0bbf997ea2578a3ca62 specs: travis-core (0.0.1) actionmailer (~> 3.2.11) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 277520fe..e57abdab 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -111,16 +111,19 @@ module Travis::Api Travis::Amqp.config = Travis.config.amqp Travis::Database.connect Travis::Features.start - Sidekiq.configure_client do |config| - config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) + + unless Travis.env == 'test' + Sidekiq.configure_client do |config| + config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) + end + + Raven.configure do |config| + config.dsn = Travis.config.sentry.dsn + end if Travis.config.sentry + + Travis::LogSubscriber::ActiveRecordMetrics.attach + Travis::Notification.setup end - - Raven.configure do |config| - config.dsn = Travis.config.sentry.dsn - end if Travis.config.sentry - - Travis::LogSubscriber::ActiveRecordMetrics.attach - Travis::Notification.setup end def self.load_endpoints diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index de02c291..963e2c59 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -10,6 +10,10 @@ class Travis::Api::App get '/:id' do respond_with service(:find_job, params) end + + get '/:job_id/log' do + respond_with service(:find_artifact, params) + end end end end diff --git a/spec/integration/v1/workers_spec.rb b/spec/integration/v1/workers_spec.rb index 34edd9e3..22bb8683 100644 --- a/spec/integration/v1/workers_spec.rb +++ b/spec/integration/v1/workers_spec.rb @@ -1,22 +1,13 @@ require 'spec_helper' describe 'Workers' do - before(:each) do - Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11)) - @workers = [ - Worker.new('1', full_name: 'ruby1:ruby1.travis-ci.org'), - Worker.new('2', full_name: 'ruby2:ruby1.travis-ci.org') - ] - end - - let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } - - attr_reader :workers + let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] } + let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } it 'GET /workers' do Worker.stubs(all: @workers) response = get '/workers', {}, headers - response.should deliver_json_for(@workers, version: 'v1', type: 'workers') + response.should deliver_json_for(Worker.all, version: 'v1', type: 'workers') end end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 4da7acae..58e370ef 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -13,8 +13,14 @@ describe 'Jobs' do response.should deliver_json_for(Job.queued('builds.common'), version: 'v2') end - it '/jobs/:job_id' do + it '/jobs/:id' do response = get "/jobs/#{job.id}", {}, headers response.should deliver_json_for(job, version: 'v2') end + + it '/jobs/:id' do + job.log.update_attributes!(content: 'the log') + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should deliver_as_txt('the log', version: 'v2') + end end diff --git a/spec/integration/v2/workers_spec.rb b/spec/integration/v2/workers_spec.rb index 35f03e36..047dff94 100644 --- a/spec/integration/v2/workers_spec.rb +++ b/spec/integration/v2/workers_spec.rb @@ -1,22 +1,13 @@ require 'spec_helper' describe 'Workers' do - before(:each) do - Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11)) - @workers = [ - Worker.new('1', full_name: 'ruby1:ruby1.travis-ci.org'), - Worker.new('2', full_name: 'ruby2:ruby1.travis-ci.org') - ] - end - - let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } - - attr_reader :workers + let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] } + let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } it 'GET /workers' do Worker.stubs(all: @workers) response = get '/workers', {}, headers - response.should deliver_json_for(@workers, version: 'v2', type: 'workers') + response.should deliver_json_for(Worker.all, version: 'v2', type: 'workers') end end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 53cc97aa..3152322a 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -24,6 +24,26 @@ RSpec::Matchers.define :deliver_json_for do |resource, options = {}| end end +RSpec::Matchers.define :deliver_as_txt do |expected, options = {}| + match do |response| + if response.status == 200 + failure_message_for_should do + "expected\n\n#{actual}\n\nto equal\n\n#{expected}" + end + response.body.to_s == expected + else + failure_message_for_should do + "expected the request to be successful (200) but was #{response.status}" + end + false + end + end + + def parse(body) + MultiJson.decode(body) + end +end + RSpec::Matchers.define :deliver_result_image_for do |name| match do |response| header = response.headers['content-disposition']