From a7128fa1b377a4bfd9e310ac415d60a7e4354a88 Mon Sep 17 00:00:00 2001 From: carlad Date: Fri, 5 Aug 2016 15:33:30 +0200 Subject: [PATCH] add debug output --- lib/travis/api/v3/queries/log.rb | 7 +++++-- spec/v3/services/log/find_spec.rb | 29 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/travis/api/v3/queries/log.rb b/lib/travis/api/v3/queries/log.rb index 4cb23bc4..75607f26 100644 --- a/lib/travis/api/v3/queries/log.rb +++ b/lib/travis/api/v3/queries/log.rb @@ -9,12 +9,15 @@ module Travis::API::V3 raise EntityMissing, 'log not found'.freeze if log.nil? - #if the log exists and has not been archived yet, then collect the log_parts and return the Log query object + 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 log_parts = [] content.each_line.with_index do |line, number| diff --git a/spec/v3/services/log/find_spec.rb b/spec/v3/services/log/find_spec.rb index f85a5891..ba2a816f 100644 --- a/spec/v3/services/log/find_spec.rb +++ b/spec/v3/services/log/find_spec.rb @@ -5,14 +5,17 @@ describe Travis::API::V3::Services::Log::Find, set_app: true do let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: user.login, name: 'minimal').first } let(:build) { repo.builds.last } let(:job) { Travis::API::V3::Models::Build.find(build.id).jobs.last } + let(:s3job) { Travis::API::V3::Models::Build.find(build.id).jobs.first } let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: 1) } let(:headers) { { 'HTTP_AUTHORIZATION' => "token #{token}" } } let(:parsed_body) { JSON.load(body) } + let(:log) { job.log } + let(:s3log) { s3job.log } + # before { s3log.update_attribute(:archived_at, Time.now) } + context 'when log stored in db' do - describe 'returns the Log with an array of Log Parts' do - let(:log) { job.log } - + describe 'returns log with an array of Log Parts' do example do log_part = log.log_parts.create(content: "logging it", number: 0) get("/v3/job/#{job.id}/log", {}, headers) @@ -29,11 +32,29 @@ describe Travis::API::V3::Services::Log::Find, set_app: true do "number" => log_part.number }]) end end + describe 'returns log as plain text' end context 'when log not found in db but stored on S3' do + describe 'returns log with an array of Log Parts' do + example do + s3log.update_attribute(: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", + '@representation' => 'standard', + '@type' => 'log', + 'content' => 'minimal log 1', + 'id' => s3log.id, + 'log_parts' => []) + end + end describe 'returns log as plain text' - describe 'returns log as chunked json' end context 'when log not found anywhere' do