2019-10-17 11:06:17 -04:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
|
RSpec.describe Ci::BuildTrace do
|
2019-10-17 11:06:17 -04:00
|
|
|
|
let(:build) { build_stubbed(:ci_build) }
|
|
|
|
|
let(:state) { nil }
|
|
|
|
|
let(:data) { StringIO.new('the-stream') }
|
|
|
|
|
|
|
|
|
|
let(:stream) do
|
|
|
|
|
Gitlab::Ci::Trace::Stream.new { data }
|
|
|
|
|
end
|
|
|
|
|
|
2020-07-01 11:08:45 -04:00
|
|
|
|
subject { described_class.new(build: build, stream: stream, state: state) }
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
|
|
shared_examples 'delegates methods' do
|
|
|
|
|
it { is_expected.to delegate_method(:state).to(:trace) }
|
|
|
|
|
it { is_expected.to delegate_method(:append).to(:trace) }
|
|
|
|
|
it { is_expected.to delegate_method(:truncated).to(:trace) }
|
|
|
|
|
it { is_expected.to delegate_method(:offset).to(:trace) }
|
|
|
|
|
it { is_expected.to delegate_method(:size).to(:trace) }
|
|
|
|
|
it { is_expected.to delegate_method(:total).to(:trace) }
|
|
|
|
|
it { is_expected.to delegate_method(:id).to(:build).with_prefix }
|
|
|
|
|
it { is_expected.to delegate_method(:status).to(:build).with_prefix }
|
|
|
|
|
it { is_expected.to delegate_method(:complete?).to(:build).with_prefix }
|
|
|
|
|
end
|
|
|
|
|
|
2020-07-01 11:08:45 -04:00
|
|
|
|
it_behaves_like 'delegates methods'
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
2020-07-01 11:08:45 -04:00
|
|
|
|
it 'returns formatted trace' do
|
|
|
|
|
expect(subject.lines).to eq([
|
|
|
|
|
{ offset: 0, content: [{ text: 'the-stream' }] }
|
|
|
|
|
])
|
2019-10-17 11:06:17 -04:00
|
|
|
|
end
|
2021-07-21 08:09:35 -04:00
|
|
|
|
|
|
|
|
|
context 'with invalid UTF-8 data' do
|
|
|
|
|
let(:data) { StringIO.new("UTF-8 dashes here: ───\n🐤🐤🐤🐤\xF0\x9F\x90\n") }
|
|
|
|
|
|
|
|
|
|
it 'returns valid UTF-8 data', :aggregate_failures do
|
|
|
|
|
expect(subject.lines[0]).to eq({ offset: 0, content: [{ text: 'UTF-8 dashes here: ───' }] } )
|
|
|
|
|
# Each of the dashes is 3 bytes, so we get 19 + 9 + 1 = 29
|
|
|
|
|
expect(subject.lines[1]).to eq({ offset: 29, content: [{ text: '🐤🐤🐤🐤<F09F90A4>' }] } )
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-10-17 11:06:17 -04:00
|
|
|
|
end
|