add webmock, update spec

This commit is contained in:
carlad 2016-08-05 16:31:53 +02:00
parent a7128fa1b3
commit c8f94e90ed
5 changed files with 32 additions and 13 deletions

View File

@ -47,6 +47,7 @@ group :test do
gem 'mocha', '~> 0.12'
gem 'database_cleaner', '~> 0.8.0'
gem 'timecop', '~> 0.8.0'
gem 'webmock'
end
group :development do

View File

@ -146,6 +146,8 @@ GEM
activerecord (~> 3.2.0, >= 3.2.9)
concurrent-ruby (1.0.2)
connection_pool (2.2.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
customerio (1.0.0)
multi_json (~> 1.0)
dalli (2.7.6)
@ -189,6 +191,7 @@ GEM
multi_json (~> 1.11)
os (~> 0.9)
signet (~> 0.7)
hashdiff (0.3.0)
hashr (0.0.22)
hike (1.2.3)
hitimes (1.2.4)
@ -288,6 +291,7 @@ GEM
rspec-expectations (>= 2.99.0.beta1)
rspec-mocks (2.99.4)
ruby_dep (1.3.1)
safe_yaml (1.0.4)
sentry-raven (1.0.0)
faraday (>= 0.7.6)
sidekiq (4.1.2)
@ -345,6 +349,10 @@ GEM
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
webmock (2.1.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
yard (0.8.7.6)
PLATFORMS
@ -392,6 +400,7 @@ DEPENDENCIES
travis-support!
travis-yaml!
unicorn
webmock
yard-sinatra!
BUNDLED WITH

View File

@ -8,16 +8,11 @@ module Travis::API::V3
log = Models::Log.find_by_job_id(job.id)
raise EntityMissing, 'log not found'.freeze if log.nil?
p log.archived_at
#if the log has been archived, go to s3
if log.archived_at
## if it's not there then fetch it from S3, and return it wrapped as a compatible log_parts object with a hard coded #number (log_parts have a number) and the parts chunked (not sure how to do this)
archived_log_path = archive_url("/jobs/#{params[:job.id]}/log.txt")
p archived_log_path
content = open(Net::HTTP.get(URI.parse(archived_log_path)))
p content
archived_log_path = archive_url("/jobs/#{job.id}/log.txt")
content = Net::HTTP.get(URI.parse(archived_log_path))
log_parts = []
content.each_line.with_index do |line, number|

View File

@ -10,6 +10,7 @@ require 'gh'
require 'multi_json'
require 'pry'
require 'stackprof'
require 'webmock/rspec'
require 'travis/api/app'
require 'travis/testing'

View File

@ -37,13 +37,14 @@ describe Travis::API::V3::Services::Log::Find, set_app: true do
context 'when log not found in db but stored on S3' do
describe 'returns log with an array of Log Parts' do
before do
stub_request(:get, "https://s3.amazonaws.com/archive.travis-ci.org/jobs/#{s3job.id}/log.txt").
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'s3.amazonaws.com', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => "$ git clean -fdx\nRemoving Gemfile.lock\n$ git fetch", :headers => {})
end
example do
s3log.update_attribute(:archived_at, Time.now)
s3log.update_attributes(archived_at: Time.now)
get("/v3/job/#{s3job.id}/log", {}, headers)
p s3job
p s3job.id
p s3log
p s3log.archived_at
expect(parsed_body).to eq(
'@href' => "/v3/job/#{s3job.id}/log",
@ -51,7 +52,19 @@ describe Travis::API::V3::Services::Log::Find, set_app: true do
'@type' => 'log',
'content' => 'minimal log 1',
'id' => s3log.id,
'log_parts' => [])
'log_parts' => [{
"@type"=>"log_part",
"@representation"=>"minimal",
"content"=>"$ git clean -fdx",
"number"=>0}, {
"@type"=>"log_part",
"@representation"=>"minimal",
"content"=>"Removing Gemfile.lock",
"number"=>1}, {
"@type"=>"log_part",
"@representation"=>"minimal",
"content"=>"$ git fetch",
"number"=>2}])
end
end
describe 'returns log as plain text'