expose logs on /job/:id/log.txt

This commit is contained in:
Sven Fuchs 2013-01-24 00:06:42 +01:00
parent f2d768080f
commit d441336573
8 changed files with 51 additions and 36 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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']