Commit 516c0621 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'backstage/34305-replace-openstruct-in-ansi-converters' into 'master'

Replace OpenStruct in Ansi converters

See merge request gitlab-org/gitlab!20444
parents d250c3bc ac165121
......@@ -37,16 +37,13 @@ module Gitlab
flush_current_line
# TODO: replace OpenStruct with a better type
# https://gitlab.com/gitlab-org/gitlab/issues/34305
OpenStruct.new(
Gitlab::Ci::Ansi2json::Result.new(
lines: @lines,
state: @state.encode,
append: append,
truncated: truncated,
offset: start_offset,
size: stream.tell - start_offset,
total: stream.size
stream: stream
)
end
......
# frozen_string_literal: true
# Convertion result object class
module Gitlab
module Ci
module Ansi2json
class Result
attr_reader :lines, :state, :append, :truncated, :offset, :size, :total
def initialize(lines:, state:, append:, truncated:, offset:, stream:)
@lines = lines
@state = state
@append = append
@truncated = truncated
@offset = offset
@size = stream.tell - offset
@total = stream.size
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Ansi2json::Result do
let(:stream) { StringIO.new('hello') }
let(:state) { Gitlab::Ci::Ansi2json::State.new(nil, stream.size) }
let(:offset) { 0 }
let(:params) do
{ lines: [], state: state, append: false, truncated: false, offset: offset, stream: stream }
end
subject { described_class.new(params) }
describe '#size' do
before do
stream.seek(5) # move stream cursor to the end
end
context 'when offset is at the start' do
let(:offset) { 0 }
it 'returns the full size' do
expect(subject.size).to eq(5)
end
end
context 'when offset is not zero' do
let(:offset) { 2 }
it 'returns the remaining size' do
expect(subject.size).to eq(3)
end
end
end
describe '#total' do
it 'returns size of stread' do
expect(subject.total).to eq(5)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment