Commit ac165121 authored by Furkan Ayhan's avatar Furkan Ayhan
Browse files

Replace OpenStruct in Ansi2json converter

parent 69268559
......@@ -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
Supports Markdown
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